Skip to contentSkip to conversation

FTGMAC100 model for the Aspeed SoCs

RFC PATCH In review Cédric Le Goater 2 participants 7 messages Nov 29, 2016 – Dec 16, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover FTGMAC100 model for the Aspeed SoCs

Hi,

The Aspeed SoCs AST2400 and AST2500 have two FTGMAC100 ethernet controllers. This serie proposes a model for this device and a way to customize the bit definitions which are slightly different from the Faraday definitions.

The last patch adds a fake NC-SI (Network Controller Sideband Interface) backend to pretend a NIC is being managed.

Thanks,

C.

Cédric Le Goater (4):
net: add FTGMAC100 support
net/ftgmac100: add a 'aspeed' property
aspeed: add a FTGMAC100 nic
slirp: add a fake NC-SI backend

 default-configs/arm-softmmu.mak |   1 +
 hw/arm/aspeed_soc.c             |  21 +
 hw/net/Makefile.objs            |   1 +
 hw/net/ftgmac100.c              | 866 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/aspeed_soc.h     |   2 +
 include/hw/net/ftgmac100.h      |  54 +++
 include/net/eth.h               |   1 +
 slirp/Makefile.objs             |   2 +-
 slirp/ncsi-pkt.h                | 418 +++++++++++++++++++
 slirp/ncsi.c                    |  78 ++++
 slirp/slirp.c                   |   4 +
 slirp/slirp.h                   |   3 +
 12 files changed, 1450 insertions(+), 1 deletion(-)
 create mode 100644 hw/net/ftgmac100.c
 create mode 100644 include/hw/net/ftgmac100.h
 create mode 100644 slirp/ncsi-pkt.h
 create mode 100644 slirp/ncsi.c
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH 1/4 net: add FTGMAC100 support

The FTGMAC100 device is an Ethernet controller configured and controlled via a set of registers available on AHB bus. Packets are transmitted and received using DMA ring buffers. There are a MAC and MII/GMII interfaces.

The model is for the moment complete enough to satisfy the Linux kernel but there are areas that need some more attention :

- PHY registers
- Automatic receive/transmit polling, no timers are used to poll the ring buffers descriptors. We just expect the qemu nic backend to push packets when they arrive.
- CRC

And some are still on the TODO list (not used today in the drivers) :

- Ethernet Address Filtering
- Multicast
- High priority queues
- VLAN
- NCSI, may be we could add n/w filters
- etc.

The code is based on the Coldfire Fast Ethernet Controller model.

---
 default-configs/arm-softmmu.mak |   1 +
 hw/net/Makefile.objs            |   1 +
 hw/net/ftgmac100.c              | 855 ++++++++++++++++++++++++++++++++++++++++
 include/hw/net/ftgmac100.h      |  51 +++
 4 files changed, 908 insertions(+)
 create mode 100644 hw/net/ftgmac100.c
 create mode 100644 include/hw/net/ftgmac100.h
default-configs/arm-softmmu.mak +1 -0
index 6de3e16a3e11..612f6e69f255 100644
@@ -28,6 +28,7 @@ CONFIG_LAN9118=y
 CONFIG_SMC91C111=y
 CONFIG_ALLWINNER_EMAC=y
 CONFIG_IMX_FEC=y
+CONFIG_FTGMAC100=y
 CONFIG_DS1338=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
hw/net/Makefile.objs +1 -0
index 610ed3e7ae64..7ca51d85a672 100644
@@ -26,6 +26,7 @@ common-obj-$(CONFIG_IMX_FEC) += imx_fec.o
 common-obj-$(CONFIG_CADENCE) += cadence_gem.o
 common-obj-$(CONFIG_STELLARIS_ENET) += stellaris_enet.o
 common-obj-$(CONFIG_LANCE) += lance.o
+common-obj-$(CONFIG_FTGMAC100) += ftgmac100.o
 
 obj-$(CONFIG_ETRAXFS) += etraxfs_eth.o
 obj-$(CONFIG_COLDFIRE) += mcf_fec.o
hw/net/ftgmac100.c new file +855 -0

855 lines not on this page · raw message

include/hw/net/ftgmac100.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

RFC PATCH 2/4 net/ftgmac100: add a 'aspeed' property

In reply to Cédric Le Goater

