tests/unit/test-smp-parse: Test "drawers" parameter in -smp
[qemu/kevin.git] / hw / net / lasi_i82596.c
blobfcf7fae941196fa0ba550cb4b340711a0de7cc93
1 /*
2 * QEMU LASI NIC i82596 emulation
4 * Copyright (c) 2019 Helge Deller <deller@gmx.de>
5 * This work is licensed under the GNU GPL license version 2 or later.
8 * On PA-RISC, this is the Network part of LASI chip.
9 * See:
10 * https://parisc.wiki.kernel.org/images-parisc/7/79/Lasi_ers.pdf
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "qemu/timer.h"
16 #include "hw/sysbus.h"
17 #include "sysemu/sysemu.h"
18 #include "net/eth.h"
19 #include "hw/net/lasi_82596.h"
20 #include "hw/net/i82596.h"
21 #include "trace.h"
22 #include "hw/qdev-properties.h"
23 #include "migration/vmstate.h"
25 #define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
26 #define PA_CPU_PORT_L_ACCESS 4
27 #define PA_CHANNEL_ATTENTION 8
28 #define PA_GET_MACADDR 12
30 #define SWAP32(x) (((uint32_t)(x) << 16) | ((((uint32_t)(x))) >> 16))
32 static void lasi_82596_mem_write(void *opaque, hwaddr addr,
33 uint64_t val, unsigned size)
35 SysBusI82596State *d = opaque;
37 trace_lasi_82596_mem_writew(addr, val);
38 switch (addr) {
39 case PA_I82596_RESET:
40 i82596_h_reset(&d->state);
41 break;
42 case PA_CPU_PORT_L_ACCESS:
43 d->val_index++;
44 if (d->val_index == 0) {
45 uint32_t v = d->last_val | (val << 16);
46 v = v & ~0xff;
47 i82596_ioport_writew(&d->state, d->last_val & 0xff, v);
49 d->last_val = val;
50 break;
51 case PA_CHANNEL_ATTENTION:
52 i82596_ioport_writew(&d->state, PORT_CA, val);
53 break;
54 case PA_GET_MACADDR:
56 * Provided for SeaBIOS only. Write MAC of Network card to addr @val.
57 * Needed for the PDC_LAN_STATION_ID_READ PDC call.
59 address_space_write(&address_space_memory, val,
60 MEMTXATTRS_UNSPECIFIED, d->state.conf.macaddr.a,
61 ETH_ALEN);
62 break;
66 static uint64_t lasi_82596_mem_read(void *opaque, hwaddr addr,
67 unsigned size)
69 SysBusI82596State *d = opaque;
70 uint32_t val;
72 if (addr == PA_GET_MACADDR) {
73 val = 0xBEEFBABE;
74 } else {
75 val = i82596_ioport_readw(&d->state, addr);
77 trace_lasi_82596_mem_readw(addr, val);
78 return val;
81 static const MemoryRegionOps lasi_82596_mem_ops = {
82 .read = lasi_82596_mem_read,
83 .write = lasi_82596_mem_write,
84 .endianness = DEVICE_BIG_ENDIAN,
85 .valid = {
86 .min_access_size = 4,
87 .max_access_size = 4,
91 static NetClientInfo net_lasi_82596_info = {
92 .type = NET_CLIENT_DRIVER_NIC,
93 .size = sizeof(NICState),
94 .can_receive = i82596_can_receive,
95 .receive = i82596_receive,
96 .link_status_changed = i82596_set_link_status,
99 static const VMStateDescription vmstate_lasi_82596 = {
100 .name = "i82596",
101 .version_id = 1,
102 .minimum_version_id = 1,
103 .fields = (const VMStateField[]) {
104 VMSTATE_STRUCT(state, SysBusI82596State, 0, vmstate_i82596,
105 I82596State),
106 VMSTATE_END_OF_LIST()
110 static void lasi_82596_realize(DeviceState *dev, Error **errp)
112 SysBusI82596State *d = SYSBUS_I82596(dev);
113 I82596State *s = &d->state;
115 memory_region_init_io(&s->mmio, OBJECT(d), &lasi_82596_mem_ops, d,
116 "lasi_82596-mmio", PA_GET_MACADDR + 4);
118 i82596_common_init(dev, s, &net_lasi_82596_info);
121 SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space, hwaddr hpa,
122 qemu_irq lan_irq, gboolean match_default)
124 DeviceState *dev;
125 SysBusI82596State *s;
126 static const MACAddr HP_MAC = {
127 .a = { 0x08, 0x00, 0x09, 0xef, 0x34, 0xf6 } };
129 dev = qemu_create_nic_device(TYPE_LASI_82596, match_default, "lasi");
130 if (!dev) {
131 return NULL;
134 s = SYSBUS_I82596(dev);
135 s->state.irq = lan_irq;
136 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
137 s->state.conf.macaddr = HP_MAC; /* set HP MAC prefix */
139 /* LASI 82596 ports in main memory. */
140 memory_region_add_subregion(addr_space, hpa, &s->state.mmio);
141 return s;
144 static void lasi_82596_reset(DeviceState *dev)
146 SysBusI82596State *d = SYSBUS_I82596(dev);
148 i82596_h_reset(&d->state);
151 static void lasi_82596_instance_init(Object *obj)
153 SysBusI82596State *d = SYSBUS_I82596(obj);
154 I82596State *s = &d->state;
156 device_add_bootindex_property(obj, &s->conf.bootindex,
157 "bootindex", "/ethernet-phy@0",
158 DEVICE(obj));
161 static Property lasi_82596_properties[] = {
162 DEFINE_NIC_PROPERTIES(SysBusI82596State, state.conf),
163 DEFINE_PROP_END_OF_LIST(),
166 static void lasi_82596_class_init(ObjectClass *klass, void *data)
168 DeviceClass *dc = DEVICE_CLASS(klass);
170 dc->realize = lasi_82596_realize;
171 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
172 dc->fw_name = "ethernet";
173 dc->reset = lasi_82596_reset;
174 dc->vmsd = &vmstate_lasi_82596;
175 dc->user_creatable = false;
176 device_class_set_props(dc, lasi_82596_properties);
179 static const TypeInfo lasi_82596_info = {
180 .name = TYPE_LASI_82596,
181 .parent = TYPE_SYS_BUS_DEVICE,
182 .instance_size = sizeof(SysBusI82596State),
183 .class_init = lasi_82596_class_init,
184 .instance_init = lasi_82596_instance_init,
187 static void lasi_82596_register_types(void)
189 type_register_static(&lasi_82596_info);
192 type_init(lasi_82596_register_types)