2004-03-14 13:20:30 +01:00
|
|
|
/*
|
|
|
|
* QEMU NE2000 emulation
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-03-14 13:20:30 +01:00
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-03-14 13:20:30 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "hw.h"
|
|
|
|
#include "pci.h"
|
2007-11-18 02:44:38 +01:00
|
|
|
#include "pc.h"
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "net.h"
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
/* debug NE2000 card */
|
|
|
|
//#define DEBUG_NE2000
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
#define MAX_ETH_FRAME_SIZE 1514
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
#define E8390_CMD 0x00 /* The command register (for all pages) */
|
|
|
|
/* Page 0 register offsets. */
|
|
|
|
#define EN0_CLDALO 0x01 /* Low byte of current local dma addr RD */
|
|
|
|
#define EN0_STARTPG 0x01 /* Starting page of ring bfr WR */
|
|
|
|
#define EN0_CLDAHI 0x02 /* High byte of current local dma addr RD */
|
|
|
|
#define EN0_STOPPG 0x02 /* Ending page +1 of ring bfr WR */
|
|
|
|
#define EN0_BOUNDARY 0x03 /* Boundary page of ring bfr RD WR */
|
|
|
|
#define EN0_TSR 0x04 /* Transmit status reg RD */
|
|
|
|
#define EN0_TPSR 0x04 /* Transmit starting page WR */
|
|
|
|
#define EN0_NCR 0x05 /* Number of collision reg RD */
|
|
|
|
#define EN0_TCNTLO 0x05 /* Low byte of tx byte count WR */
|
|
|
|
#define EN0_FIFO 0x06 /* FIFO RD */
|
|
|
|
#define EN0_TCNTHI 0x06 /* High byte of tx byte count WR */
|
|
|
|
#define EN0_ISR 0x07 /* Interrupt status reg RD WR */
|
|
|
|
#define EN0_CRDALO 0x08 /* low byte of current remote dma address RD */
|
|
|
|
#define EN0_RSARLO 0x08 /* Remote start address reg 0 */
|
|
|
|
#define EN0_CRDAHI 0x09 /* high byte, current remote dma address RD */
|
|
|
|
#define EN0_RSARHI 0x09 /* Remote start address reg 1 */
|
|
|
|
#define EN0_RCNTLO 0x0a /* Remote byte count reg WR */
|
2005-11-22 21:16:13 +01:00
|
|
|
#define EN0_RTL8029ID0 0x0a /* Realtek ID byte #1 RD */
|
2004-03-14 13:20:30 +01:00
|
|
|
#define EN0_RCNTHI 0x0b /* Remote byte count reg WR */
|
2005-11-22 21:16:13 +01:00
|
|
|
#define EN0_RTL8029ID1 0x0b /* Realtek ID byte #2 RD */
|
2004-03-14 13:20:30 +01:00
|
|
|
#define EN0_RSR 0x0c /* rx status reg RD */
|
|
|
|
#define EN0_RXCR 0x0c /* RX configuration reg WR */
|
|
|
|
#define EN0_TXCR 0x0d /* TX configuration reg WR */
|
|
|
|
#define EN0_COUNTER0 0x0d /* Rcv alignment error counter RD */
|
|
|
|
#define EN0_DCFG 0x0e /* Data configuration reg WR */
|
|
|
|
#define EN0_COUNTER1 0x0e /* Rcv CRC error counter RD */
|
|
|
|
#define EN0_IMR 0x0f /* Interrupt mask reg WR */
|
|
|
|
#define EN0_COUNTER2 0x0f /* Rcv missed frame error counter RD */
|
|
|
|
|
|
|
|
#define EN1_PHYS 0x11
|
|
|
|
#define EN1_CURPAG 0x17
|
|
|
|
#define EN1_MULT 0x18
|
|
|
|
|
2005-04-28 21:45:10 +02:00
|
|
|
#define EN2_STARTPG 0x21 /* Starting page of ring bfr RD */
|
|
|
|
#define EN2_STOPPG 0x22 /* Ending page +1 of ring bfr RD */
|
|
|
|
|
2005-11-22 21:16:13 +01:00
|
|
|
#define EN3_CONFIG0 0x33
|
|
|
|
#define EN3_CONFIG1 0x34
|
|
|
|
#define EN3_CONFIG2 0x35
|
|
|
|
#define EN3_CONFIG3 0x36
|
|
|
|
|
2004-03-14 13:20:30 +01:00
|
|
|
/* Register accessed at EN_CMD, the 8390 base addr. */
|
|
|
|
#define E8390_STOP 0x01 /* Stop and reset the chip */
|
|
|
|
#define E8390_START 0x02 /* Start the chip, clear reset */
|
|
|
|
#define E8390_TRANS 0x04 /* Transmit a frame */
|
|
|
|
#define E8390_RREAD 0x08 /* Remote read */
|
|
|
|
#define E8390_RWRITE 0x10 /* Remote write */
|
|
|
|
#define E8390_NODMA 0x20 /* Remote DMA */
|
|
|
|
#define E8390_PAGE0 0x00 /* Select page chip registers */
|
|
|
|
#define E8390_PAGE1 0x40 /* using the two high-order bits */
|
|
|
|
#define E8390_PAGE2 0x80 /* Page 3 is invalid. */
|
|
|
|
|
|
|
|
/* Bits in EN0_ISR - Interrupt status register */
|
|
|
|
#define ENISR_RX 0x01 /* Receiver, no error */
|
|
|
|
#define ENISR_TX 0x02 /* Transmitter, no error */
|
|
|
|
#define ENISR_RX_ERR 0x04 /* Receiver, with error */
|
|
|
|
#define ENISR_TX_ERR 0x08 /* Transmitter, with error */
|
|
|
|
#define ENISR_OVER 0x10 /* Receiver overwrote the ring */
|
|
|
|
#define ENISR_COUNTERS 0x20 /* Counters need emptying */
|
|
|
|
#define ENISR_RDC 0x40 /* remote dma complete */
|
|
|
|
#define ENISR_RESET 0x80 /* Reset completed */
|
|
|
|
#define ENISR_ALL 0x3f /* Interrupts we will enable */
|
|
|
|
|
|
|
|
/* Bits in received packet status byte and EN0_RSR*/
|
|
|
|
#define ENRSR_RXOK 0x01 /* Received a good packet */
|
|
|
|
#define ENRSR_CRC 0x02 /* CRC error */
|
|
|
|
#define ENRSR_FAE 0x04 /* frame alignment error */
|
|
|
|
#define ENRSR_FO 0x08 /* FIFO overrun */
|
|
|
|
#define ENRSR_MPA 0x10 /* missed pkt */
|
|
|
|
#define ENRSR_PHY 0x20 /* physical/multicast address */
|
|
|
|
#define ENRSR_DIS 0x40 /* receiver disable. set in monitor mode */
|
|
|
|
#define ENRSR_DEF 0x80 /* deferring */
|
|
|
|
|
|
|
|
/* Transmitted packet status, EN0_TSR. */
|
|
|
|
#define ENTSR_PTX 0x01 /* Packet transmitted without error */
|
|
|
|
#define ENTSR_ND 0x02 /* The transmit wasn't deferred. */
|
|
|
|
#define ENTSR_COL 0x04 /* The transmit collided at least once. */
|
|
|
|
#define ENTSR_ABT 0x08 /* The transmit collided 16 times, and was deferred. */
|
|
|
|
#define ENTSR_CRS 0x10 /* The carrier sense was lost. */
|
|
|
|
#define ENTSR_FU 0x20 /* A "FIFO underrun" occurred during transmit. */
|
|
|
|
#define ENTSR_CDH 0x40 /* The collision detect "heartbeat" signal was lost. */
|
|
|
|
#define ENTSR_OWC 0x80 /* There was an out-of-window collision. */
|
|
|
|
|
2004-04-22 01:29:33 +02:00
|
|
|
#define NE2000_PMEM_SIZE (32*1024)
|
|
|
|
#define NE2000_PMEM_START (16*1024)
|
|
|
|
#define NE2000_PMEM_END (NE2000_PMEM_SIZE+NE2000_PMEM_START)
|
|
|
|
#define NE2000_MEM_SIZE NE2000_PMEM_END
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
typedef struct NE2000State {
|
|
|
|
uint8_t cmd;
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
|
|
|
uint8_t boundary;
|
|
|
|
uint8_t tsr;
|
|
|
|
uint8_t tpsr;
|
|
|
|
uint16_t tcnt;
|
|
|
|
uint16_t rcnt;
|
|
|
|
uint32_t rsar;
|
2004-05-22 18:52:29 +02:00
|
|
|
uint8_t rsr;
|
2005-11-15 23:16:05 +01:00
|
|
|
uint8_t rxcr;
|
2004-03-14 13:20:30 +01:00
|
|
|
uint8_t isr;
|
|
|
|
uint8_t dcfg;
|
|
|
|
uint8_t imr;
|
|
|
|
uint8_t phys[6]; /* mac address */
|
|
|
|
uint8_t curpag;
|
|
|
|
uint8_t mult[8]; /* multicast mask array */
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_irq irq;
|
2009-04-17 19:11:08 +02:00
|
|
|
int isa_io_base;
|
2004-05-20 14:43:25 +02:00
|
|
|
PCIDevice *pci_dev;
|
2005-11-15 23:16:05 +01:00
|
|
|
VLANClientState *vc;
|
|
|
|
uint8_t macaddr[6];
|
2004-03-14 13:20:30 +01:00
|
|
|
uint8_t mem[NE2000_MEM_SIZE];
|
|
|
|
} NE2000State;
|
|
|
|
|
|
|
|
static void ne2000_reset(NE2000State *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s->isr = ENISR_RESET;
|
2005-11-15 23:16:05 +01:00
|
|
|
memcpy(s->mem, s->macaddr, 6);
|
2004-03-14 13:20:30 +01:00
|
|
|
s->mem[14] = 0x57;
|
|
|
|
s->mem[15] = 0x57;
|
|
|
|
|
|
|
|
/* duplicate prom data */
|
|
|
|
for(i = 15;i >= 0; i--) {
|
|
|
|
s->mem[2 * i] = s->mem[i];
|
|
|
|
s->mem[2 * i + 1] = s->mem[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ne2000_update_irq(NE2000State *s)
|
|
|
|
{
|
|
|
|
int isr;
|
2005-04-28 21:45:10 +02:00
|
|
|
isr = (s->isr & s->imr) & 0x7f;
|
2004-04-12 22:39:29 +02:00
|
|
|
#if defined(DEBUG_NE2000)
|
2007-04-07 20:14:41 +02:00
|
|
|
printf("NE2000: Set IRQ to %d (%02x %02x)\n",
|
|
|
|
isr ? 1 : 0, s->isr, s->imr);
|
2004-04-12 22:39:29 +02:00
|
|
|
#endif
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_set_irq(s->irq, (isr != 0));
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
|
2005-11-15 23:16:05 +01:00
|
|
|
#define POLYNOMIAL 0x04c11db6
|
|
|
|
|
|
|
|
/* From FreeBSD */
|
|
|
|
/* XXX: optimize */
|
|
|
|
static int compute_mcast_idx(const uint8_t *ep)
|
|
|
|
{
|
|
|
|
uint32_t crc;
|
|
|
|
int carry, i, j;
|
|
|
|
uint8_t b;
|
|
|
|
|
|
|
|
crc = 0xffffffff;
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
b = *ep++;
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
|
|
|
|
crc <<= 1;
|
|
|
|
b >>= 1;
|
|
|
|
if (carry)
|
|
|
|
crc = ((crc ^ POLYNOMIAL) | carry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (crc >> 26);
|
|
|
|
}
|
|
|
|
|
2006-02-04 23:15:28 +01:00
|
|
|
static int ne2000_buffer_full(NE2000State *s)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
|
|
|
int avail, index, boundary;
|
2006-02-04 23:15:28 +01:00
|
|
|
|
2004-03-14 13:20:30 +01:00
|
|
|
index = s->curpag << 8;
|
|
|
|
boundary = s->boundary << 8;
|
2007-04-02 10:19:57 +02:00
|
|
|
if (index < boundary)
|
2004-03-14 13:20:30 +01:00
|
|
|
avail = boundary - index;
|
|
|
|
else
|
|
|
|
avail = (s->stop - s->start) - (index - boundary);
|
|
|
|
if (avail < (MAX_ETH_FRAME_SIZE + 4))
|
2006-02-04 23:15:28 +01:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ne2000_can_receive(void *opaque)
|
|
|
|
{
|
|
|
|
NE2000State *s = opaque;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2006-02-04 23:15:28 +01:00
|
|
|
if (s->cmd & E8390_STOP)
|
2008-03-28 23:57:48 +01:00
|
|
|
return 1;
|
2006-02-04 23:15:28 +01:00
|
|
|
return !ne2000_buffer_full(s);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
#define MIN_BUF_SIZE 60
|
|
|
|
|
|
|
|
static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
uint8_t *p;
|
2007-06-25 15:47:44 +02:00
|
|
|
unsigned int total_len, next, avail, len, index, mcast_idx;
|
2004-03-14 22:46:48 +01:00
|
|
|
uint8_t buf1[60];
|
2007-09-16 23:08:06 +02:00
|
|
|
static const uint8_t broadcast_macaddr[6] =
|
2005-11-15 23:16:05 +01:00
|
|
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-03-14 13:20:30 +01:00
|
|
|
#if defined(DEBUG_NE2000)
|
|
|
|
printf("NE2000: received len=%d\n", size);
|
|
|
|
#endif
|
|
|
|
|
2006-02-04 23:15:28 +01:00
|
|
|
if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
|
2005-11-15 23:16:05 +01:00
|
|
|
return;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2005-11-15 23:16:05 +01:00
|
|
|
/* XXX: check this */
|
|
|
|
if (s->rxcr & 0x10) {
|
|
|
|
/* promiscuous: receive all */
|
|
|
|
} else {
|
|
|
|
if (!memcmp(buf, broadcast_macaddr, 6)) {
|
|
|
|
/* broadcast address */
|
|
|
|
if (!(s->rxcr & 0x04))
|
|
|
|
return;
|
|
|
|
} else if (buf[0] & 0x01) {
|
|
|
|
/* multicast */
|
|
|
|
if (!(s->rxcr & 0x08))
|
|
|
|
return;
|
|
|
|
mcast_idx = compute_mcast_idx(buf);
|
|
|
|
if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
|
|
|
|
return;
|
|
|
|
} else if (s->mem[0] == buf[0] &&
|
2007-09-17 10:09:54 +02:00
|
|
|
s->mem[2] == buf[1] &&
|
|
|
|
s->mem[4] == buf[2] &&
|
|
|
|
s->mem[6] == buf[3] &&
|
|
|
|
s->mem[8] == buf[4] &&
|
2005-11-15 23:16:05 +01:00
|
|
|
s->mem[10] == buf[5]) {
|
|
|
|
/* match */
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
/* if too small buffer, then expand it */
|
|
|
|
if (size < MIN_BUF_SIZE) {
|
|
|
|
memcpy(buf1, buf, size);
|
|
|
|
memset(buf1 + size, 0, MIN_BUF_SIZE - size);
|
|
|
|
buf = buf1;
|
|
|
|
size = MIN_BUF_SIZE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 13:20:30 +01:00
|
|
|
index = s->curpag << 8;
|
|
|
|
/* 4 bytes for header */
|
|
|
|
total_len = size + 4;
|
|
|
|
/* address for next packet (4 bytes for CRC) */
|
|
|
|
next = index + ((total_len + 4 + 255) & ~0xff);
|
|
|
|
if (next >= s->stop)
|
|
|
|
next -= (s->stop - s->start);
|
|
|
|
/* prepare packet header */
|
|
|
|
p = s->mem + index;
|
2004-05-22 18:52:29 +02:00
|
|
|
s->rsr = ENRSR_RXOK; /* receive status */
|
|
|
|
/* XXX: check this */
|
|
|
|
if (buf[0] & 0x01)
|
|
|
|
s->rsr |= ENRSR_PHY;
|
|
|
|
p[0] = s->rsr;
|
2004-03-14 13:20:30 +01:00
|
|
|
p[1] = next >> 8;
|
|
|
|
p[2] = total_len;
|
|
|
|
p[3] = total_len >> 8;
|
|
|
|
index += 4;
|
|
|
|
|
|
|
|
/* write packet data */
|
|
|
|
while (size > 0) {
|
2007-06-25 15:47:44 +02:00
|
|
|
if (index <= s->stop)
|
|
|
|
avail = s->stop - index;
|
|
|
|
else
|
|
|
|
avail = 0;
|
2004-03-14 13:20:30 +01:00
|
|
|
len = size;
|
|
|
|
if (len > avail)
|
|
|
|
len = avail;
|
|
|
|
memcpy(s->mem + index, buf, len);
|
|
|
|
buf += len;
|
|
|
|
index += len;
|
|
|
|
if (index == s->stop)
|
|
|
|
index = s->start;
|
|
|
|
size -= len;
|
|
|
|
}
|
|
|
|
s->curpag = next >> 8;
|
2004-05-22 18:52:29 +02:00
|
|
|
|
2006-12-07 19:28:42 +01:00
|
|
|
/* now we can signal we have received something */
|
2004-03-14 13:20:30 +01:00
|
|
|
s->isr |= ENISR_RX;
|
|
|
|
ne2000_update_irq(s);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2005-04-10 16:51:41 +02:00
|
|
|
int offset, page, index;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
addr &= 0xf;
|
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: write addr=0x%x val=0x%02x\n", addr, val);
|
|
|
|
#endif
|
|
|
|
if (addr == E8390_CMD) {
|
|
|
|
/* control register */
|
|
|
|
s->cmd = val;
|
2005-04-28 21:45:10 +02:00
|
|
|
if (!(val & E8390_STOP)) { /* START bit makes no sense on RTL8029... */
|
2004-04-22 01:29:33 +02:00
|
|
|
s->isr &= ~ENISR_RESET;
|
2007-06-03 15:35:16 +02:00
|
|
|
/* test specific case: zero length transfer */
|
2004-03-14 13:20:30 +01:00
|
|
|
if ((val & (E8390_RREAD | E8390_RWRITE)) &&
|
|
|
|
s->rcnt == 0) {
|
|
|
|
s->isr |= ENISR_RDC;
|
|
|
|
ne2000_update_irq(s);
|
|
|
|
}
|
|
|
|
if (val & E8390_TRANS) {
|
2005-04-10 16:51:41 +02:00
|
|
|
index = (s->tpsr << 8);
|
2007-09-16 23:08:06 +02:00
|
|
|
/* XXX: next 2 lines are a hack to make netware 3.11 work */
|
2005-04-10 16:51:41 +02:00
|
|
|
if (index >= NE2000_PMEM_END)
|
|
|
|
index -= NE2000_PMEM_SIZE;
|
|
|
|
/* fail safe: check range on the transmitted length */
|
|
|
|
if (index + s->tcnt <= NE2000_PMEM_END) {
|
2005-11-15 23:16:05 +01:00
|
|
|
qemu_send_packet(s->vc, s->mem + index, s->tcnt);
|
2005-04-10 16:51:41 +02:00
|
|
|
}
|
2007-06-03 15:35:16 +02:00
|
|
|
/* signal end of transfer */
|
2004-03-14 13:20:30 +01:00
|
|
|
s->tsr = ENTSR_PTX;
|
|
|
|
s->isr |= ENISR_TX;
|
2007-09-16 23:08:06 +02:00
|
|
|
s->cmd &= ~E8390_TRANS;
|
2004-03-14 13:20:30 +01:00
|
|
|
ne2000_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
page = s->cmd >> 6;
|
|
|
|
offset = addr | (page << 4);
|
|
|
|
switch(offset) {
|
|
|
|
case EN0_STARTPG:
|
|
|
|
s->start = val << 8;
|
|
|
|
break;
|
|
|
|
case EN0_STOPPG:
|
|
|
|
s->stop = val << 8;
|
|
|
|
break;
|
|
|
|
case EN0_BOUNDARY:
|
|
|
|
s->boundary = val;
|
|
|
|
break;
|
|
|
|
case EN0_IMR:
|
|
|
|
s->imr = val;
|
|
|
|
ne2000_update_irq(s);
|
|
|
|
break;
|
|
|
|
case EN0_TPSR:
|
|
|
|
s->tpsr = val;
|
|
|
|
break;
|
|
|
|
case EN0_TCNTLO:
|
|
|
|
s->tcnt = (s->tcnt & 0xff00) | val;
|
|
|
|
break;
|
|
|
|
case EN0_TCNTHI:
|
|
|
|
s->tcnt = (s->tcnt & 0x00ff) | (val << 8);
|
|
|
|
break;
|
|
|
|
case EN0_RSARLO:
|
|
|
|
s->rsar = (s->rsar & 0xff00) | val;
|
|
|
|
break;
|
|
|
|
case EN0_RSARHI:
|
|
|
|
s->rsar = (s->rsar & 0x00ff) | (val << 8);
|
|
|
|
break;
|
|
|
|
case EN0_RCNTLO:
|
|
|
|
s->rcnt = (s->rcnt & 0xff00) | val;
|
|
|
|
break;
|
|
|
|
case EN0_RCNTHI:
|
|
|
|
s->rcnt = (s->rcnt & 0x00ff) | (val << 8);
|
|
|
|
break;
|
2005-11-15 23:16:05 +01:00
|
|
|
case EN0_RXCR:
|
|
|
|
s->rxcr = val;
|
|
|
|
break;
|
2004-03-14 13:20:30 +01:00
|
|
|
case EN0_DCFG:
|
|
|
|
s->dcfg = val;
|
|
|
|
break;
|
|
|
|
case EN0_ISR:
|
2004-04-22 01:29:33 +02:00
|
|
|
s->isr &= ~(val & 0x7f);
|
2004-03-14 13:20:30 +01:00
|
|
|
ne2000_update_irq(s);
|
|
|
|
break;
|
|
|
|
case EN1_PHYS ... EN1_PHYS + 5:
|
|
|
|
s->phys[offset - EN1_PHYS] = val;
|
|
|
|
break;
|
|
|
|
case EN1_CURPAG:
|
|
|
|
s->curpag = val;
|
|
|
|
break;
|
|
|
|
case EN1_MULT ... EN1_MULT + 7:
|
|
|
|
s->mult[offset - EN1_MULT] = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
int offset, page, ret;
|
|
|
|
|
|
|
|
addr &= 0xf;
|
|
|
|
if (addr == E8390_CMD) {
|
|
|
|
ret = s->cmd;
|
|
|
|
} else {
|
|
|
|
page = s->cmd >> 6;
|
|
|
|
offset = addr | (page << 4);
|
|
|
|
switch(offset) {
|
|
|
|
case EN0_TSR:
|
|
|
|
ret = s->tsr;
|
|
|
|
break;
|
|
|
|
case EN0_BOUNDARY:
|
|
|
|
ret = s->boundary;
|
|
|
|
break;
|
|
|
|
case EN0_ISR:
|
|
|
|
ret = s->isr;
|
|
|
|
break;
|
2004-04-22 01:29:33 +02:00
|
|
|
case EN0_RSARLO:
|
|
|
|
ret = s->rsar & 0x00ff;
|
|
|
|
break;
|
|
|
|
case EN0_RSARHI:
|
|
|
|
ret = s->rsar >> 8;
|
|
|
|
break;
|
2004-03-14 13:20:30 +01:00
|
|
|
case EN1_PHYS ... EN1_PHYS + 5:
|
|
|
|
ret = s->phys[offset - EN1_PHYS];
|
|
|
|
break;
|
|
|
|
case EN1_CURPAG:
|
|
|
|
ret = s->curpag;
|
|
|
|
break;
|
|
|
|
case EN1_MULT ... EN1_MULT + 7:
|
|
|
|
ret = s->mult[offset - EN1_MULT];
|
|
|
|
break;
|
2004-05-22 18:52:29 +02:00
|
|
|
case EN0_RSR:
|
|
|
|
ret = s->rsr;
|
|
|
|
break;
|
2005-04-28 21:45:10 +02:00
|
|
|
case EN2_STARTPG:
|
|
|
|
ret = s->start >> 8;
|
|
|
|
break;
|
|
|
|
case EN2_STOPPG:
|
|
|
|
ret = s->stop >> 8;
|
|
|
|
break;
|
2005-11-22 21:16:13 +01:00
|
|
|
case EN0_RTL8029ID0:
|
|
|
|
ret = 0x50;
|
|
|
|
break;
|
|
|
|
case EN0_RTL8029ID1:
|
|
|
|
ret = 0x43;
|
|
|
|
break;
|
|
|
|
case EN3_CONFIG0:
|
|
|
|
ret = 0; /* 10baseT media */
|
|
|
|
break;
|
|
|
|
case EN3_CONFIG2:
|
|
|
|
ret = 0x40; /* 10baseT active */
|
|
|
|
break;
|
|
|
|
case EN3_CONFIG3:
|
|
|
|
ret = 0x40; /* Full duplex */
|
|
|
|
break;
|
2004-03-14 13:20:30 +01:00
|
|
|
default:
|
|
|
|
ret = 0x00;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: read addr=0x%x val=%02x\n", addr, ret);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
static inline void ne2000_mem_writeb(NE2000State *s, uint32_t addr,
|
2004-05-19 01:05:28 +02:00
|
|
|
uint32_t val)
|
2004-04-22 01:29:33 +02:00
|
|
|
{
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-04-22 01:29:33 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
|
|
|
s->mem[addr] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr,
|
2004-04-22 01:29:33 +02:00
|
|
|
uint32_t val)
|
|
|
|
{
|
|
|
|
addr &= ~1; /* XXX: check exact behaviour if not even */
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-04-22 01:29:33 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
2004-05-19 01:05:28 +02:00
|
|
|
*(uint16_t *)(s->mem + addr) = cpu_to_le16(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
|
2004-05-19 01:05:28 +02:00
|
|
|
uint32_t val)
|
|
|
|
{
|
2004-06-07 22:45:42 +02:00
|
|
|
addr &= ~1; /* XXX: check exact behaviour if not even */
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-05-19 01:05:28 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
2004-06-07 22:45:42 +02:00
|
|
|
cpu_to_le32wu((uint32_t *)(s->mem + addr), val);
|
2004-04-22 01:29:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr)
|
|
|
|
{
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-04-22 01:29:33 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
|
|
|
return s->mem[addr];
|
|
|
|
} else {
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
|
|
|
|
{
|
|
|
|
addr &= ~1; /* XXX: check exact behaviour if not even */
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-04-22 01:29:33 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
2004-05-19 01:05:28 +02:00
|
|
|
return le16_to_cpu(*(uint16_t *)(s->mem + addr));
|
2004-04-22 01:29:33 +02:00
|
|
|
} else {
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-19 01:05:28 +02:00
|
|
|
static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
|
|
|
|
{
|
2004-06-07 22:45:42 +02:00
|
|
|
addr &= ~1; /* XXX: check exact behaviour if not even */
|
2007-09-16 23:08:06 +02:00
|
|
|
if (addr < 32 ||
|
2004-05-19 01:05:28 +02:00
|
|
|
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
2004-06-07 22:45:42 +02:00
|
|
|
return le32_to_cpupu((uint32_t *)(s->mem + addr));
|
2004-05-19 01:05:28 +02:00
|
|
|
} else {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-10 16:45:19 +02:00
|
|
|
static inline void ne2000_dma_update(NE2000State *s, int len)
|
|
|
|
{
|
|
|
|
s->rsar += len;
|
|
|
|
/* wrap */
|
|
|
|
/* XXX: check what to do if rsar > stop */
|
|
|
|
if (s->rsar == s->stop)
|
|
|
|
s->rsar = s->start;
|
|
|
|
|
|
|
|
if (s->rcnt <= len) {
|
|
|
|
s->rcnt = 0;
|
2007-06-03 15:35:16 +02:00
|
|
|
/* signal end of transfer */
|
2004-07-10 16:45:19 +02:00
|
|
|
s->isr |= ENISR_RDC;
|
|
|
|
ne2000_update_irq(s);
|
|
|
|
} else {
|
|
|
|
s->rcnt -= len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: asic write val=0x%04x\n", val);
|
|
|
|
#endif
|
2004-04-22 01:29:33 +02:00
|
|
|
if (s->rcnt == 0)
|
2004-07-10 16:45:19 +02:00
|
|
|
return;
|
2004-03-14 13:20:30 +01:00
|
|
|
if (s->dcfg & 0x01) {
|
|
|
|
/* 16 bit access */
|
2004-04-22 01:29:33 +02:00
|
|
|
ne2000_mem_writew(s, s->rsar, val);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 2);
|
2004-03-14 13:20:30 +01:00
|
|
|
} else {
|
|
|
|
/* 8 bit access */
|
2004-04-22 01:29:33 +02:00
|
|
|
ne2000_mem_writeb(s, s->rsar, val);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 1);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (s->dcfg & 0x01) {
|
|
|
|
/* 16 bit access */
|
2004-04-22 01:29:33 +02:00
|
|
|
ret = ne2000_mem_readw(s, s->rsar);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 2);
|
2004-03-14 13:20:30 +01:00
|
|
|
} else {
|
|
|
|
/* 8 bit access */
|
2004-04-22 01:29:33 +02:00
|
|
|
ret = ne2000_mem_readb(s, s->rsar);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 1);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: asic read val=0x%04x\n", ret);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-05-19 01:05:28 +02:00
|
|
|
static void ne2000_asic_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
NE2000State *s = opaque;
|
|
|
|
|
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: asic writel val=0x%04x\n", val);
|
|
|
|
#endif
|
|
|
|
if (s->rcnt == 0)
|
2004-07-10 16:45:19 +02:00
|
|
|
return;
|
2004-05-19 01:05:28 +02:00
|
|
|
/* 32 bit access */
|
|
|
|
ne2000_mem_writel(s, s->rsar, val);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 4);
|
2004-05-19 01:05:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
NE2000State *s = opaque;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* 32 bit access */
|
|
|
|
ret = ne2000_mem_readl(s, s->rsar);
|
2004-07-10 16:45:19 +02:00
|
|
|
ne2000_dma_update(s, 4);
|
2004-05-19 01:05:28 +02:00
|
|
|
#ifdef DEBUG_NE2000
|
|
|
|
printf("NE2000: asic readl val=0x%04x\n", ret);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
|
|
|
/* nothing to do (end of reset pulse) */
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
static uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s = opaque;
|
2004-03-14 13:20:30 +01:00
|
|
|
ne2000_reset(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-10-03 15:56:00 +02:00
|
|
|
static void ne2000_save(QEMUFile* f,void* opaque)
|
|
|
|
{
|
|
|
|
NE2000State* s=(NE2000State*)opaque;
|
2007-12-16 04:02:09 +01:00
|
|
|
uint32_t tmp;
|
2004-10-03 15:56:00 +02:00
|
|
|
|
2006-08-17 12:46:34 +02:00
|
|
|
if (s->pci_dev)
|
|
|
|
pci_device_save(s->pci_dev, f);
|
|
|
|
|
2006-02-01 22:40:18 +01:00
|
|
|
qemu_put_8s(f, &s->rxcr);
|
|
|
|
|
2004-10-03 15:56:00 +02:00
|
|
|
qemu_put_8s(f, &s->cmd);
|
|
|
|
qemu_put_be32s(f, &s->start);
|
|
|
|
qemu_put_be32s(f, &s->stop);
|
|
|
|
qemu_put_8s(f, &s->boundary);
|
|
|
|
qemu_put_8s(f, &s->tsr);
|
|
|
|
qemu_put_8s(f, &s->tpsr);
|
|
|
|
qemu_put_be16s(f, &s->tcnt);
|
|
|
|
qemu_put_be16s(f, &s->rcnt);
|
|
|
|
qemu_put_be32s(f, &s->rsar);
|
|
|
|
qemu_put_8s(f, &s->rsr);
|
|
|
|
qemu_put_8s(f, &s->isr);
|
|
|
|
qemu_put_8s(f, &s->dcfg);
|
|
|
|
qemu_put_8s(f, &s->imr);
|
|
|
|
qemu_put_buffer(f, s->phys, 6);
|
|
|
|
qemu_put_8s(f, &s->curpag);
|
|
|
|
qemu_put_buffer(f, s->mult, 8);
|
2007-04-07 20:14:41 +02:00
|
|
|
tmp = 0;
|
|
|
|
qemu_put_be32s(f, &tmp); /* ignored, was irq */
|
2004-10-03 15:56:00 +02:00
|
|
|
qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ne2000_load(QEMUFile* f,void* opaque,int version_id)
|
|
|
|
{
|
|
|
|
NE2000State* s=(NE2000State*)opaque;
|
2006-08-17 12:46:34 +02:00
|
|
|
int ret;
|
2007-12-16 04:02:09 +01:00
|
|
|
uint32_t tmp;
|
2006-08-17 12:46:34 +02:00
|
|
|
|
|
|
|
if (version_id > 3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (s->pci_dev && version_id >= 3) {
|
|
|
|
ret = pci_device_load(s->pci_dev, f);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2004-10-03 15:56:00 +02:00
|
|
|
|
2006-08-17 12:46:34 +02:00
|
|
|
if (version_id >= 2) {
|
2006-02-01 22:40:18 +01:00
|
|
|
qemu_get_8s(f, &s->rxcr);
|
|
|
|
} else {
|
2006-08-17 12:46:34 +02:00
|
|
|
s->rxcr = 0x0c;
|
2006-02-01 22:40:18 +01:00
|
|
|
}
|
2004-10-03 15:56:00 +02:00
|
|
|
|
|
|
|
qemu_get_8s(f, &s->cmd);
|
|
|
|
qemu_get_be32s(f, &s->start);
|
|
|
|
qemu_get_be32s(f, &s->stop);
|
|
|
|
qemu_get_8s(f, &s->boundary);
|
|
|
|
qemu_get_8s(f, &s->tsr);
|
|
|
|
qemu_get_8s(f, &s->tpsr);
|
|
|
|
qemu_get_be16s(f, &s->tcnt);
|
|
|
|
qemu_get_be16s(f, &s->rcnt);
|
|
|
|
qemu_get_be32s(f, &s->rsar);
|
|
|
|
qemu_get_8s(f, &s->rsr);
|
|
|
|
qemu_get_8s(f, &s->isr);
|
|
|
|
qemu_get_8s(f, &s->dcfg);
|
|
|
|
qemu_get_8s(f, &s->imr);
|
|
|
|
qemu_get_buffer(f, s->phys, 6);
|
|
|
|
qemu_get_8s(f, &s->curpag);
|
|
|
|
qemu_get_buffer(f, s->mult, 8);
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_get_be32s(f, &tmp); /* ignored */
|
2004-10-03 15:56:00 +02:00
|
|
|
qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:11:08 +02:00
|
|
|
static void isa_ne2000_cleanup(VLANClientState *vc)
|
|
|
|
{
|
|
|
|
NE2000State *s = vc->opaque;
|
|
|
|
|
|
|
|
unregister_savevm("ne2000", s);
|
|
|
|
|
|
|
|
isa_unassign_ioport(s->isa_io_base, 16);
|
|
|
|
isa_unassign_ioport(s->isa_io_base + 0x10, 2);
|
|
|
|
isa_unassign_ioport(s->isa_io_base + 0x1f, 1);
|
|
|
|
|
|
|
|
qemu_free(s);
|
|
|
|
}
|
|
|
|
|
2007-04-07 20:14:41 +02:00
|
|
|
void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
|
2004-03-14 13:20:30 +01:00
|
|
|
{
|
2004-03-14 22:46:48 +01:00
|
|
|
NE2000State *s;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2009-01-13 20:39:36 +01:00
|
|
|
qemu_check_nic_model(nd, "ne2k_isa");
|
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
s = qemu_mallocz(sizeof(NE2000State));
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
register_ioport_write(base, 16, 1, ne2000_ioport_write, s);
|
|
|
|
register_ioport_read(base, 16, 1, ne2000_ioport_read, s);
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
register_ioport_write(base + 0x10, 1, 1, ne2000_asic_ioport_write, s);
|
|
|
|
register_ioport_read(base + 0x10, 1, 1, ne2000_asic_ioport_read, s);
|
|
|
|
register_ioport_write(base + 0x10, 2, 2, ne2000_asic_ioport_write, s);
|
|
|
|
register_ioport_read(base + 0x10, 2, 2, ne2000_asic_ioport_read, s);
|
2004-03-14 13:20:30 +01:00
|
|
|
|
2004-03-14 22:46:48 +01:00
|
|
|
register_ioport_write(base + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
|
|
|
|
register_ioport_read(base + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
|
2009-04-17 19:11:08 +02:00
|
|
|
s->isa_io_base = base;
|
2004-03-14 13:20:30 +01:00
|
|
|
s->irq = irq;
|
2005-11-15 23:16:05 +01:00
|
|
|
memcpy(s->macaddr, nd->macaddr, 6);
|
2004-03-14 13:20:30 +01:00
|
|
|
|
|
|
|
ne2000_reset(s);
|
2004-03-14 22:46:48 +01:00
|
|
|
|
2009-01-07 18:48:51 +01:00
|
|
|
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
|
2009-04-17 19:11:08 +02:00
|
|
|
ne2000_receive, ne2000_can_receive,
|
|
|
|
isa_ne2000_cleanup, s);
|
2005-11-15 23:16:05 +01:00
|
|
|
|
2009-01-07 18:46:21 +01:00
|
|
|
qemu_format_nic_info_str(s->vc, s->macaddr);
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2008-07-18 20:02:34 +02:00
|
|
|
register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
|
2004-03-14 13:20:30 +01:00
|
|
|
}
|
2004-05-19 01:05:28 +02:00
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
/* PCI NE2000 definitions */
|
|
|
|
|
|
|
|
typedef struct PCINE2000State {
|
|
|
|
PCIDevice dev;
|
|
|
|
NE2000State ne2000;
|
|
|
|
} PCINE2000State;
|
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
static void ne2000_map(PCIDevice *pci_dev, int region_num,
|
2004-05-19 01:05:28 +02:00
|
|
|
uint32_t addr, uint32_t size, int type)
|
|
|
|
{
|
|
|
|
PCINE2000State *d = (PCINE2000State *)pci_dev;
|
|
|
|
NE2000State *s = &d->ne2000;
|
|
|
|
|
|
|
|
register_ioport_write(addr, 16, 1, ne2000_ioport_write, s);
|
|
|
|
register_ioport_read(addr, 16, 1, ne2000_ioport_read, s);
|
|
|
|
|
|
|
|
register_ioport_write(addr + 0x10, 1, 1, ne2000_asic_ioport_write, s);
|
|
|
|
register_ioport_read(addr + 0x10, 1, 1, ne2000_asic_ioport_read, s);
|
|
|
|
register_ioport_write(addr + 0x10, 2, 2, ne2000_asic_ioport_write, s);
|
|
|
|
register_ioport_read(addr + 0x10, 2, 2, ne2000_asic_ioport_read, s);
|
|
|
|
register_ioport_write(addr + 0x10, 4, 4, ne2000_asic_ioport_writel, s);
|
|
|
|
register_ioport_read(addr + 0x10, 4, 4, ne2000_asic_ioport_readl, s);
|
|
|
|
|
|
|
|
register_ioport_write(addr + 0x1f, 1, 1, ne2000_reset_ioport_write, s);
|
|
|
|
register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
|
|
|
|
}
|
|
|
|
|
2009-04-17 19:11:08 +02:00
|
|
|
static void ne2000_cleanup(VLANClientState *vc)
|
|
|
|
{
|
|
|
|
NE2000State *s = vc->opaque;
|
|
|
|
|
|
|
|
unregister_savevm("ne2000", s);
|
|
|
|
}
|
|
|
|
|
2009-05-14 23:35:07 +02:00
|
|
|
static void pci_ne2000_init(PCIDevice *pci_dev)
|
2004-05-19 01:05:28 +02:00
|
|
|
{
|
2009-05-14 23:35:07 +02:00
|
|
|
PCINE2000State *d = (PCINE2000State *)pci_dev;
|
2004-05-19 01:05:28 +02:00
|
|
|
NE2000State *s;
|
|
|
|
uint8_t *pci_conf;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-05-19 01:05:28 +02:00
|
|
|
pci_conf = d->dev.config;
|
2009-01-26 16:37:35 +01:00
|
|
|
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
|
2009-03-13 16:02:23 +01:00
|
|
|
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029);
|
2009-02-01 20:26:20 +01:00
|
|
|
pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
|
2009-05-03 21:03:00 +02:00
|
|
|
pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
2004-05-20 14:43:25 +02:00
|
|
|
pci_conf[0x3d] = 1; // interrupt pin 0
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2007-09-16 23:08:06 +02:00
|
|
|
pci_register_io_region(&d->dev, 0, 0x100,
|
2004-05-19 01:05:28 +02:00
|
|
|
PCI_ADDRESS_SPACE_IO, ne2000_map);
|
|
|
|
s = &d->ne2000;
|
2007-04-07 20:14:41 +02:00
|
|
|
s->irq = d->dev.irq[0];
|
2004-05-20 14:43:25 +02:00
|
|
|
s->pci_dev = (PCIDevice *)d;
|
2009-05-14 23:35:07 +02:00
|
|
|
qdev_get_macaddr(&d->dev.qdev, s->macaddr);
|
2004-05-19 01:05:28 +02:00
|
|
|
ne2000_reset(s);
|
2009-05-14 23:35:07 +02:00
|
|
|
s->vc = qdev_get_vlan_client(&d->dev.qdev,
|
2009-04-17 19:11:08 +02:00
|
|
|
ne2000_receive, ne2000_can_receive,
|
|
|
|
ne2000_cleanup, s);
|
2005-11-15 23:16:05 +01:00
|
|
|
|
2009-01-07 18:46:21 +01:00
|
|
|
qemu_format_nic_info_str(s->vc, s->macaddr);
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2008-07-18 20:02:34 +02:00
|
|
|
register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
2009-02-11 16:19:52 +01:00
|
|
|
|
2009-05-14 23:35:07 +02:00
|
|
|
static void ne2000_register_devices(void)
|
|
|
|
{
|
|
|
|
pci_qdev_register("ne2k_pci", sizeof(PCINE2000State), pci_ne2000_init);
|
2004-05-19 01:05:28 +02:00
|
|
|
}
|
2009-05-14 23:35:07 +02:00
|
|
|
|
|
|
|
device_init(ne2000_register_devices)
|