Received: from eggs.gnu.org ([140.186.70.92]:59817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyZFd-0008Br-Hq for qemu-devel@nongnu.org; Tue, 30 Aug 2011 21:05:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QyZFa-0003Vq-T9 for qemu-devel@nongnu.org; Tue, 30 Aug 2011 21:05:57 -0400 Received: from nm18-vm1.bullet.mail.ukl.yahoo.com ([217.146.183.112]:36093) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1QyZFa-0003VV-1I for qemu-devel@nongnu.org; Tue, 30 Aug 2011 21:05:54 -0400 Message-ID: <1314752751.84463.YahooMailClassic@web27003.mail.ukl.yahoo.com> Date: Wed, 31 Aug 2011 02:05:51 +0100 (BST) From: bifferos MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] Add support for r6040 NIC List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org =0ASigned-off-by: Mark Kelly =0Adiff --git a/Makefile.ob= js b/Makefile.objs=0Aindex 6991a9f..7d87503 100644=0A--- a/Makefile.objs=0A= +++ b/Makefile.objs=0A@@ -240,6 +240,7 @@ hw-obj-$(CONFIG_PCNET_PCI) +=3D p= cnet-pci.o=0A hw-obj-$(CONFIG_PCNET_COMMON) +=3D pcnet.o=0A hw-obj-$(CONFIG= _E1000_PCI) +=3D e1000.o=0A hw-obj-$(CONFIG_RTL8139_PCI) +=3D rtl8139.o=0A+= hw-obj-$(CONFIG_R6040_PCI) +=3D r6040.o=0A =0A hw-obj-$(CONFIG_SMC91C111) += =3D smc91c111.o=0A hw-obj-$(CONFIG_LAN9118) +=3D lan9118.o=0Adiff --git a/d= efault-configs/pci.mak b/default-configs/pci.mak=0Aindex 22bd350..d2ea7a2 1= 00644=0A--- a/default-configs/pci.mak=0A+++ b/default-configs/pci.mak=0A@@ = -10,6 +10,7 @@ CONFIG_PCNET_PCI=3Dy=0A CONFIG_PCNET_COMMON=3Dy=0A CONFIG_LS= I_SCSI_PCI=3Dy=0A CONFIG_RTL8139_PCI=3Dy=0A+CONFIG_R6040_PCI=3Dy=0A CONFIG_= E1000_PCI=3Dy=0A CONFIG_IDE_CORE=3Dy=0A CONFIG_IDE_QDEV=3Dy=0Adiff --git a/= hw/pci.c b/hw/pci.c=0Aindex b904a4e..7e12935 100644=0A--- a/hw/pci.c=0A+++ = b/hw/pci.c=0A@@ -1527,6 +1527,7 @@ static const char * const pci_nic_models= [] =3D {=0A "rtl8139",=0A "e1000",=0A "pcnet",=0A+ "r6040",= =0A "virtio",=0A NULL=0A };=0A@@ -1539,6 +1540,7 @@ static const ch= ar * const pci_nic_names[] =3D {=0A "rtl8139",=0A "e1000",=0A "= pcnet",=0A+ "r6040",=0A "virtio-net-pci",=0A NULL=0A };=0Adiff -= -git a/hw/r6040.c b/hw/r6040.c=0Anew file mode 100644=0Aindex 0000000..8358= 7e7=0A--- /dev/null=0A+++ b/hw/r6040.c=0A@@ -0,0 +1,627 @@=0A+/*=0A+ Emul= ation of r6040 ethernet controller found in a number of SoCs.=0A+ Copyrig= ht (c) 2011 Mark Kelly, mark@bifferos.com=0A+=0A+ This has been written u= sing the R8610[1] and ip101a[2] datasheets.=0A+=0A+ ICs with the embedded= controller include R8610, R3210, AMRISC20000=0A+ and Vortex86SX=0A+=0A+ = The emulation seems good enough to fool Linux 2.6.37.6. It is=0A+ not = perfect, but has proven useful.=0A+=0A+ [1] http://www.sima.com.tw/downlo= ad/R8610_D06_20051003.pdf=0A+ [2] http://www.icplus.com.tw/pp-IP101A.html= =0A+ */=0A+=0A+#include "hw.h"=0A+#include "pci.h"=0A+#include "net.h"=0A+#= include "loader.h"=0A+#include "sysemu.h"=0A+#include "qemu-timer.h"=0A+=0A= +/* #define DEBUG_R6040 1 */=0A+=0A+=0A+#if defined DEBUG_R6040=0A+#define = DPRINTF(fmt, ...) \=0A+ do { fprintf(stderr, "R6040: " fmt, ## __VA_ARGS= __); } while (0)=0A+#else=0A+static inline GCC_FMT_ATTR(1, 2) int DPRINTF(c= onst char *fmt, ...)=0A+{=0A+ return 0;=0A+}=0A+#endif=0A+=0A+=0A+/* Cas= t in order of appearance. _W prevfix means it's used to index the=0A+ re= gister word array (RegsW)=0A+ */=0A+=0A+#define MPSCCR_W (0x88 / 2)= =0A+=0A+#define MAC0_W (0x68 / 2)=0A+#define MAC1_W (0x= 6a / 2)=0A+#define MAC2_W (0x6c / 2)=0A+=0A+=0A+#define RX_START_= LOW_W (0x34 / 2)=0A+#define RX_START_HIGH_W (0x38 / 2)=0A+#define TX_PKT= _COUNT_W (0x5a / 2)=0A+#define RX_PKT_COUNT_W (0x50 / 2)=0A+=0A+=0A+#de= fine MCR0_W (0x00 / 2)=0A+#define MCR1_W (0x04 / 2)=0A+= #define BIT_MRST (1 << 0)=0A+=0A+#define MTPR_W (0x14 / 2= )=0A+#define MRBSR_W (0x18 / 2)=0A+#define MISR_W (0x3c = / 2)=0A+#define MIER_W (0x40 / 2)=0A+=0A+#define MMDIO_W = (0x20 / 2)=0A+#define MDIO_READ_W (0x24 / 2)=0A+#define MDIO_WRITE_W = (0x28 / 2)=0A+=0A+#define MRCNT_W (0x50 / 2)=0A+#define MTCNT_= W (0x5c / 2)=0A+=0A+=0A+#define MDIO_WRITE 0x4000=0A+#define = MDIO_READ 0x2000=0A+=0A+=0A+typedef struct R6040State {=0A+ PCIDev= ice dev;=0A+ NICState *nic;=0A+ NICConf conf;=0A+=0A+ /* PHY relat= ed register sets */=0A+ uint16_t MID0[3];=0A+ uint16_t phy_regs[32];= =0A+ uint32_t phy_op_in_progress;=0A+=0A+ /* Primary IO address space= */=0A+ union {=0A+ uint8_t RegsB[0x100]; /* Byte access */=0A+= uint16_t RegsW[0x100/2]; /* word access */=0A+ uint32_t Reg= sL[0x100/4]; /* DWORD access */=0A+ };=0A+=0A+} R6040State;=0A+=0A+=0A+= /* some inlines to help access above structure */=0A+static inline uint32_t= TX_START(R6040State *s)=0A+{=0A+ uint32_t tmp =3D s->RegsW[0x2c/2];=0A+= return tmp | (s->RegsW[0x30/2] << 16);=0A+}=0A+=0A+static inline void T= X_START_SET(R6040State *s, uint32_t start)=0A+{=0A+ s->RegsW[0x2c/2] =3D= start & 0xffff;=0A+ s->RegsW[0x30/2] =3D (start >> 16) & 0xffff;=0A+}= =0A+=0A+static inline uint32_t RX_START(R6040State *s)=0A+{=0A+ uint32_t= tmp =3D s->RegsW[0x34/2];=0A+ return tmp | (s->RegsW[0x38/2] << 16);=0A= +}=0A+=0A+static inline void RX_START_SET(R6040State *s, uint32_t start)=0A= +{=0A+ s->RegsW[0x34/2] =3D start & 0xffff;=0A+ s->RegsW[0x38/2] =3D = (start >> 16) & 0xffff;=0A+}=0A+=0A+=0A+static void r6040_update_irq(R6040S= tate *s)=0A+{=0A+ uint16_t isr =3D s->RegsW[MISR_W] & s->RegsW[MIER_W];= =0A+=0A+ qemu_set_irq(s->dev.irq[0], isr ? 1 : 0);=0A+}=0A+=0A+=0A+/* Ma= rk auto-neg complete, NIC up. */=0A+static void PhysicalLinkUp(void *opaqu= e)=0A+{=0A+ R6040State *s =3D opaque;=0A+ s->phy_regs[1] |=3D (1 << 2= );=0A+}=0A+=0A+=0A+/* Transmit and receive descriptors are doubled up=0A+ = One is a subset of the other anyhow=0A+ */=0A+typedef struct descriptor {= =0A+ uint16_t DST;=0A+ uint16_t DLEN;=0A+ uint32_t DBP;=0A+ uin= t32_t DNX;=0A+ uint16_t HIDX;=0A+ uint16_t Reserved1;=0A+ uint16_t= Reserved2;=0A+} descriptor_t;=0A+=0A+=0A+/* Some debugging functions */=0A= +=0A+#ifdef DEBUG_R6040=0A+static void addr_dump16(const char *name, uint16= _t val)=0A+{=0A+ DPRINTF("%s: 0x%04x ", name, val);=0A+}=0A+=0A+static = void addr_dump32(const char *name, uint32_t val)=0A+{=0A+ DPRINTF("%s: 0= x%x ", name, val);=0A+}=0A+=0A+static void hex_dump(const uint8_t *data, u= int32_t len)=0A+{=0A+ uint8_t i;=0A+ DPRINTF("hex: ");=0A+ for (i = =3D 0; i < len; i++) {=0A+ fprintf(stderr, "%02x ", *data);=0A+ = if (i && !(i % 0x20)) {=0A+ fprintf(stderr, "\n");=0A+ = }=0A+ data++;=0A+ }=0A+ fprintf(stderr, "\n");=0A+}=0A+=0A+st= atic void desc_dump(descriptor_t *d, uint32_t addr)=0A+{=0A+ DPRINTF("\n= Dumping: 0x%x\n", addr);=0A+ addr_dump16("DST", d->DST);=0A+ addr_dum= p16("DLEN", d->DLEN);=0A+ addr_dump32("DBP", (unsigned long)d->DBP);=0A+= addr_dump32("DNX", (unsigned long)d->DNX);=0A+ addr_dump16("HIDX", d= ->HIDX);=0A+ printf("\n");=0A+}=0A+=0A+static void dump_phys_mem(uint32_= t addr, int len)=0A+{=0A+ uint8_t buffer[1024];=0A+ cpu_physical_memo= ry_read(addr, buffer, len);=0A+ hex_dump(buffer, len);=0A+}=0A+=0A+stati= c void dump_pci(uint8_t *pci_conf)=0A+{=0A+ uint32_t *p =3D (uint32_t *)= pci_conf;=0A+ int i =3D 0;=0A+ for (i =3D 0; i < 0x40; i +=3D 4) {=0A= + DPRINTF("Addr: 0x%08x, Data: 0x%08x\n", i, *p);=0A+ p++;= =0A+ }=0A+}=0A+#endif=0A+=0A+=0A+static const VMStateDescription vmstate= _r6040 =3D {=0A+ .name =3D "r6040",=0A+ .version_id =3D 3,=0A+ .mi= nimum_version_id =3D 2,=0A+ .minimum_version_id_old =3D 2,=0A+ .field= s =3D (VMStateField[]) {=0A+ VMSTATE_PCI_DEVICE(dev, R6040State),=0A= + VMSTATE_BUFFER(RegsB, R6040State),=0A+ VMSTATE_UINT16_ARRAY= (MID0, R6040State, 3),=0A+ VMSTATE_UINT16_ARRAY(phy_regs, R6040State= , 32),=0A+ VMSTATE_UINT32(phy_op_in_progress, R6040State),=0A+ = VMSTATE_MACADDR(conf.macaddr, R6040State),=0A+ VMSTATE_END_OF_LIST= ()=0A+ }=0A+};=0A+=0A+=0A+static int TryToSendOnePacket(void *opaque)=0A= +{=0A+ R6040State *s =3D opaque;=0A+ descriptor_t d;=0A+ uint8_t p= kt_buffer[2000];=0A+ uint32_t tocopy;=0A+=0A+ cpu_physical_memory_rea= d(TX_START(s), (uint8_t *)&d, sizeof(d));=0A+=0A+ if (d.DST & 0x8000) { = /* MAC owns it? */=0A+ tocopy =3D d.DLEN;=0A+ if (tocopy = > sizeof(pkt_buffer)) {=0A+ tocopy =3D sizeof(pkt_buffer);=0A+ = }=0A+ /* copy the packet to send it */=0A+ cpu_physical= _memory_read(d.DBP, pkt_buffer, tocopy);=0A+=0A+ qemu_send_packet(&s= ->nic->nc, pkt_buffer, tocopy);=0A+ s->RegsW[TX_PKT_COUNT_W]++;=0A+= =0A+ /* relinquish ownership, we're done with it */=0A+ d.DST= &=3D ~0x8000;=0A+=0A+ /* Copy the new version of the descriptor bac= k */=0A+ cpu_physical_memory_write(TX_START(s), (uint8_t *)&d, sizeo= f(d));=0A+=0A+ /* Advance to the next buffer if packet processed */= =0A+ TX_START_SET(s, d.DNX);=0A+=0A+ return 1;=0A+ }=0A+= =0A+ return 0;=0A+}=0A+=0A+=0A+static void r6040_transmit(void *opaque)= =0A+{=0A+ R6040State *s =3D opaque;=0A+ int count =3D 0;=0A+=0A+ w= hile (TryToSendOnePacket(s)) {=0A+ ++count;=0A+ }=0A+=0A+ if (= count) {=0A+ s->RegsW[MISR_W] |=3D 0x10;=0A+ r6040_update_irq= (s);=0A+ }=0A+}=0A+=0A+=0A+/* Whether to allow callback returning 1 for = yes, can receive */=0A+static int r6040_can_receive(VLANClientState *nc)=0A= +{=0A+ R6040State *s =3D DO_UPCAST(NICState, nc, nc)->opaque;=0A+ int= tmp =3D (s->RegsW[0] & (1 << 1)) ? 1 : 0;=0A+ return tmp;=0A+}=0A+=0A+= =0A+static int ReceiveOnePacket(void *opaque, const uint8_t *buf, size_t le= n)=0A+{=0A+ R6040State *s =3D opaque;=0A+ uint32_t tocopy =3D len+4; = /* include checksum */=0A+ descriptor_t d;=0A+=0A+ cpu_physical_memo= ry_read(RX_START(s), (uint8_t *)&d, sizeof(descriptor_t));=0A+ /*desc_du= mp(&d, 0);*/=0A+=0A+ if (d.DST & 0x8000) { /* MAC owned? */=0A+=0A+ = uint16_t max_buffer =3D s->RegsW[MRBSR_W] & 0x07fc;=0A+ if (to= copy > max_buffer) {=0A+ tocopy =3D max_buffer;=0A+ }=0A+= =0A+ cpu_physical_memory_write(d.DBP, buf, tocopy-4);=0A+=0A+ = /* indicate received OK */=0A+ d.DST |=3D (1 << 14);=0A+ d.D= LEN =3D tocopy;=0A+ /* relinquish ownership */=0A+ d.DST &=3D= ~0x8000;=0A+=0A+ /* Copy the descriptor back */=0A+ cpu_phys= ical_memory_write(RX_START(s), (uint8_t *)&d,=0A+ = sizeof(descriptor_t));=0A+=0A+ s->RegsW[RX_PKT_COUNT_W]++;= =0A+=0A+ s->RegsW[MISR_W] |=3D 1; /* received pkt interrupt */=0A+= =0A+ r6040_update_irq(s);=0A+=0A+ RX_START_SET(s, d.DNX); /*= advance */=0A+=0A+ return 0;=0A+ }=0A+ return -1;=0A+}=0A+=0A= +=0A+/* called on incoming packets */=0A+static ssize_t r6040_receive(VLANC= lientState *nc, const uint8_t *buf,=0A+ = size_t len)=0A+{=0A+ R6040State *s =3D DO_UPCAST(NICState, nc, nc)->= opaque;=0A+ DPRINTF("Received incoming packet of len %ld\n", len);=0A+= =0A+ if (0 =3D=3D ReceiveOnePacket(s, buf, len)) {=0A+ return len= ; /* copied OK */=0A+ }=0A+=0A+ return 0;=0A+}=0A+=0A+=0A+static voi= d r6040_cleanup(VLANClientState *vc)=0A+{=0A+ DPRINTF("r6040_cleanup\n")= ;=0A+}=0A+=0A+=0A+static inline int BIT_SET(uint16_t old, uint16_t new, uin= t16_t bit)=0A+{=0A+ uint16_t before =3D (old & (1 << bit));=0A+ uint1= 6_t after =3D (new & (1 << bit));=0A+ if (!before && after) {=0A+ = return 1;=0A+ }=0A+ return 0;=0A+}=0A+=0A+=0A+static void r6040_iopo= rt_writew(void *opaque, uint32_t addr, uint32_t val)=0A+{=0A+ R6040State= *s =3D opaque;=0A+ uint16_t old;=0A+ addr &=3D 0xff; /* get relati= ve to base address */=0A+ addr /=3D 2; /* Get the offset into the wor= d-array */=0A+ old =3D s->RegsW[addr]; /* store the old value for futu= re use */=0A+=0A+ switch (addr) {=0A+ case MCR0_W: /* 0x00 */=0A+ = if (BIT_SET(old, val, 12)) {=0A+ r6040_transmit(opaque);= =0A+ }=0A+ break;=0A+ case MCR1_W: /* 0x04 */=0A+ = if (val & BIT_MRST) { /* reset request incoming */=0A+ /* rese= t requested, complete it immediately, set this value to=0A+ d= efault */=0A+ val =3D 0x0010;=0A+ }=0A+ break;=0A+= case MTPR_W: /* TX command reg, 0x14 */=0A+ if (val & 1) {=0A+ = r6040_transmit(opaque);=0A+ val &=3D ~1;=0A+ }= =0A+ break;=0A+ case MMDIO_W: /* MDIO control, 0x20 */=0A+ = {=0A+ int phy_exists =3D ((val & 0x1f00) =3D=3D 0x100) ? 1 : 0= ;=0A+ uint16_t *phy =3D s->phy_regs;=0A+ phy +=3D (va= l & 0x1f);=0A+=0A+ if (val & (1 << 13)) { /* read data */=0A+= if (phy_exists) {=0A+ s->RegsW[MDIO_READ= _W] =3D *phy;=0A+ } else {=0A+ s->RegsW[M= DIO_READ_W] =3D 0xffff;=0A+ }=0A+ } else if (val = & (1 << 14)) { /* write data */=0A+ if (phy_exists) {=0A+ = *phy =3D s->RegsW[MDIO_WRITE_W];=0A+ }=0A+= }=0A+=0A+ /* Whether you request to read or write, b= oth bits go high while=0A+ the operation is in progress, e.g.= tell it to read, and the=0A+ write-in-progress flag also goe= s high */=0A+ val |=3D 0x6000; /* signal operation has started = */=0A+ s->phy_op_in_progress =3D 1;=0A+=0A+ break;=0A= + }=0A+ case MISR_W: /* interrupt status reg (read to clear), 0x= 3c */=0A+ return;=0A+=0A+ case MIER_W: /* interrupt enable regis= ter, 0x40 */=0A+ s->RegsW[MIER_W] =3D val;=0A+ r6040_update_i= rq(s);=0A+ return;=0A+=0A+ case MRCNT_W: /* 0x50 */=0A+ case= MTCNT_W: /* 0x5c */=0A+ return; /* Can't write to pkt count regi= sters, skip */=0A+=0A+ }=0A+ s->RegsW[addr] =3D val & 0xFFFF;=0A+}=0A= +=0A+=0A+=0A+static uint32_t r6040_ioport_readw(void *opaque, uint32_t addr= )=0A+{=0A+ R6040State *s =3D opaque;=0A+ addr &=3D 0xff; /* get rel= ative to base address */=0A+ addr /=3D 2; /* Get the offset into the = word-array */=0A+ uint32_t tmp =3D s->RegsW[addr]; /* get the value */= =0A+=0A+ switch (addr) {=0A+=0A+ case MMDIO_W: /* MDIO control, 0x20= */=0A+ {=0A+ /* Clear any in-progress MDIO activity for = the next read=0A+ This simulates the polling of the MDIO oper= ation status,=0A+ so the driver code always has to read the r= egister twice=0A+ before it thinks the operation is complete.= */=0A+ if (s->phy_op_in_progress) {=0A+ s->RegsW= [addr] &=3D ~0x6000;=0A+ s->phy_op_in_progress =3D 0;=0A+ = }=0A+ break;=0A+ }=0A+ case MISR_W: /* inter= rupt status reg (read to clear) 0x3c */=0A+ s->RegsW[addr] =3D 0;= =0A+ break;=0A+ case MIER_W: /* interrupt enable reg 0x40 */=0A+= break;=0A+ case MRCNT_W: /* 0x50 */=0A+ case MTCNT_W: /* 0x= 5c */=0A+ s->RegsW[addr] =3D 0; /* read to clear */=0A+ bre= ak;=0A+ default:=0A+ break;=0A+ }=0A+ return tmp;=0A+}=0A+= =0A+=0A+/* byte and long access are routed via the word operation handlers = */=0A+static void r6040_ioport_writeb(void *opaque, uint32_t addr, uint32_t= val)=0A+{=0A+ R6040State *s =3D opaque;=0A+ addr &=3D 0xFF;=0A+ v= al &=3D 0xFF;=0A+ uint16_t old =3D s->RegsW[addr/2]; /* get the current= value */=0A+ if (addr & 1) {=0A+ old &=3D 0xff;=0A+ old |= =3D (val << 8);=0A+ } else {=0A+ old &=3D 0xff00;=0A+ old = |=3D val;=0A+ }=0A+=0A+ r6040_ioport_writew(opaque, addr, old); /* c= all the word-based version */=0A+}=0A+=0A+static void r6040_ioport_writel(v= oid *opaque, uint32_t addr, uint32_t val)=0A+{=0A+ /* Set the low value = */=0A+ r6040_ioport_writew(opaque, addr, val & 0xffff);=0A+ /* Set th= e high value */=0A+ r6040_ioport_writew(opaque, addr+2, (val >> 16) & 0x= ffff);=0A+}=0A+=0A+static uint32_t r6040_ioport_readb(void *opaque, uint32_= t addr)=0A+{=0A+ uint32_t tmp =3D r6040_ioport_readw(opaque, addr & ~1);= =0A+ if (addr & 1) {=0A+ return (tmp & 0xff00) >> 8;=0A+ }=0A+= return tmp & 0xff;=0A+}=0A+=0A+static uint32_t r6040_ioport_readl(void = *opaque, uint32_t addr)=0A+{=0A+ uint32_t tmp =3D r6040_ioport_readw(opa= que, addr);=0A+ return tmp | (r6040_ioport_readw(opaque, addr+2) << 16);= =0A+}=0A+=0A+=0A+static void r6040_register_ioports(R6040State *s, pcibus_t= addr)=0A+{=0A+ register_ioport_write(addr, 0x100, 1, r6040_ioport_write= b, s);=0A+ register_ioport_read(addr, 0x100, 1, r6040_ioport_readb, s);= =0A+=0A+ register_ioport_write(addr, 0x100, 2, r6040_ioport_writew, s);= =0A+ register_ioport_read(addr, 0x100, 2, r6040_ioport_readw, s);=0A+= =0A+ register_ioport_write(addr, 0x100, 4, r6040_ioport_writel, s);=0A+ = register_ioport_read(addr, 0x100, 4, r6040_ioport_readl, s);=0A+}=0A+= =0A+=0A+static void r6040_map(PCIDevice *pci_dev, int region_num,=0A+ = pcibus_t addr, pcibus_t size, int type)=0A+{=0A+ R6040S= tate *s =3D DO_UPCAST(R6040State, dev, pci_dev);;=0A+=0A+ DPRINTF("## Ma= pping to address %lx\n", addr);=0A+ r6040_register_ioports(s, addr);=0A+= }=0A+=0A+=0A+static NetClientInfo net_r6040_info =3D {=0A+ .type =3D NET= _CLIENT_TYPE_NIC,=0A+ .size =3D sizeof(NICState),=0A+ .can_receive = =3D r6040_can_receive,=0A+ .receive =3D r6040_receive,=0A+ .cleanup = =3D r6040_cleanup,=0A+};=0A+=0A+=0A+static int r6040_init_pci(PCIDevice *de= v)=0A+{=0A+ QEMUTimer *timer;=0A+=0A+ R6040State *s =3D DO_UPCAST(R60= 40State, dev, dev);=0A+ uint8_t *pci_conf;=0A+=0A+ /* MAC PHYS status= change register. Linux driver expects something=0A+ sensible as def= ault and if not will try to set it */=0A+ s->RegsW[MPSCCR_W] =3D 0x9f07;= =0A+=0A+ /* Default value for maximum packet size */=0A+ s->RegsW[MRB= SR_W] =3D 0x600;=0A+=0A+ /* set the MAC, linux driver reads this when it= loads, it is=0A+ normally set by the BIOS, but obviously Qemu BIOS i= sn't going=0A+ to do that */=0A+ s->RegsW[MAC0_W] =3D 0x5452;=0A+ = s->RegsW[MAC1_W] =3D 0x1200;=0A+ s->RegsW[MAC2_W] =3D 0x5734;=0A+=0A+= /* Tell Qemu the same thing */=0A+ s->conf.macaddr.a[0] =3D s->RegsW= [MAC0_W] & 0xff;=0A+ s->conf.macaddr.a[1] =3D (s->RegsW[MAC0_W] >> 8) & = 0xff;=0A+ s->conf.macaddr.a[2] =3D s->RegsW[MAC1_W] & 0xff;=0A+ s->co= nf.macaddr.a[3] =3D (s->RegsW[MAC1_W] >> 8) & 0xff;=0A+ s->conf.macaddr.= a[4] =3D s->RegsW[MAC2_W] & 0xff;=0A+ s->conf.macaddr.a[5] =3D (s->RegsW= [MAC2_W] >> 8) & 0xff;=0A+=0A+ /* no commands running */=0A+ s->phy_o= p_in_progress =3D 0;=0A+=0A+ /* PHY auto-neg in progress */=0A+ s->ph= y_regs[1] =3D 0x786d & ~(1 << 2);=0A+ s->phy_regs[2] =3D 0x0243;=0A+ = s->phy_regs[3] =3D 0x0c54;=0A+=0A+ pci_conf =3D (uint8_t *)s->dev.config= ;=0A+=0A+ pci_conf[PCI_HEADER_TYPE] =3D PCI_HEADER_TYPE_NORMAL; /* heade= r_type */=0A+ pci_conf[PCI_INTERRUPT_LINE] =3D 0xa; /* interrupt lin= e */=0A+ pci_conf[PCI_INTERRUPT_PIN] =3D 1; /* interrupt pin 0 */= =0A+=0A+ pci_register_bar(&s->dev, 0, 0x100, PCI_BASE_ADDRESS_SPACE_IO, = r6040_map);=0A+=0A+ s->nic =3D qemu_new_nic(&net_r6040_info, &s->conf,= =0A+ dev->qdev.info->name, dev->qdev.id, s);=0A+= =0A+ qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);=0A+=0A+ = /* Simulate a delay of a couple of seconds for the link to come up.=0A+ = Not required for Linux but very handy for developing BIOS code.=0A+ = */=0A+ timer =3D qemu_new_timer_ns(vm_clock, PhysicalLinkUp, s);=0A+ = qemu_mod_timer(timer, qemu_get_clock_ms(vm_clock) + 1500000000);=0A+=0A+ = /* Register IO port access as well */=0A+ r6040_register_ioports(s, 0= xe800);=0A+=0A+ return 0;=0A+}=0A+=0A+=0A+static PCIDeviceInfo r6040_inf= o =3D {=0A+ .qdev.name =3D "r6040",=0A+ .qdev.size =3D sizeof(R6040St= ate),=0A+ .qdev.vmsd =3D &vmstate_r6040,=0A+ .init =3D r6040_in= it_pci,=0A+ .vendor_id =3D 0x17f3, /* RDC */=0A+ .device_id =3D 0x60= 40, /* r6040 nic */=0A+ .class_id =3D PCI_CLASS_NETWORK_ETHERNET,=0A= + .qdev.props =3D (Property[]) {=0A+ DEFINE_NIC_PROPERTIES(R6040S= tate, conf),=0A+ DEFINE_PROP_END_OF_LIST(),=0A+ }=0A+};=0A+=0A+= =0A+static void r6040_register(void)=0A+{=0A+ pci_qdev_register(&r6040_i= nfo);=0A+}=0A+=0A+=0A+device_init(r6040_register)=0A