The Aspeed SoCs have a different definition of the end of the ring buffer bit. Add a property to specify which set of bits should be used by the NIC.

---
 hw/net/ftgmac100.c         | 19 +++++++++++++++----
 include/hw/net/ftgmac100.h |  3 +++
 2 files changed, 18 insertions(+), 4 deletions(-)
hw/net/ftgmac100.c +15 -4
index 4a7f865f226b..fceeffcb7a7f 100644
@@ -112,6 +112,7 @@ struct ftgmac100_txdes {
 #define FTGMAC100_TXDES0_CRC_ERR         (1 << 19)
 #define FTGMAC100_TXDES0_LTS             (1 << 28)
 #define FTGMAC100_TXDES0_FTS             (1 << 29)
+#define FTGMAC100_TXDES0_EDOTR_ASPEED    (1 << 30)
 #define FTGMAC100_TXDES0_TXDMA_OWN       (1 << 31)
 
 #define FTGMAC100_TXDES1_VLANTAG_CI(x)   ((x) & 0xffff)
@@ -147,6 +148,7 @@ struct ftgmac100_rxdes {
 #define FTGMAC100_RXDES0_PAUSE_FRAME     (1 << 25)
 #define FTGMAC100_RXDES0_LRS             (1 << 28)
 #define FTGMAC100_RXDES0_FRS             (1 << 29)
+#define FTGMAC100_RXDES0_EDORR_ASPEED    (1 << 30)
 #define FTGMAC100_RXDES0_RXPKT_RDY       (1 << 31)
 
 #define FTGMAC100_RXDES1_VLANTAG_CI      0xffff
@@ -373,7 +375,7 @@ static uint32_t ftgmac100_find_txdes(Ftgmac100State *s, uint32_t addr)
 
     while (1) {
         ftgmac100_read_bd(&bd, addr);
-        if (bd.des0 & (FTGMAC100_TXDES0_FTS | FTGMAC100_TXDES0_EDOTR)) {
+        if (bd.des0 & (FTGMAC100_TXDES0_FTS | s->txdes0_edotr)) {
             break;
         }
         addr += sizeof(Ftgmac100Desc);
@@ -427,7 +429,7 @@ static void ftgmac100_do_tx(Ftgmac100State *s)
         /* Write back the modified descriptor.  */
         ftgmac100_write_bd(&bd, addr);
         /* Advance to the next descriptor.  */
-        if (bd.des0 & FTGMAC100_TXDES0_EDOTR) {
+        if (bd.des0 & s->txdes0_edotr) {
             addr = s->tx_ring;
         } else {
             addr += sizeof(Ftgmac100Desc);
@@ -448,7 +450,7 @@ static void ftgmac100_enable_rx(Ftgmac100State *s)
     while (1) {
         ftgmac100_read_bd(&bd, s->rx_descriptor);
         full = (bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY);
-        if (!full || bd.des0 & FTGMAC100_TXDES0_EDOTR) {
+        if (!full || bd.des0 & s->txdes0_edotr) {
             break;
         }
         s->rx_descriptor += sizeof(Ftgmac100Desc);
@@ -739,7 +741,7 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
             s->isr |= FTGMAC100_INT_RPKT_FIFO;
         }
         ftgmac100_write_bd(&bd, addr);
-        if (bd.des0 & FTGMAC100_RXDES0_EDORR) {
+        if (bd.des0 & s->rxdes0_edorr) {
             addr = s->rx_ring;
         } else {
             addr += sizeof(Ftgmac100Desc);
@@ -781,6 +783,14 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
     Ftgmac100State *s = FTGMAC100(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
+    if (s->aspeed) {
+        s->txdes0_edotr = FTGMAC100_TXDES0_EDOTR_ASPEED;
+        s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR_ASPEED;
+    } else {
+        s->txdes0_edotr = FTGMAC100_TXDES0_EDOTR;
+        s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
+    }
+
     memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
                           TYPE_FTGMAC100, 0x2000);
     sysbus_init_mmio(sbd, &s->iomem);
@@ -824,6 +834,7 @@ static const VMStateDescription vmstate_ftgmac100 = {
 };
 
 static Property ftgmac100_properties[] = {
+    DEFINE_PROP_BOOL("aspeed", Ftgmac100State, aspeed, false),
     DEFINE_NIC_PROPERTIES(Ftgmac100State, conf),
     DEFINE_PROP_END_OF_LIST(),
 };
include/hw/net/ftgmac100.h +3 -0
index 1aa22de9e450..7476011f0657 100644
@@ -46,6 +46,9 @@ typedef struct Ftgmac100State {
     uint32_t phy_int;
     uint32_t phy_int_mask;
 
+    bool aspeed;
+    uint32_t txdes0_edotr;
+    uint32_t rxdes0_edorr;
 } Ftgmac100State;
 
 #endif
Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH 3/4 aspeed: add a FTGMAC100 nic

In reply to Cédric Le Goater

There is a second NIC but we do not use it for the moment. We use the 'aspeed' property to tune the definition of the end of ring buffer bit for the Aspeed SoCs.

---
 hw/arm/aspeed_soc.c         | 21 +++++++++++++++++++++
 include/hw/arm/aspeed_soc.h |  2 ++
 2 files changed, 23 insertions(+)
hw/arm/aspeed_soc.c +21 -0
index 712ae9d6c54d..af0964cf6add 100644
@@ -19,6 +19,7 @@
 #include "hw/char/serial.h"
 #include "qemu/log.h"
 #include "hw/i2c/aspeed_i2c.h"
+#include "net/net.h"
 
 #define ASPEED_SOC_UART_5_BASE      0x00184000
 #define ASPEED_SOC_IOMEM_SIZE       0x00200000
@@ -33,6 +34,8 @@
 #define ASPEED_SOC_TIMER_BASE       0x1E782000
 #define ASPEED_SOC_WDT_BASE         0x1E785000
 #define ASPEED_SOC_I2C_BASE         0x1E78A000
+#define ASPEED_SOC_ETH1_BASE        0x1E660000
+#define ASPEED_SOC_ETH2_BASE        0x1E680000
 
 static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
 static const int timer_irqs[] = { 16, 17, 18, 35, 36, 37, 38, 39, };
@@ -177,6 +180,10 @@ static void aspeed_soc_init(Object *obj)
     qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default());
     object_property_add_const_link(OBJECT(&s->wdt), "scu", OBJECT(&s->scu),
                                    NULL);
+
+    object_initialize(&s->ftgmac100, sizeof(s->ftgmac100), TYPE_FTGMAC100);
+    object_property_add_child(obj, "ftgmac100", OBJECT(&s->ftgmac100), NULL);
+    qdev_set_parent_bus(DEVICE(&s->ftgmac100), sysbus_get_default());
 }
 
 static void aspeed_soc_realize(DeviceState *dev, Error **errp)
@@ -304,6 +311,20 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt), 0, ASPEED_SOC_WDT_BASE);
+
+    /* Net */
+    qdev_set_nic_properties(DEVICE(&s->ftgmac100), &nd_table[0]);
+    object_property_set_bool(OBJECT(&s->ftgmac100), true, "aspeed", &err);
+    object_property_set_bool(OBJECT(&s->ftgmac100), true, "realized",
+                             &local_err);
+    error_propagate(&err, local_err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0, ASPEED_SOC_ETH1_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0,
+                       qdev_get_gpio_in(DEVICE(&s->vic), 2));
 }
 
 static void aspeed_soc_class_init(ObjectClass *oc, void *data)
include/hw/arm/aspeed_soc.h +2 -0
index dbec0c159885..1fd0dc690be1 100644
@@ -20,6 +20,7 @@
 #include "hw/i2c/aspeed_i2c.h"
 #include "hw/ssi/aspeed_smc.h"
 #include "hw/watchdog/wdt_aspeed.h"
+#include "hw/net/ftgmac100.h"
 
 #define ASPEED_SPIS_NUM  2
 
@@ -39,6 +40,7 @@ typedef struct AspeedSoCState {
     AspeedSMCState spi[ASPEED_SPIS_NUM];
     AspeedSDMCState sdmc;
     AspeedWDTState wdt;
+    Ftgmac100State ftgmac100;
 } AspeedSoCState;
 
 #define TYPE_ASPEED_SOC "aspeed-soc"
Signature · 1 line
2.7.4
#4 lore raw

RFC PATCH 4/4 slirp: add a fake NC-SI backend

In reply to Cédric Le Goater

NC-SI (Network Controller Sideband Interface) enables a BMC to manage a set of NICs on a system. This model takes the simplest approach and reverses the NC-SI packets to pretend a NIC is present and exercise the Linux driver.

The NCSI header file <ncsi-pkt.h> comes from mainline Linux and was untabified.

---
 include/net/eth.h   |   1 +
 slirp/Makefile.objs |   2 +-
 slirp/ncsi-pkt.h    | 418 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 slirp/ncsi.c        |  78 ++++++++++
 slirp/slirp.c       |   4 +
 slirp/slirp.h       |   3 +
 6 files changed, 505 insertions(+), 1 deletion(-)
 create mode 100644 slirp/ncsi-pkt.h
 create mode 100644 slirp/ncsi.c
include/net/eth.h +1 -0
index 2013175857ba..3c6f061e9de2 100644
@@ -209,6 +209,7 @@ struct tcp_hdr {
 #define ETH_P_IPV6                (0x86dd)
 #define ETH_P_VLAN                (0x8100)
 #define ETH_P_DVLAN               (0x88a8)
+#define ETH_P_NCSI                (0x88f8)
 #define ETH_P_UNKNOWN             (0xffff)
 #define VLAN_VID_MASK             0x0fff
 #define IP_HEADER_VERSION_4       (4)
slirp/Makefile.objs +1 -1
index 1baa1f1c7cfb..28049b03cddc 100644
@@ -2,4 +2,4 @@ common-obj-y = cksum.o if.o ip_icmp.o ip6_icmp.o ip6_input.o ip6_output.o \
                ip_input.o ip_output.o dnssearch.o dhcpv6.o
 common-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
 common-obj-y += tcp_subr.o tcp_timer.o udp.o udp6.o bootp.o tftp.o arp_table.o \
-                ndp_table.o
+                ndp_table.o ncsi.o
slirp/ncsi-pkt.h new file +418 -0

418 lines not on this page · raw message

slirp/ncsi.c new file +78 -0

78 lines not on this page · raw message

slirp/slirp.c +4 -0
index 6e2b4e5a9010..c445c474e7e5 100644
@@ -870,6 +870,10 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
         }
         break;
 
+    case ETH_P_NCSI:
+        ncsi_input(slirp, pkt, pkt_len);
+        break;
+
     default:
         break;
     }
slirp/slirp.h +3 -0
index a1f31391341d..ef75357d4d75 100644
@@ -292,6 +292,9 @@ int tcp_emu(struct socket *, struct mbuf *);
 int tcp_ctl(struct socket *);
 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
 
+/* ncsi.c */
+void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
+
 #ifndef _WIN32
 #define min(x,y) ((x) < (y) ? (x) : (y))
 #define max(x,y) ((x) > (y) ? (x) : (y))
Signature · 1 line
2.7.4
#5 lore raw
In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

The Aspeed SoCs AST2400 and AST2500 have two FTGMAC100 ethernet controllers. This serie proposes a model for this device and a way to customize the bit definitions which are slightly different from the Faraday definitions.

The last patch adds a fake NC-SI (Network Controller Sideband Interface) backend to pretend a NIC is being managed.

Could you explain in a bit more detail why the patchset is marked "RFC" and what parts you want comments on? (An RFC patchset that doesn't say this kind of thing in the cover letter is dangerously close to being a "please ignore me" request :-))

thanks
-- PMM

#6 lore raw
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Cédric Le Goater

The Aspeed SoCs AST2400 and AST2500 have two FTGMAC100 ethernet controllers. This serie proposes a model for this device and a way to customize the bit definitions which are slightly different from the Faraday definitions.

Quoted 7 lines
Quoted 2 lines

The last patch adds a fake NC-SI (Network Controller Sideband Interface) backend to pretend a NIC is being managed.

Could you explain in a bit more detail why the patchset is marked "RFC" and what parts you want comments on? (An RFC patchset that doesn't say this kind of thing in the cover letter is dangerously close to being a "please ignore me" request :-))

This is true. I didn't take the time to do so ...

Well, first, this is not an area I am familiar with, so this might look more like a draft for experts and the review should take that into account :)

Also, I am not entirely satisfied with how the model looks for the first descriptor to transmit. May be I am trying to fit too well the driver.

And, the NC-SI is just a fake one to exercise the linux driver (we did find bugs with it) but I am wondering how far we should push the model. It's a rather complex interface.

Thanks,

C.