mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
hw/arm/allwinner-h3: add EMAC ethernet device
The Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC) which provides 10M/100M/1000M Ethernet connectivity. This commit adds support for the Allwinner EMAC from the Sun8i family (H2+, H3, A33, etc), including emulation for the following functionality: * DMA transfers * MII interface * Transmit CRC calculation Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-id: 20200311221854.30370-10-nieklinnenbank@gmail.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
committed by
Peter Maydell
parent
82e4838249
commit
29d08975d1
@@ -300,6 +300,7 @@ config ALLWINNER_A10
|
||||
config ALLWINNER_H3
|
||||
bool
|
||||
select ALLWINNER_A10_PIT
|
||||
select ALLWINNER_SUN8I_EMAC
|
||||
select SERIAL
|
||||
select ARM_TIMER
|
||||
select ARM_GIC
|
||||
|
||||
+15
-1
@@ -54,6 +54,7 @@ const hwaddr allwinner_h3_memmap[] = {
|
||||
[AW_H3_UART1] = 0x01c28400,
|
||||
[AW_H3_UART2] = 0x01c28800,
|
||||
[AW_H3_UART3] = 0x01c28c00,
|
||||
[AW_H3_EMAC] = 0x01c30000,
|
||||
[AW_H3_GIC_DIST] = 0x01c81000,
|
||||
[AW_H3_GIC_CPU] = 0x01c82000,
|
||||
[AW_H3_GIC_HYP] = 0x01c84000,
|
||||
@@ -106,7 +107,6 @@ struct AwH3Unimplemented {
|
||||
{ "twi1", 0x01c2b000, 1 * KiB },
|
||||
{ "twi2", 0x01c2b400, 1 * KiB },
|
||||
{ "scr", 0x01c2c400, 1 * KiB },
|
||||
{ "emac", 0x01c30000, 64 * KiB },
|
||||
{ "gpu", 0x01c40000, 64 * KiB },
|
||||
{ "hstmr", 0x01c60000, 4 * KiB },
|
||||
{ "dramcom", 0x01c62000, 4 * KiB },
|
||||
@@ -162,6 +162,7 @@ enum {
|
||||
AW_H3_GIC_SPI_OHCI2 = 77,
|
||||
AW_H3_GIC_SPI_EHCI3 = 78,
|
||||
AW_H3_GIC_SPI_OHCI3 = 79,
|
||||
AW_H3_GIC_SPI_EMAC = 82
|
||||
};
|
||||
|
||||
/* Allwinner H3 general constants */
|
||||
@@ -207,6 +208,9 @@ static void allwinner_h3_init(Object *obj)
|
||||
|
||||
sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
|
||||
TYPE_AW_SDHOST_SUN5I);
|
||||
|
||||
sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
|
||||
TYPE_AW_SUN8I_EMAC);
|
||||
}
|
||||
|
||||
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
|
||||
@@ -337,6 +341,16 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
|
||||
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
|
||||
"sd-bus", &error_abort);
|
||||
|
||||
/* EMAC */
|
||||
if (nd_table[0].used) {
|
||||
qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
|
||||
qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
|
||||
}
|
||||
qdev_init_nofail(DEVICE(&s->emac));
|
||||
sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_H3_EMAC]);
|
||||
sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
|
||||
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_EMAC));
|
||||
|
||||
/* Universal Serial Bus */
|
||||
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
|
||||
qdev_get_gpio_in(DEVICE(&s->gic),
|
||||
|
||||
@@ -77,6 +77,9 @@ static void orangepi_init(MachineState *machine)
|
||||
warn_report("Security Identifier value does not include H3 prefix");
|
||||
}
|
||||
|
||||
/* Setup EMAC properties */
|
||||
object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
|
||||
|
||||
/* Mark H3 object realized */
|
||||
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
|
||||
|
||||
|
||||
@@ -79,6 +79,9 @@ config MIPSNET
|
||||
config ALLWINNER_EMAC
|
||||
bool
|
||||
|
||||
config ALLWINNER_SUN8I_EMAC
|
||||
bool
|
||||
|
||||
config IMX_FEC
|
||||
bool
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ common-obj-$(CONFIG_XGMAC) += xgmac.o
|
||||
common-obj-$(CONFIG_MIPSNET) += mipsnet.o
|
||||
common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
|
||||
common-obj-$(CONFIG_ALLWINNER_EMAC) += allwinner_emac.o
|
||||
common-obj-$(CONFIG_ALLWINNER_SUN8I_EMAC) += allwinner-sun8i-emac.o
|
||||
common-obj-$(CONFIG_IMX_FEC) += imx_fec.o
|
||||
|
||||
common-obj-$(CONFIG_CADENCE) += cadence_gem.o
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,15 @@
|
||||
# See docs/devel/tracing.txt for syntax documentation.
|
||||
|
||||
# allwinner-sun8i-emac.c
|
||||
allwinner_sun8i_emac_mii_write_reg(uint32_t reg, uint32_t value) "MII write: reg=0x%" PRIx32 " value=0x%" PRIx32
|
||||
allwinner_sun8i_emac_mii_read_reg(uint32_t reg, uint32_t value) "MII read: reg=0x%" PRIx32 " value=0x%" PRIx32
|
||||
allwinner_sun8i_emac_receive(uint32_t desc, uint32_t paddr, uint32_t bytes) "RX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
|
||||
allwinner_sun8i_emac_transmit(uint32_t desc, uint32_t paddr, uint32_t bytes) "TX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
|
||||
allwinner_sun8i_emac_reset(void) "HW reset"
|
||||
allwinner_sun8i_emac_set_link(bool active) "Set link: active=%u"
|
||||
allwinner_sun8i_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64
|
||||
allwinner_sun8i_emac_write(uint64_t offset, uint64_t val) "MMIO write: offset=0x%" PRIx64 " value=0x%" PRIx64
|
||||
|
||||
# etraxfs_eth.c
|
||||
mdio_phy_read(int regnum, uint16_t value) "read phy_reg:%d value:0x%04x"
|
||||
mdio_phy_write(int regnum, uint16_t value) "write phy_reg:%d value:0x%04x"
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "hw/misc/allwinner-h3-sysctrl.h"
|
||||
#include "hw/misc/allwinner-sid.h"
|
||||
#include "hw/sd/allwinner-sdhost.h"
|
||||
#include "hw/net/allwinner-sun8i-emac.h"
|
||||
#include "target/arm/cpu.h"
|
||||
|
||||
/**
|
||||
@@ -77,6 +78,7 @@ enum {
|
||||
AW_H3_UART1,
|
||||
AW_H3_UART2,
|
||||
AW_H3_UART3,
|
||||
AW_H3_EMAC,
|
||||
AW_H3_GIC_DIST,
|
||||
AW_H3_GIC_CPU,
|
||||
AW_H3_GIC_HYP,
|
||||
@@ -120,6 +122,7 @@ typedef struct AwH3State {
|
||||
AwH3SysCtrlState sysctrl;
|
||||
AwSidState sid;
|
||||
AwSdHostState mmc0;
|
||||
AwSun8iEmacState emac;
|
||||
GICState gic;
|
||||
MemoryRegion sram_a1;
|
||||
MemoryRegion sram_a2;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Allwinner Sun8i Ethernet MAC emulation
|
||||
*
|
||||
* Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
|
||||
*
|
||||
* 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, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HW_NET_ALLWINNER_SUN8I_EMAC_H
|
||||
#define HW_NET_ALLWINNER_SUN8I_EMAC_H
|
||||
|
||||
#include "qom/object.h"
|
||||
#include "net/net.h"
|
||||
#include "hw/sysbus.h"
|
||||
|
||||
/**
|
||||
* Object model
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define TYPE_AW_SUN8I_EMAC "allwinner-sun8i-emac"
|
||||
#define AW_SUN8I_EMAC(obj) \
|
||||
OBJECT_CHECK(AwSun8iEmacState, (obj), TYPE_AW_SUN8I_EMAC)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Allwinner Sun8i EMAC object instance state
|
||||
*/
|
||||
typedef struct AwSun8iEmacState {
|
||||
/*< private >*/
|
||||
SysBusDevice parent_obj;
|
||||
/*< public >*/
|
||||
|
||||
/** Maps I/O registers in physical memory */
|
||||
MemoryRegion iomem;
|
||||
|
||||
/** Interrupt output signal to notify CPU */
|
||||
qemu_irq irq;
|
||||
|
||||
/** Generic Network Interface Controller (NIC) for networking API */
|
||||
NICState *nic;
|
||||
|
||||
/** Generic Network Interface Controller (NIC) configuration */
|
||||
NICConf conf;
|
||||
|
||||
/**
|
||||
* @name Media Independent Interface (MII)
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint8_t mii_phy_addr; /**< PHY address */
|
||||
uint32_t mii_cr; /**< Control */
|
||||
uint32_t mii_st; /**< Status */
|
||||
uint32_t mii_adv; /**< Advertised Abilities */
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Hardware Registers
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint32_t basic_ctl0; /**< Basic Control 0 */
|
||||
uint32_t basic_ctl1; /**< Basic Control 1 */
|
||||
uint32_t int_en; /**< Interrupt Enable */
|
||||
uint32_t int_sta; /**< Interrupt Status */
|
||||
uint32_t frm_flt; /**< Receive Frame Filter */
|
||||
|
||||
uint32_t rx_ctl0; /**< Receive Control 0 */
|
||||
uint32_t rx_ctl1; /**< Receive Control 1 */
|
||||
uint32_t rx_desc_head; /**< Receive Descriptor List Address */
|
||||
uint32_t rx_desc_curr; /**< Current Receive Descriptor Address */
|
||||
|
||||
uint32_t tx_ctl0; /**< Transmit Control 0 */
|
||||
uint32_t tx_ctl1; /**< Transmit Control 1 */
|
||||
uint32_t tx_desc_head; /**< Transmit Descriptor List Address */
|
||||
uint32_t tx_desc_curr; /**< Current Transmit Descriptor Address */
|
||||
uint32_t tx_flowctl; /**< Transmit Flow Control */
|
||||
|
||||
uint32_t mii_cmd; /**< Management Interface Command */
|
||||
uint32_t mii_data; /**< Management Interface Data */
|
||||
|
||||
/** @} */
|
||||
|
||||
} AwSun8iEmacState;
|
||||
|
||||
#endif /* HW_NET_ALLWINNER_SUN8I_H */
|
||||
Reference in New Issue
Block a user