Davicom DM9000 emulation
PATCH 1/1 Davicom DM9000 emulation
Hi,
Attached is a patch which provides Davicom DM9000E emulation support including the ability to compile in a pcap-style network trace of the device.
It is the first step along the way to getting a large number of Simtec Electronics boards emulated (ARM based) and also therefore a step towards other Samsung ARM9 SOC based systems. Future patches will bring in more devices, and also ARM920T support, leading to an S3C2410x emulation and then later S3C2440.
Regards,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
The Davicom DM9000 10/100 Ethernet controller.
This driver supplies an MMIO based DM9000 interface which can be instantiated in the emulation's memory map to provide an ethernet interface for ARM "local-bus" type systems.
Makefile.target | 3 hw/dm9000.c | 658 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dm9000.h | 28 ++ 3 files changed, 689 insertions(+)
=== modified file 'Makefile.target'
Makefile.target +3 -0
@@ -540,6 +540,9 @@ OBJS += rtl8139.o OBJS += e1000.o +# MMIO mapped network cards +OBJS += dm9000.o + ifeq ($(TARGET_BASE_ARCH), i386) # Hardware support OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
=== added file 'hw/dm9000.c'
dm9000.c +658 -0
658 lines not on this page · raw message
=== added file 'hw/dm9000.h'
dm9000.h +28 -0
@@ -0,0 +1,28 @@ +/* hw/dm9000.h +* +* DM9000 Ethernet interface +* +* Copyright 2006, 2008 Daniel Silverstone and Vincent Sanders +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; version 2 only. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#ifndef QEMU_HW_DM9000_H +#define QEMU_HW_DM9000_H + +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr,uint32_t addr_offset, +uint32_t data_offset,qemu_irq irq); + +#endif
Quoted 5 lines · Daniel Silverstone
Hi,
Attached is a patch which provides Davicom DM9000E emulation support including the ability to compile in a pcap-style network trace of the device.
Network dumping does not belong in device specific code. It should be a separate device that can be attached to the virtual network.
Quoted 1 line
+#define
DM9000_DBF(X...)if(0)fprintf(stderr, X)
This is wrong. Use do {} while(0)
Quoted 1 line
+/*
hw/dm9000.h
A new header file for one init function is excessive. dm9000_init should go in the same place as smc91c111_init.
Quoted 1 line
+OBJS += dm9000.o
Likewise, this should be the same as smc91c111.o.
Paul
Quoted 5 lines · Paul Brook
Quoted 3 lines
Attached is a patch which provides Davicom DM9000E emulation support including the ability to compile in a pcap-style network trace of the device.
Network dumping does not belong in device specific code. It should be a separate device that can be attached to the virtual network.
Accepted. I shall look into the plausiblity of providing such a device. For now, I've removed the dump code from the dm9000 driver
Quoted 2 lines
Quoted 1 line
+#define
DM9000_DBF(X...)if(0)fprintf(stderr, X)This is wrong. Use do {} while(0)
This means that the debug statements do not get compile-checked when debugging is disabled, which can lead to compile errors when debugging is turned on. I've wrapped both the enabled and disabled variants in do/while code so that they are guaranteed not to confuse condition ladders.
Quoted 3 lines
Quoted 1 line
+/*
hw/dm9000.hA new header file for one init function is excessive.
dm9000_initshould go in the same place assmc91c111_init.
Accepted, moved to hw/devices.h
Quoted 2 lines
Quoted 1 line
+OBJS += dm9000.o
Likewise, this should be the same as smc91c111.o.
Migrated into the TARGET_ARCH=arm section of Makefile.target although I'd like to suggest that eventually we would need a section which is enabled for all MMIO-type systems, since dm9000 chips could be used on MIPS, PPC etc which support MMIO.
Attached is the fixed patch with these changes.
Regards,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
The Davicom DM9000 10/100 Ethernet controller.
This driver supplies an MMIO based DM9000 interface which can be instantiated in the emulation's memory map to provide an ethernet interface for ARM "local-bus" type systems.
Makefile.target | 2 hw/devices.h | 4 hw/dm9000.c | 624 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 629 insertions(+), 1 deletion(-)
=== modified file 'Makefile.target'
Makefile.target +1 -1
@@ -599,7 +599,7 @@ ifeq ($(TARGET_BASE_ARCH), arm) OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o OBJS+= arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o -OBJS+= versatile_pci.o ptimer.o +OBJS+= versatile_pci.o ptimer.o dm9000.o OBJS+= realview_gic.o realview.o arm_sysctl.o mpcore.o OBJS+= armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o OBJS+= pl061.o
=== modified file 'hw/devices.h'
devices.h +4 -0
@@ -3,6 +3,10 @@/* Devices that have nowhere better to go. */ +/* dm9000.c */ +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr,uint32_t addr_offset, +uint32_t data_offset,qemu_irq irq); +/* smc91c111.c */ void smc91c111_init (NICInfo *,uint32_t ,qemu_irq );
=== added file 'hw/dm9000.c'
dm9000.c +624 -0
624 lines not on this page · raw message
Quoted 1 line · Daniel Silverstone
Attached is the fixed patch with these changes.
I have to apologise -- that patch lacked some semi-colons.
Also, it appears that some devices don't have the headers required for target_phys_addr_t included before they include devices.h so I had to use an #ifdef around the dm9000_init declaration. If this isn't right then I need to know what the right thing to include in such drivers is. It seems a bit unfortunate to force other drivers to include headers they were otherwise managing without.
Attached is what I hope to be my final attempt at this.
Regards,
D.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
The Davicom DM9000 10/100 Ethernet controller.
This driver supplies an MMIO based DM9000 interface which can be instantiated in the emulation's memory map to provide an ethernet interface for ARM "local-bus" type systems.
Makefile.target | 2 hw/devices.h | 4 hw/dm9000.c | 624 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 629 insertions(+), 1 deletion(-)
=== modified file 'Makefile.target'
Makefile.target +1 -1
@@ -599,7 +599,7 @@ ifeq ($(TARGET_BASE_ARCH), arm) OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o OBJS+= arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o -OBJS+= versatile_pci.o ptimer.o +OBJS+= versatile_pci.o ptimer.o dm9000.o OBJS+= realview_gic.o realview.o arm_sysctl.o mpcore.o OBJS+= armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o OBJS+= pl061.o
=== modified file 'hw/devices.h'
devices.h +7 -0
@@ -3,6 +3,13 @@/* Devices that have nowhere better to go. */ +/* dm9000.c */ +#ifdef NEED_CPU_H +/* This ifdef is present because target_phys_addr_t comes from cpu-defs.h */ +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr,uint32_t addr_offset, +uint32_t data_offset,qemu_irq irq); +#endif +/* smc91c111.c */ void smc91c111_init (NICInfo *,uint32_t ,qemu_irq );
=== added file 'hw/dm9000.c'
dm9000.c +624 -0
624 lines not on this page · raw message
Quoted 11 lines · Daniel Silverstone
Quoted 1 line · Daniel Silverstone
Attached is the fixed patch with these changes.
I have to apologise -- that patch lacked some semi-colons.
Also, it appears that some devices don't have the headers required for
target_phys_addr_tincluded before they includedevices.hso I had to use an #ifdef around thedm9000_initdeclaration. If this isn't right then I need to know what the right thing to include in such drivers is. It seems a bit unfortunate to force other drivers to include headers they were otherwise managing without.
Using target_phys_addr_t is a lie. Your device only implements 32 bits of address space.
Paul
Quoted 8 lines · Paul Brook
Quoted 6 lines
Also, it appears that some devices don't have the headers required for
target_phys_addr_tincluded before they includedevices.hso I had to use an #ifdef around thedm9000_initdeclaration. If this isn't right then I need to know what the right thing to include in such drivers is. It seems a bit unfortunate to force other drivers to include headers they were otherwise managing without.Using
target_phys_addr_tis a lie. Your device only implements 32 bits of address space.
The implementation only allows for the two registers to be up to a 32-bit address space apart, but it allows for the base of the device to be at any part of the target's physical address space. It's not unreasonable IMO. If you think it is, then I can reduce it to uint32_t but that loses semantic information regarding the base address (that it is physical).
Regards,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
Quoted 8 lines · Daniel Silverstone
Quoted 7 lines · Paul Brook
Quoted 6 lines
Also, it appears that some devices don't have the headers required for
target_phys_addr_tincluded before they includedevices.hso I had to use an #ifdef around thedm9000_initdeclaration. If this isn't right then I need to know what the right thing to include in such drivers is. It seems a bit unfortunate to force other drivers to include headers they were otherwise managing without.
Quoted 6 lines
Quoted 2 lines
Using
target_phys_addr_tis a lie. Your device only implements 32 bits of address space.The implementation only allows for the two registers to be up to a 32-bit address space apart, but it allows for the base of the device to be at any part of the target's physical address space.
No it doesn't.
+typedef struct {
+ uint32_t addr; /* address port */
[...]
+ state->addr = base_addr + addr_offset;
Will truncate the address to 32 bits.
On closer inspection I notice that the data member of the state structure is never used, and the device will respond to any accesses within the range you reserve, not just the data address.
Paul
Quoted 9 lines · Paul Brook
Quoted 3 lines
The implementation only allows for the two registers to be up to a 32-bit address space apart, but it allows for the base of the device to be at any part of the target's physical address space.
No it doesn't.
(quoted diff) +3
-0+typedef struct { + uint32_t addr; /* address port */ + state->addr = base_addr + addr_offset;Will truncate the address to 32 bits.
Argh, missed that bit when I changed it to target_phys_addr_t -- well spotted. I've fixed up addr and data to be in target_phys_addr_t which also appeals to my semantic sensibilities.
Quoted 2 lines
On closer inspection I notice that the data member of the state structure is never used,
It was intended for debug, I think I lost the debug at one point. I've reinstantated the debug which uses it. In theory I could predicate the presence in the struct on the debug macro if you feel it's worthwhile.
Quoted 2 lines
and the device will respond to any accesses within the range you
reserve, not just the data address.
This was intentional based on the physical implementation of the device.
The chip has a CMD/nDATA pin, which is typically attached to some address decode logic which results in CMD being high when the address port is selected, and low when it is not. Then access to the chip is predicated on the standard nCS type line.
Attached is a patch which correct the struct entries to be target_phys_addr_t and reinstates the debug on accesses to anywhere other than the address and data ports.
Thank you for taking the time to go through these patches. I am working on the others.
Regards,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
The Davicom DM9000 10/100 Ethernet controller.
This driver supplies an MMIO based DM9000 interface which can be instantiated in the emulation's memory map to provide an ethernet interface for ARM "local-bus" type systems.
Makefile.target | 2 hw/devices.h | 7 hw/dm9000.c | 631 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 639 insertions(+), 1 deletion(-)
=== modified file 'Makefile.target'
Makefile.target +1 -1
@@ -599,7 +599,7 @@ ifeq ($(TARGET_BASE_ARCH), arm) OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o OBJS+= arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o -OBJS+= versatile_pci.o ptimer.o +OBJS+= versatile_pci.o ptimer.o dm9000.o OBJS+= realview_gic.o realview.o arm_sysctl.o mpcore.o OBJS+= armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o OBJS+= pl061.o
=== modified file 'hw/devices.h'
devices.h +7 -0
@@ -3,6 +3,13 @@/* Devices that have nowhere better to go. */ +/* dm9000.c */ +#ifdef NEED_CPU_H +/* This ifdef is present because target_phys_addr_t comes from cpu-defs.h */ +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr,uint32_t addr_offset, +uint32_t data_offset,qemu_irq irq); +#endif +/* smc91c111.c */ void smc91c111_init (NICInfo *,uint32_t ,qemu_irq );
=== added file 'hw/dm9000.c'
dm9000.c +631 -0
631 lines not on this page · raw message
Quoted 3 lines · Daniel Silverstone
Attached is a patch which correct the struct entries to be
target_phys_addr_tand reinstates the debug on accesses to anywhere other than the address and data ports.
My list subscription appears to have faltered due to bouncing spam. Has anyone had a chance to look at the patch attached to the previous message? I really want to get one patch up-to-snuff, so that I can rework the other patches to match style etc.
Thanks,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.simtec.co.uk/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895