]> git.proxmox.com Git - mirror_qemu.git/blame - hw/eepro100.c
qemu-img rebase: Document -f option
[mirror_qemu.git] / hw / eepro100.c
CommitLineData
663e8e51
TS
1/*
2 * QEMU i8255x (PRO100) emulation
3 *
230a167c 4 * Copyright (C) 2006-2010 Stefan Weil
663e8e51
TS
5 *
6 * Portions of the code are copies from grub / etherboot eepro100.c
7 * and linux e100.c.
8 *
230a167c 9 * This program is free software: you can redistribute it and/or modify
663e8e51 10 * it under the terms of the GNU General Public License as published by
230a167c
SW
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 or any later version.
663e8e51
TS
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
230a167c 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
663e8e51
TS
21 *
22 * Tested features (i82559):
6cded3a4 23 * PXE boot (i386) ok
663e8e51
TS
24 * Linux networking (i386) ok
25 *
26 * Untested:
27 * non-i386 platforms
28 * Windows networking
29 *
30 * References:
31 *
32 * Intel 8255x 10/100 Mbps Ethernet Controller Family
33 * Open Source Software Developer Manual
ba19f2de
SW
34 *
35 * TODO:
36 * * PHY emulation should be separated from nic emulation.
37 * Most nic emulations could share the same phy code.
38 * * i82550 is untested. It is programmed like the i82559.
39 * * i82562 is untested. It is programmed like the i82559.
40 * * Power management (i82558 and later) is not implemented.
41 * * Wake-on-LAN is not implemented.
663e8e51
TS
42 */
43
78728c92 44#include <stdbool.h> /* bool */
663e8e51 45#include <stddef.h> /* offsetof */
87ecb68b
PB
46#include "hw.h"
47#include "pci.h"
48#include "net.h"
663e8e51
TS
49#include "eeprom93xx.h"
50
51/* Common declarations for all PCI devices. */
52
663e8e51
TS
53#define PCI_CONFIG_8(offset, value) \
54 (pci_conf[offset] = (value))
55#define PCI_CONFIG_16(offset, value) \
56 (*(uint16_t *)&pci_conf[offset] = cpu_to_le16(value))
57#define PCI_CONFIG_32(offset, value) \
58 (*(uint32_t *)&pci_conf[offset] = cpu_to_le32(value))
59
60#define KiB 1024
61
aac443e6 62/* Debug EEPRO100 card. */
ce0e58b3
SW
63#if 0
64# define DEBUG_EEPRO100
65#endif
663e8e51
TS
66
67#ifdef DEBUG_EEPRO100
001faf32 68#define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
663e8e51 69#else
001faf32 70#define logout(fmt, ...) ((void)0)
663e8e51
TS
71#endif
72
73/* Set flags to 0 to disable debug output. */
aac443e6
SW
74#define INT 1 /* interrupt related actions */
75#define MDI 1 /* mdi related actions */
76#define OTHER 1
77#define RXTX 1
78#define EEPROM 1 /* eeprom related actions */
663e8e51
TS
79
80#define TRACE(flag, command) ((flag) ? (command) : (void)0)
81
7f1e9d4e 82#define missing(text) fprintf(stderr, "eepro100: feature is missing in this emulation: " text "\n")
663e8e51
TS
83
84#define MAX_ETH_FRAME_SIZE 1514
85
86/* This driver supports several different devices which are declared here. */
c4c270e2 87#define i82550 0x82550
663e8e51 88#define i82551 0x82551
c4c270e2 89#define i82557A 0x82557a
663e8e51
TS
90#define i82557B 0x82557b
91#define i82557C 0x82557c
c4c270e2 92#define i82558A 0x82558a
663e8e51 93#define i82558B 0x82558b
c4c270e2
SW
94#define i82559A 0x82559a
95#define i82559B 0x82559b
663e8e51
TS
96#define i82559C 0x82559c
97#define i82559ER 0x82559e
98#define i82562 0x82562
99
aac443e6 100/* Use 64 word EEPROM. TODO: could be a runtime option. */
663e8e51
TS
101#define EEPROM_SIZE 64
102
103#define PCI_MEM_SIZE (4 * KiB)
104#define PCI_IO_SIZE 64
105#define PCI_FLASH_SIZE (128 * KiB)
106
107#define BIT(n) (1 << (n))
108#define BITS(n, m) (((0xffffffffU << (31 - n)) >> (31 - n + m)) << m)
109
110/* The SCB accepts the following controls for the Tx and Rx units: */
111#define CU_NOP 0x0000 /* No operation. */
112#define CU_START 0x0010 /* CU start. */
113#define CU_RESUME 0x0020 /* CU resume. */
114#define CU_STATSADDR 0x0040 /* Load dump counters address. */
115#define CU_SHOWSTATS 0x0050 /* Dump statistical counters. */
116#define CU_CMD_BASE 0x0060 /* Load CU base address. */
117#define CU_DUMPSTATS 0x0070 /* Dump and reset statistical counters. */
118#define CU_SRESUME 0x00a0 /* CU static resume. */
119
120#define RU_NOP 0x0000
121#define RX_START 0x0001
122#define RX_RESUME 0x0002
e824012b 123#define RU_ABORT 0x0004
663e8e51
TS
124#define RX_ADDR_LOAD 0x0006
125#define RX_RESUMENR 0x0007
126#define INT_MASK 0x0100
127#define DRVR_INT 0x0200 /* Driver generated interrupt. */
128
663e8e51
TS
129/* Offsets to the various registers.
130 All accesses need not be longword aligned. */
131enum speedo_offsets {
0908bba1 132 SCBStatus = 0, /* Status Word. */
663e8e51
TS
133 SCBAck = 1,
134 SCBCmd = 2, /* Rx/Command Unit command and status. */
135 SCBIntmask = 3,
136 SCBPointer = 4, /* General purpose pointer. */
137 SCBPort = 8, /* Misc. commands and operands. */
0908bba1
SW
138 SCBflash = 12, /* Flash memory control. */
139 SCBeeprom = 14, /* EEPROM control. */
663e8e51
TS
140 SCBCtrlMDI = 16, /* MDI interface control. */
141 SCBEarlyRx = 20, /* Early receive byte count. */
0908bba1
SW
142 SCBFlow = 24, /* Flow Control. */
143 SCBpmdr = 27, /* Power Management Driver. */
144 SCBgctrl = 28, /* General Control. */
145 SCBgstat = 29, /* General Status. */
663e8e51
TS
146};
147
148/* A speedo3 transmit buffer descriptor with two buffers... */
149typedef struct {
150 uint16_t status;
151 uint16_t command;
152 uint32_t link; /* void * */
7b8737de 153 uint32_t tbd_array_addr; /* transmit buffer descriptor array address. */
663e8e51
TS
154 uint16_t tcb_bytes; /* transmit command block byte count (in lower 14 bits */
155 uint8_t tx_threshold; /* transmit threshold */
156 uint8_t tbd_count; /* TBD number */
e7493b25
SW
157#if 0
158 /* This constitutes two "TBD" entries: hdr and data */
159 uint32_t tx_buf_addr0; /* void *, header of frame to be transmitted. */
160 int32_t tx_buf_size0; /* Length of Tx hdr. */
161 uint32_t tx_buf_addr1; /* void *, data to be transmitted. */
162 int32_t tx_buf_size1; /* Length of Tx data. */
163#endif
c227f099 164} eepro100_tx_t;
663e8e51
TS
165
166/* Receive frame descriptor. */
167typedef struct {
168 int16_t status;
169 uint16_t command;
170 uint32_t link; /* struct RxFD * */
171 uint32_t rx_buf_addr; /* void * */
172 uint16_t count;
173 uint16_t size;
174 char packet[MAX_ETH_FRAME_SIZE + 4];
c227f099 175} eepro100_rx_t;
663e8e51 176
ced5296a
SW
177typedef enum {
178 COMMAND_EL = BIT(15),
179 COMMAND_S = BIT(14),
180 COMMAND_I = BIT(13),
181 COMMAND_NC = BIT(4),
182 COMMAND_SF = BIT(3),
183 COMMAND_CMD = BITS(2, 0),
184} scb_command_bit;
185
186typedef enum {
187 STATUS_C = BIT(15),
188 STATUS_OK = BIT(13),
189} scb_status_bit;
190
663e8e51
TS
191typedef struct {
192 uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
cc02c66c
SW
193 tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
194 tx_multiple_collisions, tx_total_collisions;
663e8e51 195 uint32_t rx_good_frames, rx_crc_errors, rx_alignment_errors,
cc02c66c
SW
196 rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
197 rx_short_frame_errors;
663e8e51
TS
198 uint32_t fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
199 uint16_t xmt_tco_frames, rcv_tco_frames;
ba42b646
SW
200 /* TODO: i82559 has six reserved statistics but a total of 24 dwords. */
201 uint32_t reserved[4];
c227f099 202} eepro100_stats_t;
663e8e51
TS
203
204typedef enum {
205 cu_idle = 0,
206 cu_suspended = 1,
207 cu_active = 2,
208 cu_lpq_active = 2,
209 cu_hqp_active = 3
c227f099 210} cu_state_t;
663e8e51
TS
211
212typedef enum {
213 ru_idle = 0,
214 ru_suspended = 1,
215 ru_no_resources = 2,
216 ru_ready = 4
c227f099 217} ru_state_t;
663e8e51 218
663e8e51 219typedef struct {
273a2142 220 PCIDevice dev;
663e8e51
TS
221 uint8_t mult[8]; /* multicast mask array */
222 int mmio_index;
e00e365e 223 NICState *nic;
508ef936 224 NICConf conf;
663e8e51
TS
225 uint8_t scb_stat; /* SCB stat/ack byte */
226 uint8_t int_stat; /* PCI interrupt status */
3706c43f 227 /* region must not be saved by nic_save. */
663e8e51 228 uint32_t region[3]; /* PCI region addresses */
663e8e51 229 uint16_t mdimem[32];
c227f099 230 eeprom_t *eeprom;
663e8e51
TS
231 uint32_t device; /* device variant */
232 uint32_t pointer;
233 /* (cu_base + cu_offset) address the next command block in the command block list. */
234 uint32_t cu_base; /* CU base address */
235 uint32_t cu_offset; /* CU address offset */
236 /* (ru_base + ru_offset) address the RFD in the Receive Frame Area. */
237 uint32_t ru_base; /* RU base address */
238 uint32_t ru_offset; /* RU address offset */
c227f099 239 uint32_t statsaddr; /* pointer to eepro100_stats_t */
ba42b646 240
f3a52e50
SW
241 /* Temporary status information (no need to save these values),
242 * used while processing CU commands. */
243 eepro100_tx_t tx; /* transmit buffer descriptor */
244 uint32_t cb_address; /* = cu_base + cu_offset */
245
ba42b646
SW
246 /* Statistical counters. Also used for wake-up packet (i82559). */
247 eepro100_stats_t statistics;
248
663e8e51
TS
249#if 0
250 uint16_t status;
251#endif
252
253 /* Configuration bytes. */
254 uint8_t configuration[22];
255
256 /* Data in mem is always in the byte order of the controller (le). */
257 uint8_t mem[PCI_MEM_SIZE];
151b2986
JQ
258 /* vmstate for each particular nic */
259 VMStateDescription *vmstate;
ba42b646
SW
260
261 /* Quasi static device properties (no need to save them). */
262 uint16_t stats_size;
263 bool has_extended_tcb_support;
663e8e51
TS
264} EEPRO100State;
265
6cded3a4
SW
266/* Word indices in EEPROM. */
267typedef enum {
268 EEPROM_CNFG_MDIX = 0x03,
269 EEPROM_ID = 0x05,
270 EEPROM_PHY_ID = 0x06,
271 EEPROM_VENDOR_ID = 0x0c,
272 EEPROM_CONFIG_ASF = 0x0d,
273 EEPROM_DEVICE_ID = 0x23,
274 EEPROM_SMBUS_ADDR = 0x90,
275} EEPROMOffset;
276
b1e87018
SW
277/* Bit values for EEPROM ID word. */
278typedef enum {
279 EEPROM_ID_MDM = BIT(0), /* Modem */
280 EEPROM_ID_STB = BIT(1), /* Standby Enable */
281 EEPROM_ID_WMR = BIT(2), /* ??? */
282 EEPROM_ID_WOL = BIT(5), /* Wake on LAN */
283 EEPROM_ID_DPD = BIT(6), /* Deep Power Down */
284 EEPROM_ID_ALT = BIT(7), /* */
285 /* BITS(10, 8) device revision */
286 EEPROM_ID_BD = BIT(11), /* boot disable */
287 EEPROM_ID_ID = BIT(13), /* id bit */
288 /* BITS(15, 14) signature */
289 EEPROM_ID_VALID = BIT(14), /* signature for valid eeprom */
290} eeprom_id_bit;
291
663e8e51
TS
292/* Default values for MDI (PHY) registers */
293static const uint16_t eepro100_mdi_default[] = {
294 /* MDI Registers 0 - 6, 7 */
295 0x3000, 0x780d, 0x02a8, 0x0154, 0x05e1, 0x0000, 0x0000, 0x0000,
296 /* MDI Registers 8 - 15 */
297 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
298 /* MDI Registers 16 - 31 */
299 0x0003, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
300 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
301};
302
303/* Readonly mask for MDI (PHY) registers */
304static const uint16_t eepro100_mdi_mask[] = {
305 0x0000, 0xffff, 0xffff, 0xffff, 0xc01f, 0xffff, 0xffff, 0x0000,
306 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
307 0x0fff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
308 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
309};
310
ba42b646
SW
311/* XXX: optimize */
312static void stl_le_phys(target_phys_addr_t addr, uint32_t val)
313{
314 val = cpu_to_le32(val);
315 cpu_physical_memory_write(addr, (const uint8_t *)&val, sizeof(val));
316}
317
663e8e51
TS
318#define POLYNOMIAL 0x04c11db6
319
320/* From FreeBSD */
321/* XXX: optimize */
7b8737de 322static unsigned compute_mcast_idx(const uint8_t * ep)
663e8e51
TS
323{
324 uint32_t crc;
325 int carry, i, j;
326 uint8_t b;
327
328 crc = 0xffffffff;
329 for (i = 0; i < 6; i++) {
330 b = *ep++;
331 for (j = 0; j < 8; j++) {
332 carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
333 crc <<= 1;
334 b >>= 1;
aac443e6 335 if (carry) {
663e8e51 336 crc = ((crc ^ POLYNOMIAL) | carry);
aac443e6 337 }
663e8e51
TS
338 }
339 }
7b8737de 340 return (crc & BITS(7, 2)) >> 2;
663e8e51
TS
341}
342
343#if defined(DEBUG_EEPRO100)
344static const char *nic_dump(const uint8_t * buf, unsigned size)
345{
346 static char dump[3 * 16 + 1];
347 char *p = &dump[0];
aac443e6 348 if (size > 16) {
663e8e51 349 size = 16;
aac443e6 350 }
663e8e51
TS
351 while (size-- > 0) {
352 p += sprintf(p, " %02x", *buf++);
353 }
354 return dump;
355}
356#endif /* DEBUG_EEPRO100 */
357
358enum scb_stat_ack {
359 stat_ack_not_ours = 0x00,
360 stat_ack_sw_gen = 0x04,
361 stat_ack_rnr = 0x10,
362 stat_ack_cu_idle = 0x20,
363 stat_ack_frame_rx = 0x40,
364 stat_ack_cu_cmd_done = 0x80,
365 stat_ack_not_present = 0xFF,
366 stat_ack_rx = (stat_ack_sw_gen | stat_ack_rnr | stat_ack_frame_rx),
367 stat_ack_tx = (stat_ack_cu_idle | stat_ack_cu_cmd_done),
368};
369
370static void disable_interrupt(EEPRO100State * s)
371{
372 if (s->int_stat) {
aac443e6 373 TRACE(INT, logout("interrupt disabled\n"));
273a2142 374 qemu_irq_lower(s->dev.irq[0]);
663e8e51
TS
375 s->int_stat = 0;
376 }
377}
378
379static void enable_interrupt(EEPRO100State * s)
380{
381 if (!s->int_stat) {
aac443e6 382 TRACE(INT, logout("interrupt enabled\n"));
273a2142 383 qemu_irq_raise(s->dev.irq[0]);
663e8e51
TS
384 s->int_stat = 1;
385 }
386}
387
388static void eepro100_acknowledge(EEPRO100State * s)
389{
390 s->scb_stat &= ~s->mem[SCBAck];
391 s->mem[SCBAck] = s->scb_stat;
392 if (s->scb_stat == 0) {
393 disable_interrupt(s);
394 }
395}
396
e715c8e8 397static void eepro100_interrupt(EEPRO100State * s, uint8_t status)
663e8e51
TS
398{
399 uint8_t mask = ~s->mem[SCBIntmask];
e715c8e8
SW
400 s->mem[SCBAck] |= status;
401 status = s->scb_stat = s->mem[SCBAck];
402 status &= (mask | 0x0f);
e7493b25
SW
403#if 0
404 status &= (~s->mem[SCBIntmask] | 0x0xf);
405#endif
e715c8e8 406 if (status && (mask & 0x01)) {
663e8e51
TS
407 /* SCB mask and SCB Bit M do not disable interrupt. */
408 enable_interrupt(s);
409 } else if (s->int_stat) {
410 disable_interrupt(s);
411 }
412}
413
414static void eepro100_cx_interrupt(EEPRO100State * s)
415{
416 /* CU completed action command. */
417 /* Transmit not ok (82557 only, not in emulation). */
418 eepro100_interrupt(s, 0x80);
419}
420
421static void eepro100_cna_interrupt(EEPRO100State * s)
422{
423 /* CU left the active state. */
424 eepro100_interrupt(s, 0x20);
425}
426
427static void eepro100_fr_interrupt(EEPRO100State * s)
428{
429 /* RU received a complete frame. */
430 eepro100_interrupt(s, 0x40);
431}
432
663e8e51
TS
433static void eepro100_rnr_interrupt(EEPRO100State * s)
434{
435 /* RU is not ready. */
436 eepro100_interrupt(s, 0x10);
437}
663e8e51
TS
438
439static void eepro100_mdi_interrupt(EEPRO100State * s)
440{
441 /* MDI completed read or write cycle. */
442 eepro100_interrupt(s, 0x08);
443}
444
445static void eepro100_swi_interrupt(EEPRO100State * s)
446{
447 /* Software has requested an interrupt. */
448 eepro100_interrupt(s, 0x04);
449}
450
451#if 0
452static void eepro100_fcp_interrupt(EEPRO100State * s)
453{
454 /* Flow control pause interrupt (82558 and later). */
455 eepro100_interrupt(s, 0x01);
456}
457#endif
458
459static void pci_reset(EEPRO100State * s)
460{
461 uint32_t device = s->device;
273a2142 462 uint8_t *pci_conf = s->dev.config;
ba42b646 463 bool power_management = 1;
663e8e51 464
aac443e6 465 TRACE(OTHER, logout("%p\n", s));
663e8e51
TS
466
467 /* PCI Vendor ID */
deb54399 468 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
d6fd1e66 469 /* PCI Device ID depends on device and is set below. */
663e8e51 470 /* PCI Command */
508cc6b4 471 /* TODO: this is the default, do not override. */
663e8e51
TS
472 PCI_CONFIG_16(PCI_COMMAND, 0x0000);
473 /* PCI Status */
508cc6b4 474 /* TODO: Value at RST# should be 0. */
61702408 475 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM | PCI_STATUS_FAST_BACK);
663e8e51
TS
476 /* PCI Revision ID */
477 PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
508cc6b4 478 /* TODO: this is the default, do not override. */
663e8e51 479 /* PCI Class Code */
508cc6b4 480 PCI_CONFIG_8(PCI_CLASS_PROG, 0x00);
173a543b 481 pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
663e8e51
TS
482 /* PCI Cache Line Size */
483 /* check cache line size!!! */
e7493b25
SW
484#if 0
485 PCI_CONFIG_8(0x0c, 0x00);
486#endif
663e8e51 487 /* PCI Latency Timer */
e7493b25 488 PCI_CONFIG_8(PCI_LATENCY_TIMER, 0x20); /* latency timer = 32 clocks */
663e8e51
TS
489 /* PCI Header Type */
490 /* BIST (built-in self test) */
663e8e51 491 /* Expansion ROM Base Address (depends on boot disable!!!) */
508cc6b4
MT
492 /* TODO: not needed, set when BAR is registered */
493 PCI_CONFIG_32(PCI_ROM_ADDRESS, PCI_BASE_ADDRESS_SPACE_MEMORY);
663e8e51 494 /* Capability Pointer */
508cc6b4
MT
495 /* TODO: revisions with power_management 1 use this but
496 * do not set new capability list bit in status register. */
497 PCI_CONFIG_8(PCI_CAPABILITY_LIST, 0xdc);
aac443e6 498 /* Interrupt Line */
663e8e51 499 /* Interrupt Pin */
508cc6b4 500 /* TODO: RST# value should be 0 */
e7493b25 501 PCI_CONFIG_8(PCI_INTERRUPT_PIN, 1); /* interrupt pin 0 */
663e8e51 502 /* Minimum Grant */
508cc6b4 503 PCI_CONFIG_8(PCI_MIN_GNT, 0x08);
663e8e51 504 /* Maximum Latency */
508cc6b4 505 PCI_CONFIG_8(PCI_MAX_LAT, 0x18);
663e8e51
TS
506
507 switch (device) {
ba42b646 508 case i82550:
e7493b25 509 /* TODO: check device id. */
ba42b646
SW
510 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
511 /* Revision ID: 0x0c, 0x0d, 0x0e. */
512 PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
e7493b25 513 /* TODO: check size of statistical counters. */
ba42b646 514 s->stats_size = 80;
e7493b25 515 /* TODO: check extended tcb support. */
ba42b646
SW
516 s->has_extended_tcb_support = 1;
517 break;
663e8e51 518 case i82551:
d6fd1e66 519 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
ba42b646 520 /* Revision ID: 0x0f, 0x10. */
663e8e51 521 PCI_CONFIG_8(PCI_REVISION_ID, 0x0f);
e7493b25 522 /* TODO: check size of statistical counters. */
ba42b646
SW
523 s->stats_size = 80;
524 s->has_extended_tcb_support = 1;
525 break;
526 case i82557A:
527 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
528 PCI_CONFIG_8(PCI_REVISION_ID, 0x01);
508cc6b4 529 PCI_CONFIG_8(PCI_CAPABILITY_LIST, 0x00);
ba42b646 530 power_management = 0;
663e8e51
TS
531 break;
532 case i82557B:
d6fd1e66 533 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51 534 PCI_CONFIG_8(PCI_REVISION_ID, 0x02);
508cc6b4 535 PCI_CONFIG_8(PCI_CAPABILITY_LIST, 0x00);
ba42b646 536 power_management = 0;
663e8e51
TS
537 break;
538 case i82557C:
d6fd1e66 539 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51 540 PCI_CONFIG_8(PCI_REVISION_ID, 0x03);
508cc6b4 541 PCI_CONFIG_8(PCI_CAPABILITY_LIST, 0x00);
ba42b646
SW
542 power_management = 0;
543 break;
544 case i82558A:
545 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
508cc6b4
MT
546 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
547 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
ba42b646
SW
548 PCI_CONFIG_8(PCI_REVISION_ID, 0x04);
549 s->stats_size = 76;
550 s->has_extended_tcb_support = 1;
663e8e51
TS
551 break;
552 case i82558B:
d6fd1e66 553 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
508cc6b4
MT
554 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
555 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
663e8e51 556 PCI_CONFIG_8(PCI_REVISION_ID, 0x05);
ba42b646
SW
557 s->stats_size = 76;
558 s->has_extended_tcb_support = 1;
559 break;
560 case i82559A:
561 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
508cc6b4
MT
562 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
563 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
ba42b646
SW
564 PCI_CONFIG_8(PCI_REVISION_ID, 0x06);
565 s->stats_size = 80;
566 s->has_extended_tcb_support = 1;
567 break;
568 case i82559B:
569 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
508cc6b4
MT
570 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
571 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
ba42b646
SW
572 PCI_CONFIG_8(PCI_REVISION_ID, 0x07);
573 s->stats_size = 80;
574 s->has_extended_tcb_support = 1;
663e8e51
TS
575 break;
576 case i82559C:
d6fd1e66 577 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
508cc6b4
MT
578 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
579 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
ba42b646 580 PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
e7493b25 581 /* TODO: Windows wants revision id 0x0c. */
ba42b646
SW
582 PCI_CONFIG_8(PCI_REVISION_ID, 0x0c);
583#if EEPROM_SIZE > 0
584 PCI_CONFIG_16(PCI_SUBSYSTEM_VENDOR_ID, 0x8086);
585 PCI_CONFIG_16(PCI_SUBSYSTEM_ID, 0x0040);
586#endif
587 s->stats_size = 80;
588 s->has_extended_tcb_support = 1;
663e8e51
TS
589 break;
590 case i82559ER:
d6fd1e66 591 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
508cc6b4
MT
592 PCI_CONFIG_16(PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM |
593 PCI_STATUS_FAST_BACK | PCI_STATUS_CAP_LIST);
663e8e51 594 PCI_CONFIG_8(PCI_REVISION_ID, 0x09);
ba42b646
SW
595 s->stats_size = 80;
596 s->has_extended_tcb_support = 1;
597 break;
598 case i82562:
e7493b25 599 /* TODO: check device id. */
ba42b646
SW
600 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
601 /* TODO: wrong revision id. */
602 PCI_CONFIG_8(PCI_REVISION_ID, 0x0e);
603 s->stats_size = 80;
604 s->has_extended_tcb_support = 1;
663e8e51 605 break;
663e8e51
TS
606 default:
607 logout("Device %X is undefined!\n", device);
608 }
609
ba42b646
SW
610 s->configuration[6] |= BIT(5);
611
612 if (s->stats_size == 80) {
613 /* TODO: check TCO Statistical Counters bit. Documentation not clear. */
614 if (s->configuration[6] & BIT(2)) {
615 /* TCO statistical counters. */
616 assert(s->configuration[6] & BIT(5));
617 } else {
618 if (s->configuration[6] & BIT(5)) {
619 /* No extended statistical counters, i82557 compatible. */
620 s->stats_size = 64;
621 } else {
622 /* i82558 compatible. */
623 s->stats_size = 76;
624 }
625 }
626 } else {
627 if (s->configuration[6] & BIT(5)) {
628 /* No extended statistical counters. */
629 s->stats_size = 64;
630 }
631 }
632 assert(s->stats_size > 0 && s->stats_size <= sizeof(s->statistics));
633
634 if (power_management) {
635 /* Power Management Capabilities */
636 PCI_CONFIG_8(0xdc, 0x01);
637 /* Next Item Pointer */
638 /* Capability ID */
639 PCI_CONFIG_16(0xde, 0x7e21);
640 /* TODO: Power Management Control / Status. */
641 /* TODO: Ethernet Power Consumption Registers (i82559 and later). */
642 }
643
644#if EEPROM_SIZE > 0
663e8e51 645 if (device == i82557C || device == i82558B || device == i82559C) {
e7493b25
SW
646 /*
647 TODO: get vendor id from EEPROM for i82557C or later.
648 TODO: get device id from EEPROM for i82557C or later.
649 TODO: status bit 4 can be disabled by EEPROM for i82558, i82559.
650 TODO: header type is determined by EEPROM for i82559.
651 TODO: get subsystem id from EEPROM for i82557C or later.
652 TODO: get subsystem vendor id from EEPROM for i82557C or later.
653 TODO: exp. rom baddr depends on a bit in EEPROM for i82558 or later.
654 TODO: capability pointer depends on EEPROM for i82558.
655 */
663e8e51
TS
656 logout("Get device id and revision from EEPROM!!!\n");
657 }
ba42b646 658#endif /* EEPROM_SIZE > 0 */
663e8e51
TS
659}
660
661static void nic_selective_reset(EEPRO100State * s)
662{
663 size_t i;
664 uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
e7493b25
SW
665#if 0
666 eeprom93xx_reset(s->eeprom);
667#endif
508ef936 668 memcpy(eeprom_contents, s->conf.macaddr.a, 6);
b1e87018 669 eeprom_contents[EEPROM_ID] = EEPROM_ID_VALID;
f4e94dfe
RD
670 if (s->device == i82557B || s->device == i82557C)
671 eeprom_contents[5] = 0x0100;
6cded3a4 672 eeprom_contents[EEPROM_PHY_ID] = 1;
663e8e51
TS
673 uint16_t sum = 0;
674 for (i = 0; i < EEPROM_SIZE - 1; i++) {
675 sum += eeprom_contents[i];
676 }
677 eeprom_contents[EEPROM_SIZE - 1] = 0xbaba - sum;
aac443e6 678 TRACE(EEPROM, logout("checksum=0x%04x\n", eeprom_contents[EEPROM_SIZE - 1]));
663e8e51
TS
679
680 memset(s->mem, 0, sizeof(s->mem));
681 uint32_t val = BIT(21);
682 memcpy(&s->mem[SCBCtrlMDI], &val, sizeof(val));
683
684 assert(sizeof(s->mdimem) == sizeof(eepro100_mdi_default));
685 memcpy(&s->mdimem[0], &eepro100_mdi_default[0], sizeof(s->mdimem));
686}
687
688static void nic_reset(void *opaque)
689{
769cf7a5 690 EEPRO100State *s = opaque;
aac443e6 691 TRACE(OTHER, logout("%p\n", s));
7b8737de
SW
692 /* TODO: Clearing of multicast table for selective reset, too? */
693 memset(&s->mult[0], 0, sizeof(s->mult));
663e8e51
TS
694 nic_selective_reset(s);
695}
696
697#if defined(DEBUG_EEPRO100)
b8f6ba0d 698static const char * const e100_reg[PCI_IO_SIZE / 4] = {
663e8e51
TS
699 "Command/Status",
700 "General Pointer",
701 "Port",
702 "EEPROM/Flash Control",
703 "MDI Control",
704 "Receive DMA Byte Count",
b8f6ba0d 705 "Flow Control",
663e8e51
TS
706 "General Status/Control"
707};
708
709static char *regname(uint32_t addr)
710{
ec169288 711 static char buf[32];
663e8e51 712 if (addr < PCI_IO_SIZE) {
b8f6ba0d 713 const char *r = e100_reg[addr / 4];
663e8e51 714 if (r != 0) {
41cbc23c 715 snprintf(buf, sizeof(buf), "%s+%u", r, addr % 4);
663e8e51 716 } else {
41cbc23c 717 snprintf(buf, sizeof(buf), "0x%02x", addr);
663e8e51
TS
718 }
719 } else {
41cbc23c 720 snprintf(buf, sizeof(buf), "??? 0x%08x", addr);
663e8e51
TS
721 }
722 return buf;
723}
724#endif /* DEBUG_EEPRO100 */
725
726#if 0
727static uint16_t eepro100_read_status(EEPRO100State * s)
728{
729 uint16_t val = s->status;
aac443e6 730 TRACE(OTHER, logout("val=0x%04x\n", val));
663e8e51
TS
731 return val;
732}
733
734static void eepro100_write_status(EEPRO100State * s, uint16_t val)
735{
aac443e6 736 TRACE(OTHER, logout("val=0x%04x\n", val));
663e8e51
TS
737 s->status = val;
738}
739#endif
740
741/*****************************************************************************
742 *
743 * Command emulation.
744 *
745 ****************************************************************************/
746
747#if 0
748static uint16_t eepro100_read_command(EEPRO100State * s)
749{
750 uint16_t val = 0xffff;
e7493b25 751 TRACE(OTHER, logout("val=0x%04x\n", val));
663e8e51
TS
752 return val;
753}
754#endif
755
756/* Commands that can be put in a command list entry. */
757enum commands {
758 CmdNOp = 0,
759 CmdIASetup = 1,
760 CmdConfigure = 2,
761 CmdMulticastList = 3,
762 CmdTx = 4,
763 CmdTDR = 5, /* load microcode */
764 CmdDump = 6,
765 CmdDiagnose = 7,
766
767 /* And some extra flags: */
768 CmdSuspend = 0x4000, /* Suspend after completion. */
769 CmdIntr = 0x2000, /* Interrupt after completion. */
770 CmdTxFlex = 0x0008, /* Use "Flexible mode" for CmdTx command. */
771};
772
c227f099 773static cu_state_t get_cu_state(EEPRO100State * s)
663e8e51 774{
ced5296a 775 return ((s->mem[SCBStatus] & BITS(7, 6)) >> 6);
663e8e51
TS
776}
777
c227f099 778static void set_cu_state(EEPRO100State * s, cu_state_t state)
663e8e51 779{
ced5296a 780 s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(7, 6)) + (state << 6);
663e8e51
TS
781}
782
c227f099 783static ru_state_t get_ru_state(EEPRO100State * s)
663e8e51 784{
ced5296a 785 return ((s->mem[SCBStatus] & BITS(5, 2)) >> 2);
663e8e51
TS
786}
787
c227f099 788static void set_ru_state(EEPRO100State * s, ru_state_t state)
663e8e51 789{
ced5296a 790 s->mem[SCBStatus] = (s->mem[SCBStatus] & ~BITS(5, 2)) + (state << 2);
663e8e51
TS
791}
792
793static void dump_statistics(EEPRO100State * s)
794{
795 /* Dump statistical data. Most data is never changed by the emulation
796 * and always 0, so we first just copy the whole block and then those
797 * values which really matter.
798 * Number of data should check configuration!!!
799 */
ba42b646
SW
800 cpu_physical_memory_write(s->statsaddr,
801 (uint8_t *) & s->statistics, s->stats_size);
802 stl_le_phys(s->statsaddr + 0, s->statistics.tx_good_frames);
803 stl_le_phys(s->statsaddr + 36, s->statistics.rx_good_frames);
804 stl_le_phys(s->statsaddr + 48, s->statistics.rx_resource_errors);
805 stl_le_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors);
e7493b25
SW
806#if 0
807 stw_le_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
808 stw_le_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
809 missing("CU dump statistical counters");
810#endif
663e8e51
TS
811}
812
3d0f4b9b
SW
813static void read_cb(EEPRO100State *s)
814{
815 cpu_physical_memory_read(s->cb_address, (uint8_t *) &s->tx, sizeof(s->tx));
816 s->tx.status = le16_to_cpu(s->tx.status);
817 s->tx.command = le16_to_cpu(s->tx.command);
818 s->tx.link = le32_to_cpu(s->tx.link);
819 s->tx.tbd_array_addr = le32_to_cpu(s->tx.tbd_array_addr);
820 s->tx.tcb_bytes = le16_to_cpu(s->tx.tcb_bytes);
821}
822
f3a52e50
SW
823static void tx_command(EEPRO100State *s)
824{
7b8737de 825 uint32_t tbd_array = le32_to_cpu(s->tx.tbd_array_addr);
f3a52e50
SW
826 uint16_t tcb_bytes = (le16_to_cpu(s->tx.tcb_bytes) & 0x3fff);
827 /* Sends larger than MAX_ETH_FRAME_SIZE are allowed, up to 2600 bytes. */
828 uint8_t buf[2600];
829 uint16_t size = 0;
830 uint32_t tbd_address = s->cb_address + 0x10;
831 TRACE(RXTX, logout
832 ("transmit, TBD array address 0x%08x, TCB byte count 0x%04x, TBD count %u\n",
833 tbd_array, tcb_bytes, s->tx.tbd_count));
834
835 if (tcb_bytes > 2600) {
836 logout("TCB byte count too large, using 2600\n");
837 tcb_bytes = 2600;
838 }
839 if (!((tcb_bytes > 0) || (tbd_array != 0xffffffff))) {
840 logout
841 ("illegal values of TBD array address and TCB byte count!\n");
842 }
843 assert(tcb_bytes <= sizeof(buf));
844 while (size < tcb_bytes) {
845 uint32_t tx_buffer_address = ldl_phys(tbd_address);
846 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
e7493b25
SW
847#if 0
848 uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
849#endif
f3a52e50
SW
850 tbd_address += 8;
851 TRACE(RXTX, logout
852 ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
853 tx_buffer_address, tx_buffer_size));
854 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
855 cpu_physical_memory_read(tx_buffer_address, &buf[size],
856 tx_buffer_size);
857 size += tx_buffer_size;
858 }
859 if (tbd_array == 0xffffffff) {
860 /* Simplified mode. Was already handled by code above. */
861 } else {
862 /* Flexible mode. */
863 uint8_t tbd_count = 0;
864 if (s->has_extended_tcb_support && !(s->configuration[6] & BIT(4))) {
865 /* Extended Flexible TCB. */
866 for (; tbd_count < 2; tbd_count++) {
867 uint32_t tx_buffer_address = ldl_phys(tbd_address);
868 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
869 uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
870 tbd_address += 8;
871 TRACE(RXTX, logout
872 ("TBD (extended flexible mode): buffer address 0x%08x, size 0x%04x\n",
873 tx_buffer_address, tx_buffer_size));
874 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
875 cpu_physical_memory_read(tx_buffer_address, &buf[size],
876 tx_buffer_size);
877 size += tx_buffer_size;
878 if (tx_buffer_el & 1) {
879 break;
880 }
881 }
882 }
883 tbd_address = tbd_array;
884 for (; tbd_count < s->tx.tbd_count; tbd_count++) {
885 uint32_t tx_buffer_address = ldl_phys(tbd_address);
886 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
887 uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
888 tbd_address += 8;
889 TRACE(RXTX, logout
890 ("TBD (flexible mode): buffer address 0x%08x, size 0x%04x\n",
891 tx_buffer_address, tx_buffer_size));
892 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
893 cpu_physical_memory_read(tx_buffer_address, &buf[size],
894 tx_buffer_size);
895 size += tx_buffer_size;
896 if (tx_buffer_el & 1) {
897 break;
898 }
899 }
900 }
901 TRACE(RXTX, logout("%p sending frame, len=%d,%s\n", s, size, nic_dump(buf, size)));
902 qemu_send_packet(&s->nic->nc, buf, size);
903 s->statistics.tx_good_frames++;
904 /* Transmit with bad status would raise an CX/TNO interrupt.
905 * (82557 only). Emulation never has bad status. */
e7493b25
SW
906#if 0
907 eepro100_cx_interrupt(s);
908#endif
f3a52e50
SW
909}
910
7b8737de
SW
911static void set_multicast_list(EEPRO100State *s)
912{
913 uint16_t multicast_count = s->tx.tbd_array_addr & BITS(13, 0);
914 uint16_t i;
915 memset(&s->mult[0], 0, sizeof(s->mult));
916 TRACE(OTHER, logout("multicast list, multicast count = %u\n", multicast_count));
917 for (i = 0; i < multicast_count; i += 6) {
918 uint8_t multicast_addr[6];
919 cpu_physical_memory_read(s->cb_address + 10 + i, multicast_addr, 6);
920 TRACE(OTHER, logout("multicast entry %s\n", nic_dump(multicast_addr, 6)));
921 unsigned mcast_idx = compute_mcast_idx(multicast_addr);
922 assert(mcast_idx < 64);
923 s->mult[mcast_idx >> 3] |= (1 << (mcast_idx & 7));
924 }
925}
926
5fa9a0ae 927static void action_command(EEPRO100State *s)
663e8e51 928{
5fa9a0ae 929 for (;;) {
3d0f4b9b
SW
930 bool bit_el;
931 bool bit_s;
932 bool bit_i;
933 bool bit_nc;
7f1e9d4e 934 bool success = true;
3d0f4b9b
SW
935 s->cb_address = s->cu_base + s->cu_offset;
936 read_cb(s);
937 bit_el = ((s->tx.command & COMMAND_EL) != 0);
938 bit_s = ((s->tx.command & COMMAND_S) != 0);
939 bit_i = ((s->tx.command & COMMAND_I) != 0);
940 bit_nc = ((s->tx.command & COMMAND_NC) != 0);
941#if 0
942 bool bit_sf = ((s->tx.command & COMMAND_SF) != 0);
943#endif
944 s->cu_offset = s->tx.link;
945 TRACE(OTHER,
946 logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
947 s->tx.status, s->tx.command, s->tx.link));
948 switch (s->tx.command & COMMAND_CMD) {
663e8e51
TS
949 case CmdNOp:
950 /* Do nothing. */
951 break;
952 case CmdIASetup:
f3a52e50 953 cpu_physical_memory_read(s->cb_address + 8, &s->conf.macaddr.a[0], 6);
ce0e58b3 954 TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6)));
663e8e51
TS
955 break;
956 case CmdConfigure:
f3a52e50 957 cpu_physical_memory_read(s->cb_address + 8, &s->configuration[0],
663e8e51 958 sizeof(s->configuration));
aac443e6 959 TRACE(OTHER, logout("configuration: %s\n", nic_dump(&s->configuration[0], 16)));
663e8e51
TS
960 break;
961 case CmdMulticastList:
7b8737de 962 set_multicast_list(s);
663e8e51
TS
963 break;
964 case CmdTx:
7f1e9d4e
KW
965 if (bit_nc) {
966 missing("CmdTx: NC = 0");
967 success = false;
968 break;
969 }
f3a52e50 970 tx_command(s);
663e8e51
TS
971 break;
972 case CmdTDR:
aac443e6 973 TRACE(OTHER, logout("load microcode\n"));
663e8e51
TS
974 /* Starting with offset 8, the command contains
975 * 64 dwords microcode which we just ignore here. */
976 break;
f80a7fc3
SW
977 case CmdDiagnose:
978 TRACE(OTHER, logout("diagnose\n"));
979 /* Make sure error flag is not set. */
980 s->tx.status = 0;
981 break;
663e8e51
TS
982 default:
983 missing("undefined command");
7f1e9d4e
KW
984 success = false;
985 break;
663e8e51 986 }
7f1e9d4e 987 /* Write new status. */
ec1d02d8 988 stw_phys(s->cb_address, s->tx.status | STATUS_C | (success ? STATUS_OK : 0));
663e8e51
TS
989 if (bit_i) {
990 /* CU completed action. */
991 eepro100_cx_interrupt(s);
992 }
993 if (bit_el) {
aac443e6 994 /* CU becomes idle. Terminate command loop. */
663e8e51
TS
995 set_cu_state(s, cu_idle);
996 eepro100_cna_interrupt(s);
5fa9a0ae 997 break;
663e8e51 998 } else if (bit_s) {
5fa9a0ae 999 /* CU becomes suspended. Terminate command loop. */
663e8e51
TS
1000 set_cu_state(s, cu_suspended);
1001 eepro100_cna_interrupt(s);
5fa9a0ae 1002 break;
663e8e51
TS
1003 } else {
1004 /* More entries in list. */
aac443e6 1005 TRACE(OTHER, logout("CU list with at least one more entry\n"));
663e8e51 1006 }
5fa9a0ae
SW
1007 }
1008 TRACE(OTHER, logout("CU list empty\n"));
1009 /* List is empty. Now CU is idle or suspended. */
1010}
1011
1012static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
1013{
cb25a3fb 1014 cu_state_t cu_state;
5fa9a0ae
SW
1015 switch (val) {
1016 case CU_NOP:
1017 /* No operation. */
1018 break;
1019 case CU_START:
cb25a3fb
SW
1020 cu_state = get_cu_state(s);
1021 if (cu_state != cu_idle && cu_state != cu_suspended) {
1022 /* Intel documentation says that CU must be idle or suspended
1023 * for the CU start command. */
1024 logout("unexpected CU state is %u\n", cu_state);
5fa9a0ae
SW
1025 }
1026 set_cu_state(s, cu_active);
1027 s->cu_offset = s->pointer;
1028 action_command(s);
663e8e51
TS
1029 break;
1030 case CU_RESUME:
1031 if (get_cu_state(s) != cu_suspended) {
1032 logout("bad CU resume from CU state %u\n", get_cu_state(s));
1033 /* Workaround for bad Linux eepro100 driver which resumes
1034 * from idle state. */
e7493b25
SW
1035#if 0
1036 missing("cu resume");
1037#endif
663e8e51
TS
1038 set_cu_state(s, cu_suspended);
1039 }
1040 if (get_cu_state(s) == cu_suspended) {
aac443e6 1041 TRACE(OTHER, logout("CU resuming\n"));
663e8e51 1042 set_cu_state(s, cu_active);
5fa9a0ae 1043 action_command(s);
663e8e51
TS
1044 }
1045 break;
1046 case CU_STATSADDR:
1047 /* Load dump counters address. */
1048 s->statsaddr = s->pointer;
aac443e6 1049 TRACE(OTHER, logout("val=0x%02x (status address)\n", val));
663e8e51
TS
1050 break;
1051 case CU_SHOWSTATS:
1052 /* Dump statistical counters. */
aac443e6 1053 TRACE(OTHER, logout("val=0x%02x (dump stats)\n", val));
663e8e51 1054 dump_statistics(s);
ba42b646 1055 stl_le_phys(s->statsaddr + s->stats_size, 0xa005);
663e8e51
TS
1056 break;
1057 case CU_CMD_BASE:
1058 /* Load CU base. */
aac443e6 1059 TRACE(OTHER, logout("val=0x%02x (CU base address)\n", val));
663e8e51
TS
1060 s->cu_base = s->pointer;
1061 break;
1062 case CU_DUMPSTATS:
1063 /* Dump and reset statistical counters. */
aac443e6 1064 TRACE(OTHER, logout("val=0x%02x (dump stats and reset)\n", val));
663e8e51 1065 dump_statistics(s);
ba42b646 1066 stl_le_phys(s->statsaddr + s->stats_size, 0xa007);
663e8e51
TS
1067 memset(&s->statistics, 0, sizeof(s->statistics));
1068 break;
1069 case CU_SRESUME:
1070 /* CU static resume. */
1071 missing("CU static resume");
1072 break;
1073 default:
1074 missing("Undefined CU command");
1075 }
1076}
1077
1078static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
1079{
1080 switch (val) {
1081 case RU_NOP:
1082 /* No operation. */
1083 break;
1084 case RX_START:
1085 /* RU start. */
1086 if (get_ru_state(s) != ru_idle) {
1087 logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle);
e7493b25
SW
1088#if 0
1089 assert(!"wrong RU state");
1090#endif
663e8e51
TS
1091 }
1092 set_ru_state(s, ru_ready);
1093 s->ru_offset = s->pointer;
aac443e6 1094 TRACE(OTHER, logout("val=0x%02x (rx start)\n", val));
663e8e51
TS
1095 break;
1096 case RX_RESUME:
1097 /* Restart RU. */
1098 if (get_ru_state(s) != ru_suspended) {
1099 logout("RU state is %u, should be %u\n", get_ru_state(s),
1100 ru_suspended);
e7493b25
SW
1101#if 0
1102 assert(!"wrong RU state");
1103#endif
663e8e51
TS
1104 }
1105 set_ru_state(s, ru_ready);
1106 break;
e824012b
SW
1107 case RU_ABORT:
1108 /* RU abort. */
1109 if (get_ru_state(s) == ru_ready) {
1110 eepro100_rnr_interrupt(s);
1111 }
1112 set_ru_state(s, ru_idle);
1113 break;
663e8e51
TS
1114 case RX_ADDR_LOAD:
1115 /* Load RU base. */
aac443e6 1116 TRACE(OTHER, logout("val=0x%02x (RU base address)\n", val));
663e8e51
TS
1117 s->ru_base = s->pointer;
1118 break;
1119 default:
1120 logout("val=0x%02x (undefined RU command)\n", val);
1121 missing("Undefined SU command");
1122 }
1123}
1124
1125static void eepro100_write_command(EEPRO100State * s, uint8_t val)
1126{
1127 eepro100_ru_command(s, val & 0x0f);
1128 eepro100_cu_command(s, val & 0xf0);
1129 if ((val) == 0) {
aac443e6 1130 TRACE(OTHER, logout("val=0x%02x\n", val));
663e8e51
TS
1131 }
1132 /* Clear command byte after command was accepted. */
1133 s->mem[SCBCmd] = 0;
1134}
1135
1136/*****************************************************************************
1137 *
1138 * EEPROM emulation.
1139 *
1140 ****************************************************************************/
1141
1142#define EEPROM_CS 0x02
1143#define EEPROM_SK 0x01
1144#define EEPROM_DI 0x04
1145#define EEPROM_DO 0x08
1146
1147static uint16_t eepro100_read_eeprom(EEPRO100State * s)
1148{
1149 uint16_t val;
1150 memcpy(&val, &s->mem[SCBeeprom], sizeof(val));
1151 if (eeprom93xx_read(s->eeprom)) {
1152 val |= EEPROM_DO;
1153 } else {
1154 val &= ~EEPROM_DO;
1155 }
aac443e6 1156 TRACE(EEPROM, logout("val=0x%04x\n", val));
663e8e51
TS
1157 return val;
1158}
1159
c227f099 1160static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val)
663e8e51 1161{
aac443e6 1162 TRACE(EEPROM, logout("val=0x%02x\n", val));
663e8e51
TS
1163
1164 /* mask unwriteable bits */
e7493b25
SW
1165#if 0
1166 val = SET_MASKED(val, 0x31, eeprom->value);
1167#endif
663e8e51
TS
1168
1169 int eecs = ((val & EEPROM_CS) != 0);
1170 int eesk = ((val & EEPROM_SK) != 0);
1171 int eedi = ((val & EEPROM_DI) != 0);
1172 eeprom93xx_write(eeprom, eecs, eesk, eedi);
1173}
1174
1175static void eepro100_write_pointer(EEPRO100State * s, uint32_t val)
1176{
1177 s->pointer = le32_to_cpu(val);
aac443e6 1178 TRACE(OTHER, logout("val=0x%08x\n", val));
663e8e51
TS
1179}
1180
1181/*****************************************************************************
1182 *
1183 * MDI emulation.
1184 *
1185 ****************************************************************************/
1186
1187#if defined(DEBUG_EEPRO100)
6a0b9cc9 1188static const char * const mdi_op_name[] = {
663e8e51
TS
1189 "opcode 0",
1190 "write",
1191 "read",
1192 "opcode 3"
1193};
1194
6a0b9cc9 1195static const char * const mdi_reg_name[] = {
663e8e51
TS
1196 "Control",
1197 "Status",
1198 "PHY Identification (Word 1)",
1199 "PHY Identification (Word 2)",
1200 "Auto-Negotiation Advertisement",
1201 "Auto-Negotiation Link Partner Ability",
1202 "Auto-Negotiation Expansion"
1203};
aac443e6
SW
1204
1205static const char *reg2name(uint8_t reg)
1206{
1207 static char buffer[10];
1208 const char *p = buffer;
1209 if (reg < ARRAY_SIZE(mdi_reg_name)) {
1210 p = mdi_reg_name[reg];
1211 } else {
1212 snprintf(buffer, sizeof(buffer), "reg=0x%02x", reg);
1213 }
1214 return p;
1215}
663e8e51
TS
1216#endif /* DEBUG_EEPRO100 */
1217
1218static uint32_t eepro100_read_mdi(EEPRO100State * s)
1219{
1220 uint32_t val;
1221 memcpy(&val, &s->mem[0x10], sizeof(val));
1222
1223#ifdef DEBUG_EEPRO100
1224 uint8_t raiseint = (val & BIT(29)) >> 29;
1225 uint8_t opcode = (val & BITS(27, 26)) >> 26;
1226 uint8_t phy = (val & BITS(25, 21)) >> 21;
1227 uint8_t reg = (val & BITS(20, 16)) >> 16;
1228 uint16_t data = (val & BITS(15, 0));
1229#endif
1230 /* Emulation takes no time to finish MDI transaction. */
1231 val |= BIT(28);
1232 TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n",
1233 val, raiseint, mdi_op_name[opcode], phy,
aac443e6 1234 reg2name(reg), data));
663e8e51
TS
1235 return val;
1236}
1237
663e8e51
TS
1238static void eepro100_write_mdi(EEPRO100State * s, uint32_t val)
1239{
1240 uint8_t raiseint = (val & BIT(29)) >> 29;
1241 uint8_t opcode = (val & BITS(27, 26)) >> 26;
1242 uint8_t phy = (val & BITS(25, 21)) >> 21;
1243 uint8_t reg = (val & BITS(20, 16)) >> 16;
1244 uint16_t data = (val & BITS(15, 0));
aac443e6
SW
1245 TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n",
1246 val, raiseint, mdi_op_name[opcode], phy, reg2name(reg), data));
663e8e51
TS
1247 if (phy != 1) {
1248 /* Unsupported PHY address. */
e7493b25
SW
1249#if 0
1250 logout("phy must be 1 but is %u\n", phy);
1251#endif
663e8e51
TS
1252 data = 0;
1253 } else if (opcode != 1 && opcode != 2) {
1254 /* Unsupported opcode. */
1255 logout("opcode must be 1 or 2 but is %u\n", opcode);
1256 data = 0;
1257 } else if (reg > 6) {
1258 /* Unsupported register. */
1259 logout("register must be 0...6 but is %u\n", reg);
1260 data = 0;
1261 } else {
1262 TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n",
1263 val, raiseint, mdi_op_name[opcode], phy,
aac443e6 1264 reg2name(reg), data));
663e8e51
TS
1265 if (opcode == 1) {
1266 /* MDI write */
1267 switch (reg) {
1268 case 0: /* Control Register */
1269 if (data & 0x8000) {
1270 /* Reset status and control registers to default. */
1271 s->mdimem[0] = eepro100_mdi_default[0];
1272 s->mdimem[1] = eepro100_mdi_default[1];
1273 data = s->mdimem[reg];
1274 } else {
1275 /* Restart Auto Configuration = Normal Operation */
1276 data &= ~0x0200;
1277 }
1278 break;
1279 case 1: /* Status Register */
1280 missing("not writable");
1281 data = s->mdimem[reg];
1282 break;
1283 case 2: /* PHY Identification Register (Word 1) */
1284 case 3: /* PHY Identification Register (Word 2) */
1285 missing("not implemented");
1286 break;
1287 case 4: /* Auto-Negotiation Advertisement Register */
1288 case 5: /* Auto-Negotiation Link Partner Ability Register */
1289 break;
1290 case 6: /* Auto-Negotiation Expansion Register */
1291 default:
1292 missing("not implemented");
1293 }
1294 s->mdimem[reg] = data;
1295 } else if (opcode == 2) {
1296 /* MDI read */
1297 switch (reg) {
1298 case 0: /* Control Register */
1299 if (data & 0x8000) {
1300 /* Reset status and control registers to default. */
1301 s->mdimem[0] = eepro100_mdi_default[0];
1302 s->mdimem[1] = eepro100_mdi_default[1];
1303 }
1304 break;
1305 case 1: /* Status Register */
1306 s->mdimem[reg] |= 0x0020;
1307 break;
1308 case 2: /* PHY Identification Register (Word 1) */
1309 case 3: /* PHY Identification Register (Word 2) */
1310 case 4: /* Auto-Negotiation Advertisement Register */
1311 break;
1312 case 5: /* Auto-Negotiation Link Partner Ability Register */
1313 s->mdimem[reg] = 0x41fe;
1314 break;
1315 case 6: /* Auto-Negotiation Expansion Register */
1316 s->mdimem[reg] = 0x0001;
1317 break;
1318 }
1319 data = s->mdimem[reg];
1320 }
1321 /* Emulation takes no time to finish MDI transaction.
1322 * Set MDI bit in SCB status register. */
1323 s->mem[SCBAck] |= 0x08;
1324 val |= BIT(28);
1325 if (raiseint) {
1326 eepro100_mdi_interrupt(s);
1327 }
1328 }
1329 val = (val & 0xffff0000) + data;
1330 memcpy(&s->mem[0x10], &val, sizeof(val));
1331}
1332
1333/*****************************************************************************
1334 *
1335 * Port emulation.
1336 *
1337 ****************************************************************************/
1338
1339#define PORT_SOFTWARE_RESET 0
1340#define PORT_SELFTEST 1
1341#define PORT_SELECTIVE_RESET 2
1342#define PORT_DUMP 3
1343#define PORT_SELECTION_MASK 3
1344
1345typedef struct {
1346 uint32_t st_sign; /* Self Test Signature */
1347 uint32_t st_result; /* Self Test Results */
c227f099 1348} eepro100_selftest_t;
663e8e51
TS
1349
1350static uint32_t eepro100_read_port(EEPRO100State * s)
1351{
1352 return 0;
1353}
1354
1355static void eepro100_write_port(EEPRO100State * s, uint32_t val)
1356{
1357 val = le32_to_cpu(val);
1358 uint32_t address = (val & ~PORT_SELECTION_MASK);
1359 uint8_t selection = (val & PORT_SELECTION_MASK);
1360 switch (selection) {
1361 case PORT_SOFTWARE_RESET:
1362 nic_reset(s);
1363 break;
1364 case PORT_SELFTEST:
aac443e6 1365 TRACE(OTHER, logout("selftest address=0x%08x\n", address));
c227f099 1366 eepro100_selftest_t data;
663e8e51
TS
1367 cpu_physical_memory_read(address, (uint8_t *) & data, sizeof(data));
1368 data.st_sign = 0xffffffff;
1369 data.st_result = 0;
1370 cpu_physical_memory_write(address, (uint8_t *) & data, sizeof(data));
1371 break;
1372 case PORT_SELECTIVE_RESET:
aac443e6 1373 TRACE(OTHER, logout("selective reset, selftest address=0x%08x\n", address));
663e8e51
TS
1374 nic_selective_reset(s);
1375 break;
1376 default:
1377 logout("val=0x%08x\n", val);
1378 missing("unknown port selection");
1379 }
1380}
1381
1382/*****************************************************************************
1383 *
1384 * General hardware emulation.
1385 *
1386 ****************************************************************************/
1387
1388static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
1389{
1390 uint8_t val;
1391 if (addr <= sizeof(s->mem) - sizeof(val)) {
1392 memcpy(&val, &s->mem[addr], sizeof(val));
1393 }
1394
1395 switch (addr) {
1396 case SCBStatus:
e7493b25
SW
1397#if 0
1398 val = eepro100_read_status(s);
1399#endif
aac443e6 1400 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1401 break;
1402 case SCBAck:
e7493b25
SW
1403#if 0
1404 val = eepro100_read_status(s);
1405#endif
aac443e6 1406 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1407 break;
1408 case SCBCmd:
aac443e6 1409 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
e7493b25
SW
1410#if 0
1411 val = eepro100_read_command(s);
1412#endif
663e8e51
TS
1413 break;
1414 case SCBIntmask:
aac443e6 1415 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1416 break;
1417 case SCBPort + 3:
aac443e6 1418 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1419 break;
1420 case SCBeeprom:
1421 val = eepro100_read_eeprom(s);
1422 break;
0908bba1 1423 case SCBpmdr: /* Power Management Driver Register */
663e8e51 1424 val = 0;
aac443e6 1425 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51 1426 break;
0908bba1 1427 case SCBgstat: /* General Status Register */
663e8e51
TS
1428 /* 100 Mbps full duplex, valid link */
1429 val = 0x07;
aac443e6 1430 TRACE(OTHER, logout("addr=General Status val=%02x\n", val));
663e8e51
TS
1431 break;
1432 default:
1433 logout("addr=%s val=0x%02x\n", regname(addr), val);
1434 missing("unknown byte read");
1435 }
1436 return val;
1437}
1438
1439static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr)
1440{
1441 uint16_t val;
1442 if (addr <= sizeof(s->mem) - sizeof(val)) {
1443 memcpy(&val, &s->mem[addr], sizeof(val));
1444 }
1445
663e8e51
TS
1446 switch (addr) {
1447 case SCBStatus:
e7493b25
SW
1448#if 0
1449 val = eepro100_read_status(s);
1450#endif
dbbaaff6 1451 case SCBCmd:
aac443e6 1452 TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
663e8e51
TS
1453 break;
1454 case SCBeeprom:
1455 val = eepro100_read_eeprom(s);
aac443e6 1456 TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
663e8e51
TS
1457 break;
1458 default:
1459 logout("addr=%s val=0x%04x\n", regname(addr), val);
1460 missing("unknown word read");
1461 }
1462 return val;
1463}
1464
1465static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr)
1466{
1467 uint32_t val;
1468 if (addr <= sizeof(s->mem) - sizeof(val)) {
1469 memcpy(&val, &s->mem[addr], sizeof(val));
1470 }
1471
1472 switch (addr) {
1473 case SCBStatus:
e7493b25
SW
1474#if 0
1475 val = eepro100_read_status(s);
1476#endif
aac443e6 1477 TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
663e8e51
TS
1478 break;
1479 case SCBPointer:
e7493b25
SW
1480#if 0
1481 val = eepro100_read_pointer(s);
1482#endif
aac443e6 1483 TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
663e8e51
TS
1484 break;
1485 case SCBPort:
1486 val = eepro100_read_port(s);
aac443e6 1487 TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
663e8e51
TS
1488 break;
1489 case SCBCtrlMDI:
1490 val = eepro100_read_mdi(s);
1491 break;
1492 default:
1493 logout("addr=%s val=0x%08x\n", regname(addr), val);
1494 missing("unknown longword read");
1495 }
1496 return val;
1497}
1498
1499static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
1500{
1501 if (addr <= sizeof(s->mem) - sizeof(val)) {
1502 memcpy(&s->mem[addr], &val, sizeof(val));
1503 }
1504
aac443e6 1505 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1506
1507 switch (addr) {
1508 case SCBStatus:
e7493b25
SW
1509#if 0
1510 eepro100_write_status(s, val);
1511#endif
663e8e51
TS
1512 break;
1513 case SCBAck:
1514 eepro100_acknowledge(s);
1515 break;
1516 case SCBCmd:
1517 eepro100_write_command(s, val);
1518 break;
1519 case SCBIntmask:
1520 if (val & BIT(1)) {
1521 eepro100_swi_interrupt(s);
1522 }
1523 eepro100_interrupt(s, 0);
1524 break;
1525 case SCBPort + 3:
aac443e6 1526 case SCBFlow: /* does not exist on 82557 */
3257d2b6
TS
1527 case SCBFlow + 1:
1528 case SCBFlow + 2:
0908bba1 1529 case SCBpmdr: /* does not exist on 82557 */
aac443e6 1530 TRACE(OTHER, logout("addr=%s val=0x%02x\n", regname(addr), val));
663e8e51
TS
1531 break;
1532 case SCBeeprom:
1533 eepro100_write_eeprom(s->eeprom, val);
1534 break;
1535 default:
1536 logout("addr=%s val=0x%02x\n", regname(addr), val);
1537 missing("unknown byte write");
1538 }
1539}
1540
1541static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val)
1542{
1543 if (addr <= sizeof(s->mem) - sizeof(val)) {
1544 memcpy(&s->mem[addr], &val, sizeof(val));
1545 }
1546
aac443e6 1547 TRACE(OTHER, logout("addr=%s val=0x%04x\n", regname(addr), val));
663e8e51
TS
1548
1549 switch (addr) {
1550 case SCBStatus:
e7493b25
SW
1551#if 0
1552 eepro100_write_status(s, val);
1553#endif
663e8e51
TS
1554 eepro100_acknowledge(s);
1555 break;
1556 case SCBCmd:
1557 eepro100_write_command(s, val);
1558 eepro100_write1(s, SCBIntmask, val >> 8);
1559 break;
1560 case SCBeeprom:
1561 eepro100_write_eeprom(s->eeprom, val);
1562 break;
1563 default:
1564 logout("addr=%s val=0x%04x\n", regname(addr), val);
1565 missing("unknown word write");
1566 }
1567}
1568
1569static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val)
1570{
1571 if (addr <= sizeof(s->mem) - sizeof(val)) {
1572 memcpy(&s->mem[addr], &val, sizeof(val));
1573 }
1574
1575 switch (addr) {
1576 case SCBPointer:
1577 eepro100_write_pointer(s, val);
1578 break;
1579 case SCBPort:
aac443e6 1580 TRACE(OTHER, logout("addr=%s val=0x%08x\n", regname(addr), val));
663e8e51
TS
1581 eepro100_write_port(s, val);
1582 break;
1583 case SCBCtrlMDI:
1584 eepro100_write_mdi(s, val);
1585 break;
1586 default:
1587 logout("addr=%s val=0x%08x\n", regname(addr), val);
1588 missing("unknown longword write");
1589 }
1590}
1591
aac443e6
SW
1592/*****************************************************************************
1593 *
1594 * Port mapped I/O.
1595 *
1596 ****************************************************************************/
1597
663e8e51
TS
1598static uint32_t ioport_read1(void *opaque, uint32_t addr)
1599{
1600 EEPRO100State *s = opaque;
e7493b25
SW
1601#if 0
1602 logout("addr=%s\n", regname(addr));
1603#endif
663e8e51
TS
1604 return eepro100_read1(s, addr - s->region[1]);
1605}
1606
1607static uint32_t ioport_read2(void *opaque, uint32_t addr)
1608{
1609 EEPRO100State *s = opaque;
1610 return eepro100_read2(s, addr - s->region[1]);
1611}
1612
1613static uint32_t ioport_read4(void *opaque, uint32_t addr)
1614{
1615 EEPRO100State *s = opaque;
1616 return eepro100_read4(s, addr - s->region[1]);
1617}
1618
1619static void ioport_write1(void *opaque, uint32_t addr, uint32_t val)
1620{
1621 EEPRO100State *s = opaque;
e7493b25
SW
1622#if 0
1623 logout("addr=%s val=0x%02x\n", regname(addr), val);
1624#endif
663e8e51
TS
1625 eepro100_write1(s, addr - s->region[1], val);
1626}
1627
1628static void ioport_write2(void *opaque, uint32_t addr, uint32_t val)
1629{
1630 EEPRO100State *s = opaque;
1631 eepro100_write2(s, addr - s->region[1], val);
1632}
1633
1634static void ioport_write4(void *opaque, uint32_t addr, uint32_t val)
1635{
1636 EEPRO100State *s = opaque;
1637 eepro100_write4(s, addr - s->region[1], val);
1638}
1639
1640/***********************************************************/
1641/* PCI EEPRO100 definitions */
1642
663e8e51 1643static void pci_map(PCIDevice * pci_dev, int region_num,
6e355d90 1644 pcibus_t addr, pcibus_t size, int type)
663e8e51 1645{
273a2142 1646 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51 1647
89e8b13c
IY
1648 TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", "
1649 "size=0x%08"FMT_PCIBUS", type=%d\n",
aac443e6 1650 region_num, addr, size, type));
663e8e51
TS
1651
1652 assert(region_num == 1);
1653 register_ioport_write(addr, size, 1, ioport_write1, s);
1654 register_ioport_read(addr, size, 1, ioport_read1, s);
1655 register_ioport_write(addr, size, 2, ioport_write2, s);
1656 register_ioport_read(addr, size, 2, ioport_read2, s);
1657 register_ioport_write(addr, size, 4, ioport_write4, s);
1658 register_ioport_read(addr, size, 4, ioport_read4, s);
1659
1660 s->region[region_num] = addr;
1661}
1662
aac443e6
SW
1663/*****************************************************************************
1664 *
1665 * Memory mapped I/O.
1666 *
1667 ****************************************************************************/
1668
c227f099 1669static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
663e8e51
TS
1670{
1671 EEPRO100State *s = opaque;
e7493b25
SW
1672#if 0
1673 logout("addr=%s val=0x%02x\n", regname(addr), val);
1674#endif
663e8e51
TS
1675 eepro100_write1(s, addr, val);
1676}
1677
c227f099 1678static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
663e8e51
TS
1679{
1680 EEPRO100State *s = opaque;
e7493b25
SW
1681#if 0
1682 logout("addr=%s val=0x%02x\n", regname(addr), val);
1683#endif
663e8e51
TS
1684 eepro100_write2(s, addr, val);
1685}
1686
c227f099 1687static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
663e8e51
TS
1688{
1689 EEPRO100State *s = opaque;
e7493b25
SW
1690#if 0
1691 logout("addr=%s val=0x%02x\n", regname(addr), val);
1692#endif
663e8e51
TS
1693 eepro100_write4(s, addr, val);
1694}
1695
c227f099 1696static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
663e8e51
TS
1697{
1698 EEPRO100State *s = opaque;
e7493b25
SW
1699#if 0
1700 logout("addr=%s\n", regname(addr));
1701#endif
663e8e51
TS
1702 return eepro100_read1(s, addr);
1703}
1704
c227f099 1705static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
663e8e51
TS
1706{
1707 EEPRO100State *s = opaque;
e7493b25
SW
1708#if 0
1709 logout("addr=%s\n", regname(addr));
1710#endif
663e8e51
TS
1711 return eepro100_read2(s, addr);
1712}
1713
c227f099 1714static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
663e8e51
TS
1715{
1716 EEPRO100State *s = opaque;
e7493b25
SW
1717#if 0
1718 logout("addr=%s\n", regname(addr));
1719#endif
663e8e51
TS
1720 return eepro100_read4(s, addr);
1721}
1722
d60efc6b 1723static CPUWriteMemoryFunc * const pci_mmio_write[] = {
663e8e51
TS
1724 pci_mmio_writeb,
1725 pci_mmio_writew,
1726 pci_mmio_writel
1727};
1728
d60efc6b 1729static CPUReadMemoryFunc * const pci_mmio_read[] = {
663e8e51
TS
1730 pci_mmio_readb,
1731 pci_mmio_readw,
1732 pci_mmio_readl
1733};
1734
1735static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
6e355d90 1736 pcibus_t addr, pcibus_t size, int type)
663e8e51 1737{
273a2142 1738 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51 1739
89e8b13c
IY
1740 TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", "
1741 "size=0x%08"FMT_PCIBUS", type=%d\n",
aac443e6 1742 region_num, addr, size, type));
663e8e51
TS
1743
1744 if (region_num == 0) {
1745 /* Map control / status registers. */
273a2142
JQ
1746 cpu_register_physical_memory(addr, size, s->mmio_index);
1747 s->region[region_num] = addr;
663e8e51
TS
1748 }
1749}
1750
e00e365e 1751static int nic_can_receive(VLANClientState *nc)
663e8e51 1752{
e00e365e 1753 EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
aac443e6 1754 TRACE(RXTX, logout("%p\n", s));
663e8e51 1755 return get_ru_state(s) == ru_ready;
e7493b25
SW
1756#if 0
1757 return !eepro100_buffer_full(s);
1758#endif
663e8e51
TS
1759}
1760
e00e365e 1761static ssize_t nic_receive(VLANClientState *nc, const uint8_t * buf, size_t size)
663e8e51
TS
1762{
1763 /* TODO:
1764 * - Magic packets should set bit 30 in power management driver register.
1765 * - Interesting packets should set bit 29 in power management driver register.
1766 */
e00e365e 1767 EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
663e8e51
TS
1768 uint16_t rfd_status = 0xa000;
1769 static const uint8_t broadcast_macaddr[6] =
1770 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1771
1772 /* TODO: check multiple IA bit. */
7f1e9d4e
KW
1773 if (s->configuration[20] & BIT(6)) {
1774 missing("Multiple IA bit");
1775 return -1;
1776 }
663e8e51
TS
1777
1778 if (s->configuration[8] & 0x80) {
1779 /* CSMA is disabled. */
1780 logout("%p received while CSMA is disabled\n", s);
4f1c942b 1781 return -1;
ced5296a 1782 } else if (size < 64 && (s->configuration[7] & BIT(0))) {
663e8e51
TS
1783 /* Short frame and configuration byte 7/0 (discard short receive) set:
1784 * Short frame is discarded */
067d01de 1785 logout("%p received short frame (%zu byte)\n", s, size);
663e8e51 1786 s->statistics.rx_short_frame_errors++;
e7493b25
SW
1787#if 0
1788 return -1;
1789#endif
ced5296a 1790 } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & BIT(3))) {
663e8e51
TS
1791 /* Long frame and configuration byte 18/3 (long receive ok) not set:
1792 * Long frames are discarded. */
067d01de 1793 logout("%p received long frame (%zu byte), ignored\n", s, size);
4f1c942b 1794 return -1;
e7493b25 1795 } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) { /* !!! */
663e8e51
TS
1796 /* Frame matches individual address. */
1797 /* TODO: check configuration byte 15/4 (ignore U/L). */
067d01de 1798 TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size));
663e8e51
TS
1799 } else if (memcmp(buf, broadcast_macaddr, 6) == 0) {
1800 /* Broadcast frame. */
067d01de 1801 TRACE(RXTX, logout("%p received broadcast, len=%zu\n", s, size));
663e8e51 1802 rfd_status |= 0x0002;
7b8737de 1803 } else if (buf[0] & 0x01) {
663e8e51 1804 /* Multicast frame. */
7b8737de 1805 TRACE(RXTX, logout("%p received multicast, len=%zu,%s\n", s, size, nic_dump(buf, size)));
7f1e9d4e 1806 if (s->configuration[21] & BIT(3)) {
7b8737de
SW
1807 /* Multicast all bit is set, receive all multicast frames. */
1808 } else {
1809 unsigned mcast_idx = compute_mcast_idx(buf);
1810 assert(mcast_idx < 64);
1811 if (s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))) {
1812 /* Multicast frame is allowed in hash table. */
ced5296a 1813 } else if (s->configuration[15] & BIT(0)) {
7b8737de
SW
1814 /* Promiscuous: receive all. */
1815 rfd_status |= 0x0004;
1816 } else {
1817 TRACE(RXTX, logout("%p multicast ignored\n", s));
1818 return -1;
1819 }
663e8e51 1820 }
7b8737de 1821 /* TODO: Next not for promiscuous mode? */
663e8e51 1822 rfd_status |= 0x0002;
ced5296a 1823 } else if (s->configuration[15] & BIT(0)) {
663e8e51 1824 /* Promiscuous: receive all. */
067d01de 1825 TRACE(RXTX, logout("%p received frame in promiscuous mode, len=%zu\n", s, size));
663e8e51
TS
1826 rfd_status |= 0x0004;
1827 } else {
067d01de 1828 TRACE(RXTX, logout("%p received frame, ignored, len=%zu,%s\n", s, size,
aac443e6 1829 nic_dump(buf, size)));
4f1c942b 1830 return size;
663e8e51
TS
1831 }
1832
1833 if (get_ru_state(s) != ru_ready) {
aac443e6
SW
1834 /* No resources available. */
1835 logout("no resources, state=%u\n", get_ru_state(s));
e824012b
SW
1836 /* TODO: RNR interrupt only at first failed frame? */
1837 eepro100_rnr_interrupt(s);
663e8e51 1838 s->statistics.rx_resource_errors++;
e7493b25
SW
1839#if 0
1840 assert(!"no resources");
1841#endif
4f1c942b 1842 return -1;
663e8e51 1843 }
e7493b25 1844 /* !!! */
c227f099 1845 eepro100_rx_t rx;
663e8e51 1846 cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx,
c227f099 1847 offsetof(eepro100_rx_t, packet));
663e8e51
TS
1848 uint16_t rfd_command = le16_to_cpu(rx.command);
1849 uint16_t rfd_size = le16_to_cpu(rx.size);
7f1e9d4e
KW
1850
1851 if (size > rfd_size) {
1852 logout("Receive buffer (%" PRId16 " bytes) too small for data "
1853 "(%zu bytes); data truncated\n", rfd_size, size);
1854 size = rfd_size;
1855 }
663e8e51
TS
1856 if (size < 64) {
1857 rfd_status |= 0x0080;
1858 }
aac443e6
SW
1859 TRACE(OTHER, logout("command 0x%04x, link 0x%08x, addr 0x%08x, size %u\n",
1860 rfd_command, rx.link, rx.rx_buf_addr, rfd_size));
c227f099 1861 stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, status),
663e8e51 1862 rfd_status);
c227f099 1863 stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size);
663e8e51 1864 /* Early receive interrupt not supported. */
e7493b25
SW
1865#if 0
1866 eepro100_er_interrupt(s);
1867#endif
663e8e51 1868 /* Receive CRC Transfer not supported. */
ced5296a 1869 if (s->configuration[18] & BIT(2)) {
7f1e9d4e
KW
1870 missing("Receive CRC Transfer");
1871 return -1;
1872 }
663e8e51 1873 /* TODO: check stripping enable bit. */
e7493b25
SW
1874#if 0
1875 assert(!(s->configuration[17] & BIT(0)));
1876#endif
663e8e51 1877 cpu_physical_memory_write(s->ru_base + s->ru_offset +
c227f099 1878 offsetof(eepro100_rx_t, packet), buf, size);
663e8e51
TS
1879 s->statistics.rx_good_frames++;
1880 eepro100_fr_interrupt(s);
1881 s->ru_offset = le32_to_cpu(rx.link);
ced5296a 1882 if (rfd_command & COMMAND_EL) {
663e8e51 1883 /* EL bit is set, so this was the last frame. */
7f1e9d4e
KW
1884 logout("receive: Running out of frames\n");
1885 set_ru_state(s, ru_suspended);
663e8e51 1886 }
ced5296a 1887 if (rfd_command & COMMAND_S) {
663e8e51
TS
1888 /* S bit is set. */
1889 set_ru_state(s, ru_suspended);
1890 }
4f1c942b 1891 return size;
663e8e51
TS
1892}
1893
151b2986
JQ
1894static const VMStateDescription vmstate_eepro100 = {
1895 .version_id = 3,
1896 .minimum_version_id = 2,
1897 .minimum_version_id_old = 2,
1898 .fields = (VMStateField []) {
1899 VMSTATE_PCI_DEVICE(dev, EEPRO100State),
1900 VMSTATE_UNUSED(32),
1901 VMSTATE_BUFFER(mult, EEPRO100State),
1902 VMSTATE_BUFFER(mem, EEPRO100State),
1903 /* Save all members of struct between scb_stat and mem. */
1904 VMSTATE_UINT8(scb_stat, EEPRO100State),
1905 VMSTATE_UINT8(int_stat, EEPRO100State),
1906 VMSTATE_UNUSED(3*4),
1907 VMSTATE_MACADDR(conf.macaddr, EEPRO100State),
1908 VMSTATE_UNUSED(19*4),
1909 VMSTATE_UINT16_ARRAY(mdimem, EEPRO100State, 32),
1910 /* The eeprom should be saved and restored by its own routines. */
1911 VMSTATE_UINT32(device, EEPRO100State),
1912 /* TODO check device. */
1913 VMSTATE_UINT32(pointer, EEPRO100State),
1914 VMSTATE_UINT32(cu_base, EEPRO100State),
1915 VMSTATE_UINT32(cu_offset, EEPRO100State),
1916 VMSTATE_UINT32(ru_base, EEPRO100State),
1917 VMSTATE_UINT32(ru_offset, EEPRO100State),
1918 VMSTATE_UINT32(statsaddr, EEPRO100State),
ba42b646 1919 /* Save eepro100_stats_t statistics. */
151b2986
JQ
1920 VMSTATE_UINT32(statistics.tx_good_frames, EEPRO100State),
1921 VMSTATE_UINT32(statistics.tx_max_collisions, EEPRO100State),
1922 VMSTATE_UINT32(statistics.tx_late_collisions, EEPRO100State),
1923 VMSTATE_UINT32(statistics.tx_underruns, EEPRO100State),
1924 VMSTATE_UINT32(statistics.tx_lost_crs, EEPRO100State),
1925 VMSTATE_UINT32(statistics.tx_deferred, EEPRO100State),
1926 VMSTATE_UINT32(statistics.tx_single_collisions, EEPRO100State),
1927 VMSTATE_UINT32(statistics.tx_multiple_collisions, EEPRO100State),
1928 VMSTATE_UINT32(statistics.tx_total_collisions, EEPRO100State),
1929 VMSTATE_UINT32(statistics.rx_good_frames, EEPRO100State),
1930 VMSTATE_UINT32(statistics.rx_crc_errors, EEPRO100State),
1931 VMSTATE_UINT32(statistics.rx_alignment_errors, EEPRO100State),
1932 VMSTATE_UINT32(statistics.rx_resource_errors, EEPRO100State),
1933 VMSTATE_UINT32(statistics.rx_overrun_errors, EEPRO100State),
1934 VMSTATE_UINT32(statistics.rx_cdt_errors, EEPRO100State),
1935 VMSTATE_UINT32(statistics.rx_short_frame_errors, EEPRO100State),
1936 VMSTATE_UINT32(statistics.fc_xmt_pause, EEPRO100State),
1937 VMSTATE_UINT32(statistics.fc_rcv_pause, EEPRO100State),
1938 VMSTATE_UINT32(statistics.fc_rcv_unsupported, EEPRO100State),
1939 VMSTATE_UINT16(statistics.xmt_tco_frames, EEPRO100State),
1940 VMSTATE_UINT16(statistics.rcv_tco_frames, EEPRO100State),
2657c663 1941#if 0
151b2986 1942 VMSTATE_UINT16(status, EEPRO100State),
2657c663 1943#endif
151b2986
JQ
1944 /* Configuration bytes. */
1945 VMSTATE_BUFFER(configuration, EEPRO100State),
1946 VMSTATE_END_OF_LIST()
aac443e6 1947 }
151b2986 1948};
663e8e51 1949
e00e365e 1950static void nic_cleanup(VLANClientState *nc)
b946a153 1951{
e00e365e 1952 EEPRO100State *s = DO_UPCAST(NICState, nc, nc)->opaque;
b946a153 1953
e00e365e 1954 s->nic = NULL;
b946a153
AL
1955}
1956
c4c270e2 1957static int pci_nic_uninit(PCIDevice *pci_dev)
b946a153 1958{
c4c270e2 1959 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
b946a153
AL
1960
1961 cpu_unregister_io_memory(s->mmio_index);
151b2986 1962 vmstate_unregister(s->vmstate, s);
508ef936 1963 eeprom93xx_free(s->eeprom);
e00e365e 1964 qemu_del_vlan_client(&s->nic->nc);
b946a153
AL
1965 return 0;
1966}
1967
e00e365e
MM
1968static NetClientInfo net_eepro100_info = {
1969 .type = NET_CLIENT_TYPE_NIC,
1970 .size = sizeof(NICState),
1971 .can_receive = nic_can_receive,
1972 .receive = nic_receive,
1973 .cleanup = nic_cleanup,
1974};
1975
81a322d4 1976static int nic_init(PCIDevice *pci_dev, uint32_t device)
663e8e51 1977{
273a2142 1978 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51 1979
aac443e6 1980 TRACE(OTHER, logout("\n"));
663e8e51 1981
663e8e51 1982 s->device = device;
663e8e51
TS
1983
1984 pci_reset(s);
1985
1986 /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM,
1987 * i82559 and later support 64 or 256 word EEPROM. */
1988 s->eeprom = eeprom93xx_new(EEPROM_SIZE);
1989
1990 /* Handler for memory-mapped I/O */
273a2142 1991 s->mmio_index =
1eed09cb 1992 cpu_register_io_memory(pci_mmio_read, pci_mmio_write, s);
663e8e51 1993
273a2142 1994 pci_register_bar(&s->dev, 0, PCI_MEM_SIZE,
0392a017
IY
1995 PCI_BASE_ADDRESS_SPACE_MEMORY |
1996 PCI_BASE_ADDRESS_MEM_PREFETCH, pci_mmio_map);
1997 pci_register_bar(&s->dev, 1, PCI_IO_SIZE, PCI_BASE_ADDRESS_SPACE_IO,
663e8e51 1998 pci_map);
0392a017 1999 pci_register_bar(&s->dev, 2, PCI_FLASH_SIZE, PCI_BASE_ADDRESS_SPACE_MEMORY,
663e8e51
TS
2000 pci_mmio_map);
2001
508ef936 2002 qemu_macaddr_default_if_unset(&s->conf.macaddr);
ce0e58b3 2003 logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6));
663e8e51
TS
2004 assert(s->region[1] == 0);
2005
2006 nic_reset(s);
2007
e00e365e
MM
2008 s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
2009 pci_dev->qdev.info->name, pci_dev->qdev.id, s);
663e8e51 2010
e00e365e
MM
2011 qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
2012 TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
663e8e51 2013
a08d4367 2014 qemu_register_reset(nic_reset, s);
663e8e51 2015
151b2986
JQ
2016 s->vmstate = qemu_malloc(sizeof(vmstate_eepro100));
2017 memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100));
e00e365e 2018 s->vmstate->name = s->nic->nc.model;
151b2986 2019 vmstate_register(-1, s->vmstate, s);
4e9df06a 2020
81a322d4 2021 return 0;
663e8e51
TS
2022}
2023
c4c270e2
SW
2024static int pci_i82550_init(PCIDevice *pci_dev)
2025{
2026 return nic_init(pci_dev, i82550);
2027}
2028
2029static int pci_i82551_init(PCIDevice *pci_dev)
2030{
2031 return nic_init(pci_dev, i82551);
2032}
2033
2034static int pci_i82557a_init(PCIDevice *pci_dev)
2035{
2036 return nic_init(pci_dev, i82557A);
2037}
2038
2039static int pci_i82557b_init(PCIDevice *pci_dev)
2040{
2041 return nic_init(pci_dev, i82557B);
2042}
2043
2044static int pci_i82557c_init(PCIDevice *pci_dev)
2045{
2046 return nic_init(pci_dev, i82557C);
2047}
2048
2049static int pci_i82558a_init(PCIDevice *pci_dev)
2050{
2051 return nic_init(pci_dev, i82558A);
2052}
2053
2054static int pci_i82558b_init(PCIDevice *pci_dev)
2055{
2056 return nic_init(pci_dev, i82558B);
2057}
2058
2059static int pci_i82559a_init(PCIDevice *pci_dev)
2060{
2061 return nic_init(pci_dev, i82559A);
2062}
2063
2064static int pci_i82559b_init(PCIDevice *pci_dev)
2065{
2066 return nic_init(pci_dev, i82559B);
2067}
2068
2069static int pci_i82559c_init(PCIDevice *pci_dev)
9d07d757 2070{
c4c270e2 2071 return nic_init(pci_dev, i82559C);
9d07d757
PB
2072}
2073
c4c270e2 2074static int pci_i82559er_init(PCIDevice *pci_dev)
663e8e51 2075{
c4c270e2 2076 return nic_init(pci_dev, i82559ER);
663e8e51
TS
2077}
2078
c4c270e2 2079static int pci_i82562_init(PCIDevice *pci_dev)
663e8e51 2080{
c4c270e2 2081 return nic_init(pci_dev, i82562);
663e8e51
TS
2082}
2083
0aab0d3a
GH
2084static PCIDeviceInfo eepro100_info[] = {
2085 {
c4c270e2 2086 .qdev.name = "i82550",
762401e2 2087 .qdev.desc = "Intel i82550 Ethernet",
c4c270e2
SW
2088 .qdev.size = sizeof(EEPRO100State),
2089 .init = pci_i82550_init,
6a90e308 2090 .exit = pci_nic_uninit,
da51e79b 2091 .romfile = "gpxe-eepro100-80861209.rom",
508ef936
GH
2092 .qdev.props = (Property[]) {
2093 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2094 DEFINE_PROP_END_OF_LIST(),
2095 },
c4c270e2 2096 },{
0aab0d3a 2097 .qdev.name = "i82551",
762401e2 2098 .qdev.desc = "Intel i82551 Ethernet",
273a2142 2099 .qdev.size = sizeof(EEPRO100State),
0aab0d3a 2100 .init = pci_i82551_init,
e3936fa5 2101 .exit = pci_nic_uninit,
da51e79b 2102 .romfile = "gpxe-eepro100-80861209.rom",
508ef936
GH
2103 .qdev.props = (Property[]) {
2104 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2105 DEFINE_PROP_END_OF_LIST(),
2106 },
c4c270e2
SW
2107 },{
2108 .qdev.name = "i82557a",
762401e2 2109 .qdev.desc = "Intel i82557A Ethernet",
c4c270e2
SW
2110 .qdev.size = sizeof(EEPRO100State),
2111 .init = pci_i82557a_init,
6a90e308 2112 .exit = pci_nic_uninit,
da51e79b 2113 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2114 .qdev.props = (Property[]) {
2115 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2116 DEFINE_PROP_END_OF_LIST(),
2117 },
0aab0d3a
GH
2118 },{
2119 .qdev.name = "i82557b",
762401e2 2120 .qdev.desc = "Intel i82557B Ethernet",
273a2142 2121 .qdev.size = sizeof(EEPRO100State),
0aab0d3a 2122 .init = pci_i82557b_init,
e3936fa5 2123 .exit = pci_nic_uninit,
da51e79b 2124 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2125 .qdev.props = (Property[]) {
2126 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2127 DEFINE_PROP_END_OF_LIST(),
2128 },
c4c270e2
SW
2129 },{
2130 .qdev.name = "i82557c",
762401e2 2131 .qdev.desc = "Intel i82557C Ethernet",
c4c270e2
SW
2132 .qdev.size = sizeof(EEPRO100State),
2133 .init = pci_i82557c_init,
6a90e308 2134 .exit = pci_nic_uninit,
da51e79b 2135 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2136 .qdev.props = (Property[]) {
2137 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2138 DEFINE_PROP_END_OF_LIST(),
2139 },
c4c270e2
SW
2140 },{
2141 .qdev.name = "i82558a",
762401e2 2142 .qdev.desc = "Intel i82558A Ethernet",
c4c270e2
SW
2143 .qdev.size = sizeof(EEPRO100State),
2144 .init = pci_i82558a_init,
6a90e308 2145 .exit = pci_nic_uninit,
da51e79b 2146 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2147 .qdev.props = (Property[]) {
2148 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2149 DEFINE_PROP_END_OF_LIST(),
2150 },
c4c270e2
SW
2151 },{
2152 .qdev.name = "i82558b",
762401e2 2153 .qdev.desc = "Intel i82558B Ethernet",
c4c270e2
SW
2154 .qdev.size = sizeof(EEPRO100State),
2155 .init = pci_i82558b_init,
6a90e308 2156 .exit = pci_nic_uninit,
da51e79b 2157 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2158 .qdev.props = (Property[]) {
2159 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2160 DEFINE_PROP_END_OF_LIST(),
2161 },
c4c270e2
SW
2162 },{
2163 .qdev.name = "i82559a",
762401e2 2164 .qdev.desc = "Intel i82559A Ethernet",
c4c270e2
SW
2165 .qdev.size = sizeof(EEPRO100State),
2166 .init = pci_i82559a_init,
6a90e308 2167 .exit = pci_nic_uninit,
da51e79b 2168 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2169 .qdev.props = (Property[]) {
2170 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2171 DEFINE_PROP_END_OF_LIST(),
2172 },
c4c270e2
SW
2173 },{
2174 .qdev.name = "i82559b",
762401e2 2175 .qdev.desc = "Intel i82559B Ethernet",
c4c270e2
SW
2176 .qdev.size = sizeof(EEPRO100State),
2177 .init = pci_i82559b_init,
6a90e308 2178 .exit = pci_nic_uninit,
da51e79b 2179 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2180 .qdev.props = (Property[]) {
2181 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2182 DEFINE_PROP_END_OF_LIST(),
2183 },
c4c270e2
SW
2184 },{
2185 .qdev.name = "i82559c",
762401e2 2186 .qdev.desc = "Intel i82559C Ethernet",
c4c270e2
SW
2187 .qdev.size = sizeof(EEPRO100State),
2188 .init = pci_i82559c_init,
6a90e308 2189 .exit = pci_nic_uninit,
da51e79b 2190 .romfile = "gpxe-eepro100-80861229.rom",
508ef936
GH
2191 .qdev.props = (Property[]) {
2192 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2193 DEFINE_PROP_END_OF_LIST(),
2194 },
0aab0d3a
GH
2195 },{
2196 .qdev.name = "i82559er",
762401e2 2197 .qdev.desc = "Intel i82559ER Ethernet",
273a2142 2198 .qdev.size = sizeof(EEPRO100State),
0aab0d3a 2199 .init = pci_i82559er_init,
e3936fa5 2200 .exit = pci_nic_uninit,
da51e79b 2201 .romfile = "gpxe-eepro100-80861209.rom",
508ef936
GH
2202 .qdev.props = (Property[]) {
2203 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2204 DEFINE_PROP_END_OF_LIST(),
2205 },
c4c270e2
SW
2206 },{
2207 .qdev.name = "i82562",
762401e2 2208 .qdev.desc = "Intel i82562 Ethernet",
c4c270e2
SW
2209 .qdev.size = sizeof(EEPRO100State),
2210 .init = pci_i82562_init,
6a90e308 2211 .exit = pci_nic_uninit,
da51e79b 2212 .romfile = "gpxe-eepro100-80861209.rom",
508ef936
GH
2213 .qdev.props = (Property[]) {
2214 DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
2215 DEFINE_PROP_END_OF_LIST(),
2216 },
0aab0d3a
GH
2217 },{
2218 /* end of list */
2219 }
2220};
2221
9d07d757 2222static void eepro100_register_devices(void)
663e8e51 2223{
0aab0d3a 2224 pci_qdev_register_many(eepro100_info);
663e8e51
TS
2225}
2226
9d07d757 2227device_init(eepro100_register_devices)