]> Git Repo - qemu.git/blame - hw/eepro100.c
mv from strdup to qemu_strdup in qemu-option.c
[qemu.git] / hw / eepro100.c
CommitLineData
663e8e51
TS
1/*
2 * QEMU i8255x (PRO100) emulation
3 *
4 * Copyright (c) 2006-2007 Stefan Weil
5 *
6 * Portions of the code are copies from grub / etherboot eepro100.c
7 * and linux e100.c.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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
8167ee88 20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
663e8e51
TS
21 *
22 * Tested features (i82559):
23 * PXE boot (i386) no valid link
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
34 */
35
36#if defined(TARGET_I386)
37# warning "PXE boot still not working!"
38#endif
39
663e8e51 40#include <stddef.h> /* offsetof */
b84a5c6f 41#include <stdbool.h>
87ecb68b
PB
42#include "hw.h"
43#include "pci.h"
44#include "net.h"
663e8e51
TS
45#include "eeprom93xx.h"
46
47/* Common declarations for all PCI devices. */
48
663e8e51
TS
49#define PCI_CONFIG_8(offset, value) \
50 (pci_conf[offset] = (value))
51#define PCI_CONFIG_16(offset, value) \
52 (*(uint16_t *)&pci_conf[offset] = cpu_to_le16(value))
53#define PCI_CONFIG_32(offset, value) \
54 (*(uint32_t *)&pci_conf[offset] = cpu_to_le32(value))
55
56#define KiB 1024
57
58/* debug EEPRO100 card */
59//~ #define DEBUG_EEPRO100
60
61#ifdef DEBUG_EEPRO100
001faf32 62#define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
663e8e51 63#else
001faf32 64#define logout(fmt, ...) ((void)0)
663e8e51
TS
65#endif
66
67/* Set flags to 0 to disable debug output. */
68#define MDI 0
69
70#define TRACE(flag, command) ((flag) ? (command) : (void)0)
71
72#define missing(text) assert(!"feature is missing in this emulation: " text)
73
74#define MAX_ETH_FRAME_SIZE 1514
75
76/* This driver supports several different devices which are declared here. */
77#define i82551 0x82551
78#define i82557B 0x82557b
79#define i82557C 0x82557c
80#define i82558B 0x82558b
81#define i82559C 0x82559c
82#define i82559ER 0x82559e
83#define i82562 0x82562
84
85#define EEPROM_SIZE 64
86
87#define PCI_MEM_SIZE (4 * KiB)
88#define PCI_IO_SIZE 64
89#define PCI_FLASH_SIZE (128 * KiB)
90
91#define BIT(n) (1 << (n))
92#define BITS(n, m) (((0xffffffffU << (31 - n)) >> (31 - n + m)) << m)
93
94/* The SCB accepts the following controls for the Tx and Rx units: */
95#define CU_NOP 0x0000 /* No operation. */
96#define CU_START 0x0010 /* CU start. */
97#define CU_RESUME 0x0020 /* CU resume. */
98#define CU_STATSADDR 0x0040 /* Load dump counters address. */
99#define CU_SHOWSTATS 0x0050 /* Dump statistical counters. */
100#define CU_CMD_BASE 0x0060 /* Load CU base address. */
101#define CU_DUMPSTATS 0x0070 /* Dump and reset statistical counters. */
102#define CU_SRESUME 0x00a0 /* CU static resume. */
103
104#define RU_NOP 0x0000
105#define RX_START 0x0001
106#define RX_RESUME 0x0002
107#define RX_ABORT 0x0004
108#define RX_ADDR_LOAD 0x0006
109#define RX_RESUMENR 0x0007
110#define INT_MASK 0x0100
111#define DRVR_INT 0x0200 /* Driver generated interrupt. */
112
663e8e51
TS
113/* Offsets to the various registers.
114 All accesses need not be longword aligned. */
115enum speedo_offsets {
116 SCBStatus = 0,
117 SCBAck = 1,
118 SCBCmd = 2, /* Rx/Command Unit command and status. */
119 SCBIntmask = 3,
120 SCBPointer = 4, /* General purpose pointer. */
121 SCBPort = 8, /* Misc. commands and operands. */
122 SCBflash = 12, SCBeeprom = 14, /* EEPROM and flash memory control. */
123 SCBCtrlMDI = 16, /* MDI interface control. */
124 SCBEarlyRx = 20, /* Early receive byte count. */
3257d2b6 125 SCBFlow = 24,
663e8e51
TS
126};
127
128/* A speedo3 transmit buffer descriptor with two buffers... */
129typedef struct {
130 uint16_t status;
131 uint16_t command;
132 uint32_t link; /* void * */
133 uint32_t tx_desc_addr; /* transmit buffer decsriptor array address. */
134 uint16_t tcb_bytes; /* transmit command block byte count (in lower 14 bits */
135 uint8_t tx_threshold; /* transmit threshold */
136 uint8_t tbd_count; /* TBD number */
137 //~ /* This constitutes two "TBD" entries: hdr and data */
138 //~ uint32_t tx_buf_addr0; /* void *, header of frame to be transmitted. */
139 //~ int32_t tx_buf_size0; /* Length of Tx hdr. */
140 //~ uint32_t tx_buf_addr1; /* void *, data to be transmitted. */
141 //~ int32_t tx_buf_size1; /* Length of Tx data. */
142} eepro100_tx_t;
143
144/* Receive frame descriptor. */
145typedef struct {
146 int16_t status;
147 uint16_t command;
148 uint32_t link; /* struct RxFD * */
149 uint32_t rx_buf_addr; /* void * */
150 uint16_t count;
151 uint16_t size;
152 char packet[MAX_ETH_FRAME_SIZE + 4];
153} eepro100_rx_t;
154
155typedef struct {
156 uint32_t tx_good_frames, tx_max_collisions, tx_late_collisions,
157 tx_underruns, tx_lost_crs, tx_deferred, tx_single_collisions,
158 tx_multiple_collisions, tx_total_collisions;
159 uint32_t rx_good_frames, rx_crc_errors, rx_alignment_errors,
160 rx_resource_errors, rx_overrun_errors, rx_cdt_errors,
161 rx_short_frame_errors;
162 uint32_t fc_xmt_pause, fc_rcv_pause, fc_rcv_unsupported;
163 uint16_t xmt_tco_frames, rcv_tco_frames;
164 uint32_t complete;
165} eepro100_stats_t;
166
167typedef enum {
168 cu_idle = 0,
169 cu_suspended = 1,
170 cu_active = 2,
171 cu_lpq_active = 2,
172 cu_hqp_active = 3
173} cu_state_t;
174
175typedef enum {
176 ru_idle = 0,
177 ru_suspended = 1,
178 ru_no_resources = 2,
179 ru_ready = 4
180} ru_state_t;
181
663e8e51 182typedef struct {
273a2142 183 PCIDevice dev;
663e8e51
TS
184#if 1
185 uint8_t cmd;
186 uint32_t start;
187 uint32_t stop;
188 uint8_t boundary;
189 uint8_t tsr;
190 uint8_t tpsr;
191 uint16_t tcnt;
192 uint16_t rcnt;
193 uint32_t rsar;
194 uint8_t rsr;
195 uint8_t rxcr;
196 uint8_t isr;
197 uint8_t dcfg;
198 uint8_t imr;
199 uint8_t phys[6]; /* mac address */
200 uint8_t curpag;
201 uint8_t mult[8]; /* multicast mask array */
202 int mmio_index;
663e8e51
TS
203 VLANClientState *vc;
204#endif
205 uint8_t scb_stat; /* SCB stat/ack byte */
206 uint8_t int_stat; /* PCI interrupt status */
207 uint32_t region[3]; /* PCI region addresses */
208 uint8_t macaddr[6];
209 uint32_t statcounter[19];
210 uint16_t mdimem[32];
211 eeprom_t *eeprom;
212 uint32_t device; /* device variant */
213 uint32_t pointer;
214 /* (cu_base + cu_offset) address the next command block in the command block list. */
215 uint32_t cu_base; /* CU base address */
216 uint32_t cu_offset; /* CU address offset */
217 /* (ru_base + ru_offset) address the RFD in the Receive Frame Area. */
218 uint32_t ru_base; /* RU base address */
219 uint32_t ru_offset; /* RU address offset */
220 uint32_t statsaddr; /* pointer to eepro100_stats_t */
221 eepro100_stats_t statistics; /* statistical counters */
222#if 0
223 uint16_t status;
224#endif
225
226 /* Configuration bytes. */
227 uint8_t configuration[22];
228
229 /* Data in mem is always in the byte order of the controller (le). */
230 uint8_t mem[PCI_MEM_SIZE];
231} EEPRO100State;
232
233/* Default values for MDI (PHY) registers */
234static const uint16_t eepro100_mdi_default[] = {
235 /* MDI Registers 0 - 6, 7 */
236 0x3000, 0x780d, 0x02a8, 0x0154, 0x05e1, 0x0000, 0x0000, 0x0000,
237 /* MDI Registers 8 - 15 */
238 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
239 /* MDI Registers 16 - 31 */
240 0x0003, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
241 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
242};
243
244/* Readonly mask for MDI (PHY) registers */
245static const uint16_t eepro100_mdi_mask[] = {
246 0x0000, 0xffff, 0xffff, 0xffff, 0xc01f, 0xffff, 0xffff, 0x0000,
247 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
248 0x0fff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
249 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
250};
251
252#define POLYNOMIAL 0x04c11db6
253
254/* From FreeBSD */
255/* XXX: optimize */
256static int compute_mcast_idx(const uint8_t * ep)
257{
258 uint32_t crc;
259 int carry, i, j;
260 uint8_t b;
261
262 crc = 0xffffffff;
263 for (i = 0; i < 6; i++) {
264 b = *ep++;
265 for (j = 0; j < 8; j++) {
266 carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
267 crc <<= 1;
268 b >>= 1;
269 if (carry)
270 crc = ((crc ^ POLYNOMIAL) | carry);
271 }
272 }
273 return (crc >> 26);
274}
275
276#if defined(DEBUG_EEPRO100)
277static const char *nic_dump(const uint8_t * buf, unsigned size)
278{
279 static char dump[3 * 16 + 1];
280 char *p = &dump[0];
281 if (size > 16)
282 size = 16;
283 while (size-- > 0) {
284 p += sprintf(p, " %02x", *buf++);
285 }
286 return dump;
287}
288#endif /* DEBUG_EEPRO100 */
289
290enum scb_stat_ack {
291 stat_ack_not_ours = 0x00,
292 stat_ack_sw_gen = 0x04,
293 stat_ack_rnr = 0x10,
294 stat_ack_cu_idle = 0x20,
295 stat_ack_frame_rx = 0x40,
296 stat_ack_cu_cmd_done = 0x80,
297 stat_ack_not_present = 0xFF,
298 stat_ack_rx = (stat_ack_sw_gen | stat_ack_rnr | stat_ack_frame_rx),
299 stat_ack_tx = (stat_ack_cu_idle | stat_ack_cu_cmd_done),
300};
301
302static void disable_interrupt(EEPRO100State * s)
303{
304 if (s->int_stat) {
305 logout("interrupt disabled\n");
273a2142 306 qemu_irq_lower(s->dev.irq[0]);
663e8e51
TS
307 s->int_stat = 0;
308 }
309}
310
311static void enable_interrupt(EEPRO100State * s)
312{
313 if (!s->int_stat) {
314 logout("interrupt enabled\n");
273a2142 315 qemu_irq_raise(s->dev.irq[0]);
663e8e51
TS
316 s->int_stat = 1;
317 }
318}
319
320static void eepro100_acknowledge(EEPRO100State * s)
321{
322 s->scb_stat &= ~s->mem[SCBAck];
323 s->mem[SCBAck] = s->scb_stat;
324 if (s->scb_stat == 0) {
325 disable_interrupt(s);
326 }
327}
328
329static void eepro100_interrupt(EEPRO100State * s, uint8_t stat)
330{
331 uint8_t mask = ~s->mem[SCBIntmask];
332 s->mem[SCBAck] |= stat;
333 stat = s->scb_stat = s->mem[SCBAck];
334 stat &= (mask | 0x0f);
335 //~ stat &= (~s->mem[SCBIntmask] | 0x0xf);
336 if (stat && (mask & 0x01)) {
337 /* SCB mask and SCB Bit M do not disable interrupt. */
338 enable_interrupt(s);
339 } else if (s->int_stat) {
340 disable_interrupt(s);
341 }
342}
343
344static void eepro100_cx_interrupt(EEPRO100State * s)
345{
346 /* CU completed action command. */
347 /* Transmit not ok (82557 only, not in emulation). */
348 eepro100_interrupt(s, 0x80);
349}
350
351static void eepro100_cna_interrupt(EEPRO100State * s)
352{
353 /* CU left the active state. */
354 eepro100_interrupt(s, 0x20);
355}
356
357static void eepro100_fr_interrupt(EEPRO100State * s)
358{
359 /* RU received a complete frame. */
360 eepro100_interrupt(s, 0x40);
361}
362
363#if 0
364static void eepro100_rnr_interrupt(EEPRO100State * s)
365{
366 /* RU is not ready. */
367 eepro100_interrupt(s, 0x10);
368}
369#endif
370
371static void eepro100_mdi_interrupt(EEPRO100State * s)
372{
373 /* MDI completed read or write cycle. */
374 eepro100_interrupt(s, 0x08);
375}
376
377static void eepro100_swi_interrupt(EEPRO100State * s)
378{
379 /* Software has requested an interrupt. */
380 eepro100_interrupt(s, 0x04);
381}
382
383#if 0
384static void eepro100_fcp_interrupt(EEPRO100State * s)
385{
386 /* Flow control pause interrupt (82558 and later). */
387 eepro100_interrupt(s, 0x01);
388}
389#endif
390
391static void pci_reset(EEPRO100State * s)
392{
393 uint32_t device = s->device;
273a2142 394 uint8_t *pci_conf = s->dev.config;
663e8e51
TS
395
396 logout("%p\n", s);
397
398 /* PCI Vendor ID */
deb54399 399 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
d6fd1e66 400 /* PCI Device ID depends on device and is set below. */
663e8e51
TS
401 /* PCI Command */
402 PCI_CONFIG_16(PCI_COMMAND, 0x0000);
403 /* PCI Status */
404 PCI_CONFIG_16(PCI_STATUS, 0x2800);
405 /* PCI Revision ID */
406 PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
407 /* PCI Class Code */
408 PCI_CONFIG_8(0x09, 0x00);
173a543b 409 pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
663e8e51
TS
410 /* PCI Cache Line Size */
411 /* check cache line size!!! */
412 //~ PCI_CONFIG_8(0x0c, 0x00);
413 /* PCI Latency Timer */
414 PCI_CONFIG_8(0x0d, 0x20); // latency timer = 32 clocks
415 /* PCI Header Type */
416 /* BIST (built-in self test) */
417#if defined(TARGET_I386)
418// !!! workaround for buggy bios
419//~ #define PCI_ADDRESS_SPACE_MEM_PREFETCH 0
420#endif
421#if 0
422 /* PCI Base Address Registers */
423 /* CSR Memory Mapped Base Address */
424 PCI_CONFIG_32(PCI_BASE_ADDRESS_0,
425 PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_MEM_PREFETCH);
426 /* CSR I/O Mapped Base Address */
427 PCI_CONFIG_32(PCI_BASE_ADDRESS_1, PCI_ADDRESS_SPACE_IO);
428#if 0
429 /* Flash Memory Mapped Base Address */
430 PCI_CONFIG_32(PCI_BASE_ADDRESS_2, 0xfffe0000 | PCI_ADDRESS_SPACE_MEM);
431#endif
432#endif
433 /* Expansion ROM Base Address (depends on boot disable!!!) */
434 PCI_CONFIG_32(0x30, 0x00000000);
435 /* Capability Pointer */
436 PCI_CONFIG_8(0x34, 0xdc);
437 /* Interrupt Pin */
438 PCI_CONFIG_8(0x3d, 1); // interrupt pin 0
439 /* Minimum Grant */
440 PCI_CONFIG_8(0x3e, 0x08);
441 /* Maximum Latency */
442 PCI_CONFIG_8(0x3f, 0x18);
443 /* Power Management Capabilities / Next Item Pointer / Capability ID */
444 PCI_CONFIG_32(0xdc, 0x7e210001);
445
446 switch (device) {
447 case i82551:
d6fd1e66 448 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
663e8e51
TS
449 PCI_CONFIG_8(PCI_REVISION_ID, 0x0f);
450 break;
451 case i82557B:
d6fd1e66 452 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51
TS
453 PCI_CONFIG_8(PCI_REVISION_ID, 0x02);
454 break;
455 case i82557C:
d6fd1e66 456 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51
TS
457 PCI_CONFIG_8(PCI_REVISION_ID, 0x03);
458 break;
459 case i82558B:
d6fd1e66 460 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51
TS
461 PCI_CONFIG_16(PCI_STATUS, 0x2810);
462 PCI_CONFIG_8(PCI_REVISION_ID, 0x05);
463 break;
464 case i82559C:
d6fd1e66 465 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82557);
663e8e51
TS
466 PCI_CONFIG_16(PCI_STATUS, 0x2810);
467 //~ PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
468 break;
469 case i82559ER:
d6fd1e66 470 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
663e8e51
TS
471 PCI_CONFIG_16(PCI_STATUS, 0x2810);
472 PCI_CONFIG_8(PCI_REVISION_ID, 0x09);
473 break;
474 //~ PCI_CONFIG_16(PCI_DEVICE_ID, 0x1029);
475 //~ PCI_CONFIG_16(PCI_DEVICE_ID, 0x1030); /* 82559 InBusiness 10/100 */
476 default:
477 logout("Device %X is undefined!\n", device);
478 }
479
480 if (device == i82557C || device == i82558B || device == i82559C) {
481 logout("Get device id and revision from EEPROM!!!\n");
482 }
483}
484
485static void nic_selective_reset(EEPRO100State * s)
486{
487 size_t i;
488 uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
489 //~ eeprom93xx_reset(s->eeprom);
490 memcpy(eeprom_contents, s->macaddr, 6);
491 eeprom_contents[0xa] = 0x4000;
492 uint16_t sum = 0;
493 for (i = 0; i < EEPROM_SIZE - 1; i++) {
494 sum += eeprom_contents[i];
495 }
496 eeprom_contents[EEPROM_SIZE - 1] = 0xbaba - sum;
497
498 memset(s->mem, 0, sizeof(s->mem));
499 uint32_t val = BIT(21);
500 memcpy(&s->mem[SCBCtrlMDI], &val, sizeof(val));
501
502 assert(sizeof(s->mdimem) == sizeof(eepro100_mdi_default));
503 memcpy(&s->mdimem[0], &eepro100_mdi_default[0], sizeof(s->mdimem));
504}
505
506static void nic_reset(void *opaque)
507{
769cf7a5 508 EEPRO100State *s = opaque;
663e8e51
TS
509 logout("%p\n", s);
510 static int first;
511 if (!first) {
512 first = 1;
513 }
514 nic_selective_reset(s);
515}
516
517#if defined(DEBUG_EEPRO100)
518static const char *reg[PCI_IO_SIZE / 4] = {
519 "Command/Status",
520 "General Pointer",
521 "Port",
522 "EEPROM/Flash Control",
523 "MDI Control",
524 "Receive DMA Byte Count",
525 "Flow control register",
526 "General Status/Control"
527};
528
529static char *regname(uint32_t addr)
530{
531 static char buf[16];
532 if (addr < PCI_IO_SIZE) {
533 const char *r = reg[addr / 4];
534 if (r != 0) {
535 sprintf(buf, "%s+%u", r, addr % 4);
536 } else {
537 sprintf(buf, "0x%02x", addr);
538 }
539 } else {
540 sprintf(buf, "??? 0x%08x", addr);
541 }
542 return buf;
543}
544#endif /* DEBUG_EEPRO100 */
545
546#if 0
547static uint16_t eepro100_read_status(EEPRO100State * s)
548{
549 uint16_t val = s->status;
550 logout("val=0x%04x\n", val);
551 return val;
552}
553
554static void eepro100_write_status(EEPRO100State * s, uint16_t val)
555{
556 logout("val=0x%04x\n", val);
557 s->status = val;
558}
559#endif
560
561/*****************************************************************************
562 *
563 * Command emulation.
564 *
565 ****************************************************************************/
566
567#if 0
568static uint16_t eepro100_read_command(EEPRO100State * s)
569{
570 uint16_t val = 0xffff;
571 //~ logout("val=0x%04x\n", val);
572 return val;
573}
574#endif
575
576/* Commands that can be put in a command list entry. */
577enum commands {
578 CmdNOp = 0,
579 CmdIASetup = 1,
580 CmdConfigure = 2,
581 CmdMulticastList = 3,
582 CmdTx = 4,
583 CmdTDR = 5, /* load microcode */
584 CmdDump = 6,
585 CmdDiagnose = 7,
586
587 /* And some extra flags: */
588 CmdSuspend = 0x4000, /* Suspend after completion. */
589 CmdIntr = 0x2000, /* Interrupt after completion. */
590 CmdTxFlex = 0x0008, /* Use "Flexible mode" for CmdTx command. */
591};
592
593static cu_state_t get_cu_state(EEPRO100State * s)
594{
595 return ((s->mem[SCBStatus] >> 6) & 0x03);
596}
597
598static void set_cu_state(EEPRO100State * s, cu_state_t state)
599{
600 s->mem[SCBStatus] = (s->mem[SCBStatus] & 0x3f) + (state << 6);
601}
602
603static ru_state_t get_ru_state(EEPRO100State * s)
604{
605 return ((s->mem[SCBStatus] >> 2) & 0x0f);
606}
607
608static void set_ru_state(EEPRO100State * s, ru_state_t state)
609{
610 s->mem[SCBStatus] = (s->mem[SCBStatus] & 0xc3) + (state << 2);
611}
612
613static void dump_statistics(EEPRO100State * s)
614{
615 /* Dump statistical data. Most data is never changed by the emulation
616 * and always 0, so we first just copy the whole block and then those
617 * values which really matter.
618 * Number of data should check configuration!!!
619 */
620 cpu_physical_memory_write(s->statsaddr, (uint8_t *) & s->statistics, 64);
621 stl_phys(s->statsaddr + 0, s->statistics.tx_good_frames);
622 stl_phys(s->statsaddr + 36, s->statistics.rx_good_frames);
623 stl_phys(s->statsaddr + 48, s->statistics.rx_resource_errors);
624 stl_phys(s->statsaddr + 60, s->statistics.rx_short_frame_errors);
625 //~ stw_phys(s->statsaddr + 76, s->statistics.xmt_tco_frames);
626 //~ stw_phys(s->statsaddr + 78, s->statistics.rcv_tco_frames);
627 //~ missing("CU dump statistical counters");
628}
629
630static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
631{
632 eepro100_tx_t tx;
633 uint32_t cb_address;
634 switch (val) {
635 case CU_NOP:
636 /* No operation. */
637 break;
638 case CU_START:
639 if (get_cu_state(s) != cu_idle) {
640 /* Intel documentation says that CU must be idle for the CU
641 * start command. Intel driver for Linux also starts the CU
642 * from suspended state. */
643 logout("CU state is %u, should be %u\n", get_cu_state(s), cu_idle);
644 //~ assert(!"wrong CU state");
645 }
646 set_cu_state(s, cu_active);
647 s->cu_offset = s->pointer;
648 next_command:
649 cb_address = s->cu_base + s->cu_offset;
650 cpu_physical_memory_read(cb_address, (uint8_t *) & tx, sizeof(tx));
651 uint16_t status = le16_to_cpu(tx.status);
652 uint16_t command = le16_to_cpu(tx.command);
653 logout
654 ("val=0x%02x (cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
655 val, status, command, tx.link);
656 bool bit_el = ((command & 0x8000) != 0);
657 bool bit_s = ((command & 0x4000) != 0);
658 bool bit_i = ((command & 0x2000) != 0);
659 bool bit_nc = ((command & 0x0010) != 0);
660 //~ bool bit_sf = ((command & 0x0008) != 0);
661 uint16_t cmd = command & 0x0007;
662 s->cu_offset = le32_to_cpu(tx.link);
663 switch (cmd) {
664 case CmdNOp:
665 /* Do nothing. */
666 break;
667 case CmdIASetup:
668 cpu_physical_memory_read(cb_address + 8, &s->macaddr[0], 6);
669 logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
670 break;
671 case CmdConfigure:
672 cpu_physical_memory_read(cb_address + 8, &s->configuration[0],
673 sizeof(s->configuration));
674 logout("configuration: %s\n", nic_dump(&s->configuration[0], 16));
675 break;
676 case CmdMulticastList:
677 //~ missing("multicast list");
678 break;
679 case CmdTx:
680 (void)0;
681 uint32_t tbd_array = le32_to_cpu(tx.tx_desc_addr);
682 uint16_t tcb_bytes = (le16_to_cpu(tx.tcb_bytes) & 0x3fff);
683 logout
684 ("transmit, TBD array address 0x%08x, TCB byte count 0x%04x, TBD count %u\n",
685 tbd_array, tcb_bytes, tx.tbd_count);
686 assert(!bit_nc);
687 //~ assert(!bit_sf);
688 assert(tcb_bytes <= 2600);
689 /* Next assertion fails for local configuration. */
690 //~ assert((tcb_bytes > 0) || (tbd_array != 0xffffffff));
691 if (!((tcb_bytes > 0) || (tbd_array != 0xffffffff))) {
692 logout
693 ("illegal values of TBD array address and TCB byte count!\n");
694 }
24e6f355
RD
695 // sends larger than MAX_ETH_FRAME_SIZE are allowed, up to 2600 bytes
696 uint8_t buf[2600];
663e8e51
TS
697 uint16_t size = 0;
698 uint32_t tbd_address = cb_address + 0x10;
699 assert(tcb_bytes <= sizeof(buf));
700 while (size < tcb_bytes) {
701 uint32_t tx_buffer_address = ldl_phys(tbd_address);
702 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
703 //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
704 tbd_address += 8;
705 logout
706 ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
707 tx_buffer_address, tx_buffer_size);
24e6f355 708 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
663e8e51
TS
709 cpu_physical_memory_read(tx_buffer_address, &buf[size],
710 tx_buffer_size);
711 size += tx_buffer_size;
712 }
713 if (tbd_array == 0xffffffff) {
714 /* Simplified mode. Was already handled by code above. */
715 } else {
716 /* Flexible mode. */
717 uint8_t tbd_count = 0;
3f9cb1c1
NS
718 if ((s->device >= i82558B) && !(s->configuration[6] & BIT(4))) {
719 /* Extended Flexible TCB. */
663e8e51
TS
720 assert(tcb_bytes == 0);
721 for (; tbd_count < 2; tbd_count++) {
722 uint32_t tx_buffer_address = ldl_phys(tbd_address);
723 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
724 uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
725 tbd_address += 8;
726 logout
3f9cb1c1 727 ("TBD (extended flexible mode): buffer address 0x%08x, size 0x%04x\n",
663e8e51 728 tx_buffer_address, tx_buffer_size);
24e6f355 729 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
663e8e51
TS
730 cpu_physical_memory_read(tx_buffer_address, &buf[size],
731 tx_buffer_size);
732 size += tx_buffer_size;
733 if (tx_buffer_el & 1) {
734 break;
735 }
736 }
737 }
738 tbd_address = tbd_array;
739 for (; tbd_count < tx.tbd_count; tbd_count++) {
740 uint32_t tx_buffer_address = ldl_phys(tbd_address);
741 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
742 uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
743 tbd_address += 8;
744 logout
745 ("TBD (flexible mode): buffer address 0x%08x, size 0x%04x\n",
746 tx_buffer_address, tx_buffer_size);
24e6f355 747 tx_buffer_size = MIN(tx_buffer_size, sizeof(buf) - size);
663e8e51
TS
748 cpu_physical_memory_read(tx_buffer_address, &buf[size],
749 tx_buffer_size);
750 size += tx_buffer_size;
751 if (tx_buffer_el & 1) {
752 break;
753 }
754 }
755 }
756 qemu_send_packet(s->vc, buf, size);
757 s->statistics.tx_good_frames++;
758 /* Transmit with bad status would raise an CX/TNO interrupt.
759 * (82557 only). Emulation never has bad status. */
760 //~ eepro100_cx_interrupt(s);
761 break;
762 case CmdTDR:
763 logout("load microcode\n");
764 /* Starting with offset 8, the command contains
765 * 64 dwords microcode which we just ignore here. */
766 break;
767 default:
768 missing("undefined command");
769 }
770 /* Write new status (success). */
771 stw_phys(cb_address, status | 0x8000 | 0x2000);
772 if (bit_i) {
773 /* CU completed action. */
774 eepro100_cx_interrupt(s);
775 }
776 if (bit_el) {
777 /* CU becomes idle. */
778 set_cu_state(s, cu_idle);
779 eepro100_cna_interrupt(s);
780 } else if (bit_s) {
781 /* CU becomes suspended. */
782 set_cu_state(s, cu_suspended);
783 eepro100_cna_interrupt(s);
784 } else {
785 /* More entries in list. */
786 logout("CU list with at least one more entry\n");
787 goto next_command;
788 }
789 logout("CU list empty\n");
790 /* List is empty. Now CU is idle or suspended. */
791 break;
792 case CU_RESUME:
793 if (get_cu_state(s) != cu_suspended) {
794 logout("bad CU resume from CU state %u\n", get_cu_state(s));
795 /* Workaround for bad Linux eepro100 driver which resumes
796 * from idle state. */
797 //~ missing("cu resume");
798 set_cu_state(s, cu_suspended);
799 }
800 if (get_cu_state(s) == cu_suspended) {
801 logout("CU resuming\n");
802 set_cu_state(s, cu_active);
803 goto next_command;
804 }
805 break;
806 case CU_STATSADDR:
807 /* Load dump counters address. */
808 s->statsaddr = s->pointer;
809 logout("val=0x%02x (status address)\n", val);
810 break;
811 case CU_SHOWSTATS:
812 /* Dump statistical counters. */
813 dump_statistics(s);
814 break;
815 case CU_CMD_BASE:
816 /* Load CU base. */
817 logout("val=0x%02x (CU base address)\n", val);
818 s->cu_base = s->pointer;
819 break;
820 case CU_DUMPSTATS:
821 /* Dump and reset statistical counters. */
822 dump_statistics(s);
823 memset(&s->statistics, 0, sizeof(s->statistics));
824 break;
825 case CU_SRESUME:
826 /* CU static resume. */
827 missing("CU static resume");
828 break;
829 default:
830 missing("Undefined CU command");
831 }
832}
833
834static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
835{
836 switch (val) {
837 case RU_NOP:
838 /* No operation. */
839 break;
840 case RX_START:
841 /* RU start. */
842 if (get_ru_state(s) != ru_idle) {
843 logout("RU state is %u, should be %u\n", get_ru_state(s), ru_idle);
844 //~ assert(!"wrong RU state");
845 }
846 set_ru_state(s, ru_ready);
847 s->ru_offset = s->pointer;
848 logout("val=0x%02x (rx start)\n", val);
849 break;
850 case RX_RESUME:
851 /* Restart RU. */
852 if (get_ru_state(s) != ru_suspended) {
853 logout("RU state is %u, should be %u\n", get_ru_state(s),
854 ru_suspended);
855 //~ assert(!"wrong RU state");
856 }
857 set_ru_state(s, ru_ready);
858 break;
859 case RX_ADDR_LOAD:
860 /* Load RU base. */
861 logout("val=0x%02x (RU base address)\n", val);
862 s->ru_base = s->pointer;
863 break;
864 default:
865 logout("val=0x%02x (undefined RU command)\n", val);
866 missing("Undefined SU command");
867 }
868}
869
870static void eepro100_write_command(EEPRO100State * s, uint8_t val)
871{
872 eepro100_ru_command(s, val & 0x0f);
873 eepro100_cu_command(s, val & 0xf0);
874 if ((val) == 0) {
875 logout("val=0x%02x\n", val);
876 }
877 /* Clear command byte after command was accepted. */
878 s->mem[SCBCmd] = 0;
879}
880
881/*****************************************************************************
882 *
883 * EEPROM emulation.
884 *
885 ****************************************************************************/
886
887#define EEPROM_CS 0x02
888#define EEPROM_SK 0x01
889#define EEPROM_DI 0x04
890#define EEPROM_DO 0x08
891
892static uint16_t eepro100_read_eeprom(EEPRO100State * s)
893{
894 uint16_t val;
895 memcpy(&val, &s->mem[SCBeeprom], sizeof(val));
896 if (eeprom93xx_read(s->eeprom)) {
897 val |= EEPROM_DO;
898 } else {
899 val &= ~EEPROM_DO;
900 }
901 return val;
902}
903
904static void eepro100_write_eeprom(eeprom_t * eeprom, uint8_t val)
905{
906 logout("write val=0x%02x\n", val);
907
908 /* mask unwriteable bits */
909 //~ val = SET_MASKED(val, 0x31, eeprom->value);
910
911 int eecs = ((val & EEPROM_CS) != 0);
912 int eesk = ((val & EEPROM_SK) != 0);
913 int eedi = ((val & EEPROM_DI) != 0);
914 eeprom93xx_write(eeprom, eecs, eesk, eedi);
915}
916
917static void eepro100_write_pointer(EEPRO100State * s, uint32_t val)
918{
919 s->pointer = le32_to_cpu(val);
920 logout("val=0x%08x\n", val);
921}
922
923/*****************************************************************************
924 *
925 * MDI emulation.
926 *
927 ****************************************************************************/
928
929#if defined(DEBUG_EEPRO100)
930static const char *mdi_op_name[] = {
931 "opcode 0",
932 "write",
933 "read",
934 "opcode 3"
935};
936
937static const char *mdi_reg_name[] = {
938 "Control",
939 "Status",
940 "PHY Identification (Word 1)",
941 "PHY Identification (Word 2)",
942 "Auto-Negotiation Advertisement",
943 "Auto-Negotiation Link Partner Ability",
944 "Auto-Negotiation Expansion"
945};
946#endif /* DEBUG_EEPRO100 */
947
948static uint32_t eepro100_read_mdi(EEPRO100State * s)
949{
950 uint32_t val;
951 memcpy(&val, &s->mem[0x10], sizeof(val));
952
953#ifdef DEBUG_EEPRO100
954 uint8_t raiseint = (val & BIT(29)) >> 29;
955 uint8_t opcode = (val & BITS(27, 26)) >> 26;
956 uint8_t phy = (val & BITS(25, 21)) >> 21;
957 uint8_t reg = (val & BITS(20, 16)) >> 16;
958 uint16_t data = (val & BITS(15, 0));
959#endif
960 /* Emulation takes no time to finish MDI transaction. */
961 val |= BIT(28);
962 TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n",
963 val, raiseint, mdi_op_name[opcode], phy,
964 mdi_reg_name[reg], data));
965 return val;
966}
967
968//~ #define BITS(val, upper, lower) (val & ???)
969static void eepro100_write_mdi(EEPRO100State * s, uint32_t val)
970{
971 uint8_t raiseint = (val & BIT(29)) >> 29;
972 uint8_t opcode = (val & BITS(27, 26)) >> 26;
973 uint8_t phy = (val & BITS(25, 21)) >> 21;
974 uint8_t reg = (val & BITS(20, 16)) >> 16;
975 uint16_t data = (val & BITS(15, 0));
976 if (phy != 1) {
977 /* Unsupported PHY address. */
978 //~ logout("phy must be 1 but is %u\n", phy);
979 data = 0;
980 } else if (opcode != 1 && opcode != 2) {
981 /* Unsupported opcode. */
982 logout("opcode must be 1 or 2 but is %u\n", opcode);
983 data = 0;
984 } else if (reg > 6) {
985 /* Unsupported register. */
986 logout("register must be 0...6 but is %u\n", reg);
987 data = 0;
988 } else {
989 TRACE(MDI, logout("val=0x%08x (int=%u, %s, phy=%u, %s, data=0x%04x\n",
990 val, raiseint, mdi_op_name[opcode], phy,
991 mdi_reg_name[reg], data));
992 if (opcode == 1) {
993 /* MDI write */
994 switch (reg) {
995 case 0: /* Control Register */
996 if (data & 0x8000) {
997 /* Reset status and control registers to default. */
998 s->mdimem[0] = eepro100_mdi_default[0];
999 s->mdimem[1] = eepro100_mdi_default[1];
1000 data = s->mdimem[reg];
1001 } else {
1002 /* Restart Auto Configuration = Normal Operation */
1003 data &= ~0x0200;
1004 }
1005 break;
1006 case 1: /* Status Register */
1007 missing("not writable");
1008 data = s->mdimem[reg];
1009 break;
1010 case 2: /* PHY Identification Register (Word 1) */
1011 case 3: /* PHY Identification Register (Word 2) */
1012 missing("not implemented");
1013 break;
1014 case 4: /* Auto-Negotiation Advertisement Register */
1015 case 5: /* Auto-Negotiation Link Partner Ability Register */
1016 break;
1017 case 6: /* Auto-Negotiation Expansion Register */
1018 default:
1019 missing("not implemented");
1020 }
1021 s->mdimem[reg] = data;
1022 } else if (opcode == 2) {
1023 /* MDI read */
1024 switch (reg) {
1025 case 0: /* Control Register */
1026 if (data & 0x8000) {
1027 /* Reset status and control registers to default. */
1028 s->mdimem[0] = eepro100_mdi_default[0];
1029 s->mdimem[1] = eepro100_mdi_default[1];
1030 }
1031 break;
1032 case 1: /* Status Register */
1033 s->mdimem[reg] |= 0x0020;
1034 break;
1035 case 2: /* PHY Identification Register (Word 1) */
1036 case 3: /* PHY Identification Register (Word 2) */
1037 case 4: /* Auto-Negotiation Advertisement Register */
1038 break;
1039 case 5: /* Auto-Negotiation Link Partner Ability Register */
1040 s->mdimem[reg] = 0x41fe;
1041 break;
1042 case 6: /* Auto-Negotiation Expansion Register */
1043 s->mdimem[reg] = 0x0001;
1044 break;
1045 }
1046 data = s->mdimem[reg];
1047 }
1048 /* Emulation takes no time to finish MDI transaction.
1049 * Set MDI bit in SCB status register. */
1050 s->mem[SCBAck] |= 0x08;
1051 val |= BIT(28);
1052 if (raiseint) {
1053 eepro100_mdi_interrupt(s);
1054 }
1055 }
1056 val = (val & 0xffff0000) + data;
1057 memcpy(&s->mem[0x10], &val, sizeof(val));
1058}
1059
1060/*****************************************************************************
1061 *
1062 * Port emulation.
1063 *
1064 ****************************************************************************/
1065
1066#define PORT_SOFTWARE_RESET 0
1067#define PORT_SELFTEST 1
1068#define PORT_SELECTIVE_RESET 2
1069#define PORT_DUMP 3
1070#define PORT_SELECTION_MASK 3
1071
1072typedef struct {
1073 uint32_t st_sign; /* Self Test Signature */
1074 uint32_t st_result; /* Self Test Results */
1075} eepro100_selftest_t;
1076
1077static uint32_t eepro100_read_port(EEPRO100State * s)
1078{
1079 return 0;
1080}
1081
1082static void eepro100_write_port(EEPRO100State * s, uint32_t val)
1083{
1084 val = le32_to_cpu(val);
1085 uint32_t address = (val & ~PORT_SELECTION_MASK);
1086 uint8_t selection = (val & PORT_SELECTION_MASK);
1087 switch (selection) {
1088 case PORT_SOFTWARE_RESET:
1089 nic_reset(s);
1090 break;
1091 case PORT_SELFTEST:
1092 logout("selftest address=0x%08x\n", address);
1093 eepro100_selftest_t data;
1094 cpu_physical_memory_read(address, (uint8_t *) & data, sizeof(data));
1095 data.st_sign = 0xffffffff;
1096 data.st_result = 0;
1097 cpu_physical_memory_write(address, (uint8_t *) & data, sizeof(data));
1098 break;
1099 case PORT_SELECTIVE_RESET:
1100 logout("selective reset, selftest address=0x%08x\n", address);
1101 nic_selective_reset(s);
1102 break;
1103 default:
1104 logout("val=0x%08x\n", val);
1105 missing("unknown port selection");
1106 }
1107}
1108
1109/*****************************************************************************
1110 *
1111 * General hardware emulation.
1112 *
1113 ****************************************************************************/
1114
1115static uint8_t eepro100_read1(EEPRO100State * s, uint32_t addr)
1116{
1117 uint8_t val;
1118 if (addr <= sizeof(s->mem) - sizeof(val)) {
1119 memcpy(&val, &s->mem[addr], sizeof(val));
1120 }
1121
1122 switch (addr) {
1123 case SCBStatus:
1124 //~ val = eepro100_read_status(s);
1125 logout("addr=%s val=0x%02x\n", regname(addr), val);
1126 break;
1127 case SCBAck:
1128 //~ val = eepro100_read_status(s);
1129 logout("addr=%s val=0x%02x\n", regname(addr), val);
1130 break;
1131 case SCBCmd:
1132 logout("addr=%s val=0x%02x\n", regname(addr), val);
1133 //~ val = eepro100_read_command(s);
1134 break;
1135 case SCBIntmask:
1136 logout("addr=%s val=0x%02x\n", regname(addr), val);
1137 break;
1138 case SCBPort + 3:
1139 logout("addr=%s val=0x%02x\n", regname(addr), val);
1140 break;
1141 case SCBeeprom:
1142 val = eepro100_read_eeprom(s);
1143 break;
1144 case 0x1b: /* PMDR (power management driver register) */
1145 val = 0;
1146 logout("addr=%s val=0x%02x\n", regname(addr), val);
1147 break;
1148 case 0x1d: /* general status register */
1149 /* 100 Mbps full duplex, valid link */
1150 val = 0x07;
1151 logout("addr=General Status val=%02x\n", val);
1152 break;
1153 default:
1154 logout("addr=%s val=0x%02x\n", regname(addr), val);
1155 missing("unknown byte read");
1156 }
1157 return val;
1158}
1159
1160static uint16_t eepro100_read2(EEPRO100State * s, uint32_t addr)
1161{
1162 uint16_t val;
1163 if (addr <= sizeof(s->mem) - sizeof(val)) {
1164 memcpy(&val, &s->mem[addr], sizeof(val));
1165 }
1166
1167 logout("addr=%s val=0x%04x\n", regname(addr), val);
1168
1169 switch (addr) {
1170 case SCBStatus:
1171 //~ val = eepro100_read_status(s);
1172 break;
1173 case SCBeeprom:
1174 val = eepro100_read_eeprom(s);
1175 break;
1176 default:
1177 logout("addr=%s val=0x%04x\n", regname(addr), val);
1178 missing("unknown word read");
1179 }
1180 return val;
1181}
1182
1183static uint32_t eepro100_read4(EEPRO100State * s, uint32_t addr)
1184{
1185 uint32_t val;
1186 if (addr <= sizeof(s->mem) - sizeof(val)) {
1187 memcpy(&val, &s->mem[addr], sizeof(val));
1188 }
1189
1190 switch (addr) {
1191 case SCBStatus:
1192 //~ val = eepro100_read_status(s);
1193 logout("addr=%s val=0x%08x\n", regname(addr), val);
1194 break;
1195 case SCBPointer:
1196 //~ val = eepro100_read_pointer(s);
1197 logout("addr=%s val=0x%08x\n", regname(addr), val);
1198 break;
1199 case SCBPort:
1200 val = eepro100_read_port(s);
1201 logout("addr=%s val=0x%08x\n", regname(addr), val);
1202 break;
1203 case SCBCtrlMDI:
1204 val = eepro100_read_mdi(s);
1205 break;
1206 default:
1207 logout("addr=%s val=0x%08x\n", regname(addr), val);
1208 missing("unknown longword read");
1209 }
1210 return val;
1211}
1212
1213static void eepro100_write1(EEPRO100State * s, uint32_t addr, uint8_t val)
1214{
1215 if (addr <= sizeof(s->mem) - sizeof(val)) {
1216 memcpy(&s->mem[addr], &val, sizeof(val));
1217 }
1218
1219 logout("addr=%s val=0x%02x\n", regname(addr), val);
1220
1221 switch (addr) {
1222 case SCBStatus:
1223 //~ eepro100_write_status(s, val);
1224 break;
1225 case SCBAck:
1226 eepro100_acknowledge(s);
1227 break;
1228 case SCBCmd:
1229 eepro100_write_command(s, val);
1230 break;
1231 case SCBIntmask:
1232 if (val & BIT(1)) {
1233 eepro100_swi_interrupt(s);
1234 }
1235 eepro100_interrupt(s, 0);
1236 break;
1237 case SCBPort + 3:
3257d2b6
TS
1238 case SCBFlow:
1239 case SCBFlow + 1:
1240 case SCBFlow + 2:
1241 case SCBFlow + 3:
663e8e51
TS
1242 logout("addr=%s val=0x%02x\n", regname(addr), val);
1243 break;
1244 case SCBeeprom:
1245 eepro100_write_eeprom(s->eeprom, val);
1246 break;
1247 default:
1248 logout("addr=%s val=0x%02x\n", regname(addr), val);
1249 missing("unknown byte write");
1250 }
1251}
1252
1253static void eepro100_write2(EEPRO100State * s, uint32_t addr, uint16_t val)
1254{
1255 if (addr <= sizeof(s->mem) - sizeof(val)) {
1256 memcpy(&s->mem[addr], &val, sizeof(val));
1257 }
1258
1259 logout("addr=%s val=0x%04x\n", regname(addr), val);
1260
1261 switch (addr) {
1262 case SCBStatus:
1263 //~ eepro100_write_status(s, val);
1264 eepro100_acknowledge(s);
1265 break;
1266 case SCBCmd:
1267 eepro100_write_command(s, val);
1268 eepro100_write1(s, SCBIntmask, val >> 8);
1269 break;
1270 case SCBeeprom:
1271 eepro100_write_eeprom(s->eeprom, val);
1272 break;
1273 default:
1274 logout("addr=%s val=0x%04x\n", regname(addr), val);
1275 missing("unknown word write");
1276 }
1277}
1278
1279static void eepro100_write4(EEPRO100State * s, uint32_t addr, uint32_t val)
1280{
1281 if (addr <= sizeof(s->mem) - sizeof(val)) {
1282 memcpy(&s->mem[addr], &val, sizeof(val));
1283 }
1284
1285 switch (addr) {
1286 case SCBPointer:
1287 eepro100_write_pointer(s, val);
1288 break;
1289 case SCBPort:
1290 logout("addr=%s val=0x%08x\n", regname(addr), val);
1291 eepro100_write_port(s, val);
1292 break;
1293 case SCBCtrlMDI:
1294 eepro100_write_mdi(s, val);
1295 break;
1296 default:
1297 logout("addr=%s val=0x%08x\n", regname(addr), val);
1298 missing("unknown longword write");
1299 }
1300}
1301
1302static uint32_t ioport_read1(void *opaque, uint32_t addr)
1303{
1304 EEPRO100State *s = opaque;
1305 //~ logout("addr=%s\n", regname(addr));
1306 return eepro100_read1(s, addr - s->region[1]);
1307}
1308
1309static uint32_t ioport_read2(void *opaque, uint32_t addr)
1310{
1311 EEPRO100State *s = opaque;
1312 return eepro100_read2(s, addr - s->region[1]);
1313}
1314
1315static uint32_t ioport_read4(void *opaque, uint32_t addr)
1316{
1317 EEPRO100State *s = opaque;
1318 return eepro100_read4(s, addr - s->region[1]);
1319}
1320
1321static void ioport_write1(void *opaque, uint32_t addr, uint32_t val)
1322{
1323 EEPRO100State *s = opaque;
1324 //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
1325 eepro100_write1(s, addr - s->region[1], val);
1326}
1327
1328static void ioport_write2(void *opaque, uint32_t addr, uint32_t val)
1329{
1330 EEPRO100State *s = opaque;
1331 eepro100_write2(s, addr - s->region[1], val);
1332}
1333
1334static void ioport_write4(void *opaque, uint32_t addr, uint32_t val)
1335{
1336 EEPRO100State *s = opaque;
1337 eepro100_write4(s, addr - s->region[1], val);
1338}
1339
1340/***********************************************************/
1341/* PCI EEPRO100 definitions */
1342
663e8e51
TS
1343static void pci_map(PCIDevice * pci_dev, int region_num,
1344 uint32_t addr, uint32_t size, int type)
1345{
273a2142 1346 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51
TS
1347
1348 logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n",
1349 region_num, addr, size, type);
1350
1351 assert(region_num == 1);
1352 register_ioport_write(addr, size, 1, ioport_write1, s);
1353 register_ioport_read(addr, size, 1, ioport_read1, s);
1354 register_ioport_write(addr, size, 2, ioport_write2, s);
1355 register_ioport_read(addr, size, 2, ioport_read2, s);
1356 register_ioport_write(addr, size, 4, ioport_write4, s);
1357 register_ioport_read(addr, size, 4, ioport_read4, s);
1358
1359 s->region[region_num] = addr;
1360}
1361
1362static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
1363{
1364 EEPRO100State *s = opaque;
663e8e51
TS
1365 //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
1366 eepro100_write1(s, addr, val);
1367}
1368
1369static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
1370{
1371 EEPRO100State *s = opaque;
663e8e51
TS
1372 //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
1373 eepro100_write2(s, addr, val);
1374}
1375
1376static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
1377{
1378 EEPRO100State *s = opaque;
663e8e51
TS
1379 //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
1380 eepro100_write4(s, addr, val);
1381}
1382
1383static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
1384{
1385 EEPRO100State *s = opaque;
663e8e51
TS
1386 //~ logout("addr=%s\n", regname(addr));
1387 return eepro100_read1(s, addr);
1388}
1389
1390static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
1391{
1392 EEPRO100State *s = opaque;
663e8e51
TS
1393 //~ logout("addr=%s\n", regname(addr));
1394 return eepro100_read2(s, addr);
1395}
1396
1397static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
1398{
1399 EEPRO100State *s = opaque;
663e8e51
TS
1400 //~ logout("addr=%s\n", regname(addr));
1401 return eepro100_read4(s, addr);
1402}
1403
d60efc6b 1404static CPUWriteMemoryFunc * const pci_mmio_write[] = {
663e8e51
TS
1405 pci_mmio_writeb,
1406 pci_mmio_writew,
1407 pci_mmio_writel
1408};
1409
d60efc6b 1410static CPUReadMemoryFunc * const pci_mmio_read[] = {
663e8e51
TS
1411 pci_mmio_readb,
1412 pci_mmio_readw,
1413 pci_mmio_readl
1414};
1415
1416static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
1417 uint32_t addr, uint32_t size, int type)
1418{
273a2142 1419 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51
TS
1420
1421 logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n",
1422 region_num, addr, size, type);
1423
1424 if (region_num == 0) {
1425 /* Map control / status registers. */
273a2142
JQ
1426 cpu_register_physical_memory(addr, size, s->mmio_index);
1427 s->region[region_num] = addr;
663e8e51
TS
1428 }
1429}
1430
e3f5ec2b 1431static int nic_can_receive(VLANClientState *vc)
663e8e51 1432{
e3f5ec2b 1433 EEPRO100State *s = vc->opaque;
663e8e51
TS
1434 logout("%p\n", s);
1435 return get_ru_state(s) == ru_ready;
1436 //~ return !eepro100_buffer_full(s);
1437}
1438
4f1c942b 1439static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
663e8e51
TS
1440{
1441 /* TODO:
1442 * - Magic packets should set bit 30 in power management driver register.
1443 * - Interesting packets should set bit 29 in power management driver register.
1444 */
e3f5ec2b 1445 EEPRO100State *s = vc->opaque;
663e8e51
TS
1446 uint16_t rfd_status = 0xa000;
1447 static const uint8_t broadcast_macaddr[6] =
1448 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1449
1450 /* TODO: check multiple IA bit. */
1451 assert(!(s->configuration[20] & BIT(6)));
1452
1453 if (s->configuration[8] & 0x80) {
1454 /* CSMA is disabled. */
1455 logout("%p received while CSMA is disabled\n", s);
4f1c942b 1456 return -1;
663e8e51
TS
1457 } else if (size < 64 && (s->configuration[7] & 1)) {
1458 /* Short frame and configuration byte 7/0 (discard short receive) set:
1459 * Short frame is discarded */
1460 logout("%p received short frame (%d byte)\n", s, size);
1461 s->statistics.rx_short_frame_errors++;
4f1c942b 1462 //~ return -1;
663e8e51
TS
1463 } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) {
1464 /* Long frame and configuration byte 18/3 (long receive ok) not set:
1465 * Long frames are discarded. */
1466 logout("%p received long frame (%d byte), ignored\n", s, size);
4f1c942b 1467 return -1;
663e8e51
TS
1468 } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!!
1469 /* Frame matches individual address. */
1470 /* TODO: check configuration byte 15/4 (ignore U/L). */
1471 logout("%p received frame for me, len=%d\n", s, size);
1472 } else if (memcmp(buf, broadcast_macaddr, 6) == 0) {
1473 /* Broadcast frame. */
1474 logout("%p received broadcast, len=%d\n", s, size);
1475 rfd_status |= 0x0002;
1476 } else if (buf[0] & 0x01) { // !!!
1477 /* Multicast frame. */
1478 logout("%p received multicast, len=%d\n", s, size);
1479 /* TODO: check multicast all bit. */
1480 assert(!(s->configuration[21] & BIT(3)));
1481 int mcast_idx = compute_mcast_idx(buf);
1482 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) {
4f1c942b 1483 return size;
663e8e51
TS
1484 }
1485 rfd_status |= 0x0002;
1486 } else if (s->configuration[15] & 1) {
1487 /* Promiscuous: receive all. */
1488 logout("%p received frame in promiscuous mode, len=%d\n", s, size);
1489 rfd_status |= 0x0004;
1490 } else {
1491 logout("%p received frame, ignored, len=%d,%s\n", s, size,
1492 nic_dump(buf, size));
4f1c942b 1493 return size;
663e8e51
TS
1494 }
1495
1496 if (get_ru_state(s) != ru_ready) {
1497 /* No ressources available. */
1498 logout("no ressources, state=%u\n", get_ru_state(s));
1499 s->statistics.rx_resource_errors++;
1500 //~ assert(!"no ressources");
4f1c942b 1501 return -1;
663e8e51
TS
1502 }
1503 //~ !!!
1504//~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}}
1505 eepro100_rx_t rx;
1506 cpu_physical_memory_read(s->ru_base + s->ru_offset, (uint8_t *) & rx,
1507 offsetof(eepro100_rx_t, packet));
1508 uint16_t rfd_command = le16_to_cpu(rx.command);
1509 uint16_t rfd_size = le16_to_cpu(rx.size);
1510 assert(size <= rfd_size);
1511 if (size < 64) {
1512 rfd_status |= 0x0080;
1513 }
1514 logout("command 0x%04x, link 0x%08x, addr 0x%08x, size %u\n", rfd_command,
1515 rx.link, rx.rx_buf_addr, rfd_size);
1516 stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, status),
1517 rfd_status);
1518 stw_phys(s->ru_base + s->ru_offset + offsetof(eepro100_rx_t, count), size);
1519 /* Early receive interrupt not supported. */
1520 //~ eepro100_er_interrupt(s);
1521 /* Receive CRC Transfer not supported. */
1522 assert(!(s->configuration[18] & 4));
1523 /* TODO: check stripping enable bit. */
1524 //~ assert(!(s->configuration[17] & 1));
1525 cpu_physical_memory_write(s->ru_base + s->ru_offset +
1526 offsetof(eepro100_rx_t, packet), buf, size);
1527 s->statistics.rx_good_frames++;
1528 eepro100_fr_interrupt(s);
1529 s->ru_offset = le32_to_cpu(rx.link);
1530 if (rfd_command & 0x8000) {
1531 /* EL bit is set, so this was the last frame. */
1532 assert(0);
1533 }
1534 if (rfd_command & 0x4000) {
1535 /* S bit is set. */
1536 set_ru_state(s, ru_suspended);
1537 }
4f1c942b 1538 return size;
663e8e51
TS
1539}
1540
1541static int nic_load(QEMUFile * f, void *opaque, int version_id)
1542{
769cf7a5 1543 EEPRO100State *s = opaque;
2657c663 1544 int i;
663e8e51
TS
1545 int ret;
1546
663e8e51
TS
1547 if (version_id > 3)
1548 return -EINVAL;
1549
273a2142
JQ
1550 if (version_id >= 3) {
1551 ret = pci_device_load(&s->dev, f);
663e8e51
TS
1552 if (ret < 0)
1553 return ret;
1554 }
1555
1556 if (version_id >= 2) {
1557 qemu_get_8s(f, &s->rxcr);
1558 } else {
1559 s->rxcr = 0x0c;
1560 }
1561
1562 qemu_get_8s(f, &s->cmd);
1563 qemu_get_be32s(f, &s->start);
1564 qemu_get_be32s(f, &s->stop);
1565 qemu_get_8s(f, &s->boundary);
1566 qemu_get_8s(f, &s->tsr);
1567 qemu_get_8s(f, &s->tpsr);
1568 qemu_get_be16s(f, &s->tcnt);
1569 qemu_get_be16s(f, &s->rcnt);
1570 qemu_get_be32s(f, &s->rsar);
1571 qemu_get_8s(f, &s->rsr);
1572 qemu_get_8s(f, &s->isr);
1573 qemu_get_8s(f, &s->dcfg);
1574 qemu_get_8s(f, &s->imr);
1575 qemu_get_buffer(f, s->phys, 6);
1576 qemu_get_8s(f, &s->curpag);
1577 qemu_get_buffer(f, s->mult, 8);
1578 qemu_get_buffer(f, s->mem, sizeof(s->mem));
1579
2657c663
AZ
1580 /* Restore all members of struct between scv_stat and mem */
1581 qemu_get_8s(f, &s->scb_stat);
1582 qemu_get_8s(f, &s->int_stat);
1583 for (i = 0; i < 3; i++)
1584 qemu_get_be32s(f, &s->region[i]);
1585 qemu_get_buffer(f, s->macaddr, 6);
5fafdf24 1586 for (i = 0; i < 19; i++)
2657c663
AZ
1587 qemu_get_be32s(f, &s->statcounter[i]);
1588 for (i = 0; i < 32; i++)
1589 qemu_get_be16s(f, &s->mdimem[i]);
1590 /* The eeprom should be saved and restored by its own routines */
1591 qemu_get_be32s(f, &s->device);
1592 qemu_get_be32s(f, &s->pointer);
1593 qemu_get_be32s(f, &s->cu_base);
1594 qemu_get_be32s(f, &s->cu_offset);
1595 qemu_get_be32s(f, &s->ru_base);
1596 qemu_get_be32s(f, &s->ru_offset);
1597 qemu_get_be32s(f, &s->statsaddr);
1598 /* Restore epro100_stats_t statistics */
1599 qemu_get_be32s(f, &s->statistics.tx_good_frames);
1600 qemu_get_be32s(f, &s->statistics.tx_max_collisions);
1601 qemu_get_be32s(f, &s->statistics.tx_late_collisions);
1602 qemu_get_be32s(f, &s->statistics.tx_underruns);
1603 qemu_get_be32s(f, &s->statistics.tx_lost_crs);
1604 qemu_get_be32s(f, &s->statistics.tx_deferred);
1605 qemu_get_be32s(f, &s->statistics.tx_single_collisions);
1606 qemu_get_be32s(f, &s->statistics.tx_multiple_collisions);
1607 qemu_get_be32s(f, &s->statistics.tx_total_collisions);
1608 qemu_get_be32s(f, &s->statistics.rx_good_frames);
1609 qemu_get_be32s(f, &s->statistics.rx_crc_errors);
1610 qemu_get_be32s(f, &s->statistics.rx_alignment_errors);
1611 qemu_get_be32s(f, &s->statistics.rx_resource_errors);
1612 qemu_get_be32s(f, &s->statistics.rx_overrun_errors);
1613 qemu_get_be32s(f, &s->statistics.rx_cdt_errors);
1614 qemu_get_be32s(f, &s->statistics.rx_short_frame_errors);
1615 qemu_get_be32s(f, &s->statistics.fc_xmt_pause);
1616 qemu_get_be32s(f, &s->statistics.fc_rcv_pause);
1617 qemu_get_be32s(f, &s->statistics.fc_rcv_unsupported);
1618 qemu_get_be16s(f, &s->statistics.xmt_tco_frames);
1619 qemu_get_be16s(f, &s->statistics.rcv_tco_frames);
1620 qemu_get_be32s(f, &s->statistics.complete);
1621#if 0
1622 qemu_get_be16s(f, &s->status);
1623#endif
1624
1625 /* Configuration bytes. */
1626 qemu_get_buffer(f, s->configuration, sizeof(s->configuration));
1627
663e8e51
TS
1628 return 0;
1629}
1630
1631static void nic_save(QEMUFile * f, void *opaque)
1632{
769cf7a5 1633 EEPRO100State *s = opaque;
2657c663 1634 int i;
663e8e51 1635
273a2142 1636 pci_device_save(&s->dev, f);
663e8e51
TS
1637
1638 qemu_put_8s(f, &s->rxcr);
1639
1640 qemu_put_8s(f, &s->cmd);
1641 qemu_put_be32s(f, &s->start);
1642 qemu_put_be32s(f, &s->stop);
1643 qemu_put_8s(f, &s->boundary);
1644 qemu_put_8s(f, &s->tsr);
1645 qemu_put_8s(f, &s->tpsr);
1646 qemu_put_be16s(f, &s->tcnt);
1647 qemu_put_be16s(f, &s->rcnt);
1648 qemu_put_be32s(f, &s->rsar);
1649 qemu_put_8s(f, &s->rsr);
1650 qemu_put_8s(f, &s->isr);
1651 qemu_put_8s(f, &s->dcfg);
1652 qemu_put_8s(f, &s->imr);
1653 qemu_put_buffer(f, s->phys, 6);
1654 qemu_put_8s(f, &s->curpag);
1655 qemu_put_buffer(f, s->mult, 8);
1656 qemu_put_buffer(f, s->mem, sizeof(s->mem));
2657c663
AZ
1657
1658 /* Save all members of struct between scv_stat and mem */
1659 qemu_put_8s(f, &s->scb_stat);
1660 qemu_put_8s(f, &s->int_stat);
1661 for (i = 0; i < 3; i++)
1662 qemu_put_be32s(f, &s->region[i]);
1663 qemu_put_buffer(f, s->macaddr, 6);
5fafdf24 1664 for (i = 0; i < 19; i++)
2657c663
AZ
1665 qemu_put_be32s(f, &s->statcounter[i]);
1666 for (i = 0; i < 32; i++)
1667 qemu_put_be16s(f, &s->mdimem[i]);
1668 /* The eeprom should be saved and restored by its own routines */
1669 qemu_put_be32s(f, &s->device);
1670 qemu_put_be32s(f, &s->pointer);
1671 qemu_put_be32s(f, &s->cu_base);
1672 qemu_put_be32s(f, &s->cu_offset);
1673 qemu_put_be32s(f, &s->ru_base);
1674 qemu_put_be32s(f, &s->ru_offset);
1675 qemu_put_be32s(f, &s->statsaddr);
1676 /* Save epro100_stats_t statistics */
1677 qemu_put_be32s(f, &s->statistics.tx_good_frames);
1678 qemu_put_be32s(f, &s->statistics.tx_max_collisions);
1679 qemu_put_be32s(f, &s->statistics.tx_late_collisions);
1680 qemu_put_be32s(f, &s->statistics.tx_underruns);
1681 qemu_put_be32s(f, &s->statistics.tx_lost_crs);
1682 qemu_put_be32s(f, &s->statistics.tx_deferred);
1683 qemu_put_be32s(f, &s->statistics.tx_single_collisions);
1684 qemu_put_be32s(f, &s->statistics.tx_multiple_collisions);
1685 qemu_put_be32s(f, &s->statistics.tx_total_collisions);
1686 qemu_put_be32s(f, &s->statistics.rx_good_frames);
1687 qemu_put_be32s(f, &s->statistics.rx_crc_errors);
1688 qemu_put_be32s(f, &s->statistics.rx_alignment_errors);
1689 qemu_put_be32s(f, &s->statistics.rx_resource_errors);
1690 qemu_put_be32s(f, &s->statistics.rx_overrun_errors);
1691 qemu_put_be32s(f, &s->statistics.rx_cdt_errors);
1692 qemu_put_be32s(f, &s->statistics.rx_short_frame_errors);
1693 qemu_put_be32s(f, &s->statistics.fc_xmt_pause);
1694 qemu_put_be32s(f, &s->statistics.fc_rcv_pause);
1695 qemu_put_be32s(f, &s->statistics.fc_rcv_unsupported);
1696 qemu_put_be16s(f, &s->statistics.xmt_tco_frames);
1697 qemu_put_be16s(f, &s->statistics.rcv_tco_frames);
1698 qemu_put_be32s(f, &s->statistics.complete);
1699#if 0
1700 qemu_put_be16s(f, &s->status);
1701#endif
1702
1703 /* Configuration bytes. */
1704 qemu_put_buffer(f, s->configuration, sizeof(s->configuration));
663e8e51
TS
1705}
1706
b946a153
AL
1707static void nic_cleanup(VLANClientState *vc)
1708{
1709 EEPRO100State *s = vc->opaque;
1710
1711 unregister_savevm(vc->model, s);
1712
1713 eeprom93xx_free(s->eeprom);
1714}
1715
1716static int pci_nic_uninit(PCIDevice *dev)
1717{
273a2142 1718 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, dev);
b946a153
AL
1719
1720 cpu_unregister_io_memory(s->mmio_index);
1721
1722 return 0;
1723}
1724
81a322d4 1725static int nic_init(PCIDevice *pci_dev, uint32_t device)
663e8e51 1726{
273a2142 1727 EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
663e8e51
TS
1728
1729 logout("\n");
1730
273a2142 1731 s->dev.unregister = pci_nic_uninit;
663e8e51 1732
663e8e51 1733 s->device = device;
663e8e51
TS
1734
1735 pci_reset(s);
1736
1737 /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM,
1738 * i82559 and later support 64 or 256 word EEPROM. */
1739 s->eeprom = eeprom93xx_new(EEPROM_SIZE);
1740
1741 /* Handler for memory-mapped I/O */
273a2142 1742 s->mmio_index =
1eed09cb 1743 cpu_register_io_memory(pci_mmio_read, pci_mmio_write, s);
663e8e51 1744
273a2142 1745 pci_register_bar(&s->dev, 0, PCI_MEM_SIZE,
663e8e51
TS
1746 PCI_ADDRESS_SPACE_MEM |
1747 PCI_ADDRESS_SPACE_MEM_PREFETCH, pci_mmio_map);
273a2142 1748 pci_register_bar(&s->dev, 1, PCI_IO_SIZE, PCI_ADDRESS_SPACE_IO,
663e8e51 1749 pci_map);
273a2142 1750 pci_register_bar(&s->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM,
663e8e51
TS
1751 pci_mmio_map);
1752
273a2142 1753 qdev_get_macaddr(&s->dev.qdev, s->macaddr);
663e8e51
TS
1754 logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
1755 assert(s->region[1] == 0);
1756
1757 nic_reset(s);
1758
273a2142 1759 s->vc = qdev_get_vlan_client(&s->dev.qdev,
463af534 1760 nic_can_receive, nic_receive, NULL,
b946a153 1761 nic_cleanup, s);
663e8e51 1762
7cb7434b 1763 qemu_format_nic_info_str(s->vc, s->macaddr);
663e8e51 1764
a08d4367 1765 qemu_register_reset(nic_reset, s);
663e8e51 1766
32a8f6ae 1767 register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s);
81a322d4 1768 return 0;
663e8e51
TS
1769}
1770
81a322d4 1771static int pci_i82551_init(PCIDevice *dev)
9d07d757 1772{
81a322d4 1773 return nic_init(dev, i82551);
9d07d757
PB
1774}
1775
81a322d4 1776static int pci_i82557b_init(PCIDevice *dev)
663e8e51 1777{
81a322d4 1778 return nic_init(dev, i82557B);
663e8e51
TS
1779}
1780
81a322d4 1781static int pci_i82559er_init(PCIDevice *dev)
663e8e51 1782{
81a322d4 1783 return nic_init(dev, i82559ER);
663e8e51
TS
1784}
1785
0aab0d3a
GH
1786static PCIDeviceInfo eepro100_info[] = {
1787 {
1788 .qdev.name = "i82551",
273a2142 1789 .qdev.size = sizeof(EEPRO100State),
0aab0d3a
GH
1790 .init = pci_i82551_init,
1791 },{
1792 .qdev.name = "i82557b",
273a2142 1793 .qdev.size = sizeof(EEPRO100State),
0aab0d3a
GH
1794 .init = pci_i82557b_init,
1795 },{
1796 .qdev.name = "i82559er",
273a2142 1797 .qdev.size = sizeof(EEPRO100State),
0aab0d3a
GH
1798 .init = pci_i82559er_init,
1799 },{
1800 /* end of list */
1801 }
1802};
1803
9d07d757 1804static void eepro100_register_devices(void)
663e8e51 1805{
0aab0d3a 1806 pci_qdev_register_many(eepro100_info);
663e8e51
TS
1807}
1808
9d07d757 1809device_init(eepro100_register_devices)
This page took 0.497195 seconds and 4 git commands to generate.