From b4c29b54e7967a6197fd2542e5abd601fe434e1d Mon Sep 17 00:00:00 2001 From: Jiri Gaisler Date: Sat, 24 Oct 2020 16:43:49 +0200 Subject: Add networking support for griscv bsp * Only GRETH device supported for now * Fix endian problem in GRETH driver * Remove SPARC assembly from greth.c * Builds with both autoconf and waf --- bsps/riscv/griscv/console/console.c | 2 +- bsps/riscv/griscv/include/bsp.h | 14 +++++++ bsps/riscv/griscv/net/griscv_greth.c | 59 ++++++++++++++++++++++++++++ bsps/shared/grlib/net/greth.c | 24 +++++------ bsps/shared/net/greth2.c | 6 ++- c/src/lib/libbsp/riscv/griscv/Makefile.am | 6 +++ spec/build/bsps/riscv/griscv/grp.yml | 2 + spec/build/bsps/riscv/griscv/objnetnosmp.yml | 18 +++++++++ 8 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 bsps/riscv/griscv/net/griscv_greth.c create mode 100644 spec/build/bsps/riscv/griscv/objnetnosmp.yml diff --git a/bsps/riscv/griscv/console/console.c b/bsps/riscv/griscv/console/console.c index 582b4c81b8..c92be99fdb 100644 --- a/bsps/riscv/griscv/console/console.c +++ b/bsps/riscv/griscv/console/console.c @@ -64,7 +64,7 @@ static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg) /* Extract needed information of one APBUART */ apbuarts[uarts].regs = (struct apbuart_regs *)apb->start; - apbuarts[uarts].irq = apb->irq; + apbuarts[uarts].irq = apb->common.irq; /* Get APBUART core frequency, it is assumed that it is the same * as Bus frequency where the UART is situated */ diff --git a/bsps/riscv/griscv/include/bsp.h b/bsps/riscv/griscv/include/bsp.h index 95cccd3d0a..9d6fb2a16f 100644 --- a/bsps/riscv/griscv/include/bsp.h +++ b/bsps/riscv/griscv/include/bsp.h @@ -75,6 +75,20 @@ extern void BSP_shared_interrupt_mask(int irq); extern void BSP_shared_interrupt_clear(int irq); extern void BSP_shared_interrupt_unmask(int irq); +/* + * Network driver configuration for greth + */ +struct rtems_bsdnet_ifconfig; +extern int rtems_griscv_greth_driver_attach( + struct rtems_bsdnet_ifconfig *config, + int attach +); + +#define RTEMS_BSP_NETWORK_DRIVER_NAME "gr_eth1" +#define RTEMS_BSP_NETWORK_DRIVER_ATTACH rtems_griscv_greth_driver_attach +#define GRETH_SUPPORTED +#define CPU_U32_FIX + #ifdef __cplusplus } #endif diff --git a/bsps/riscv/griscv/net/griscv_greth.c b/bsps/riscv/griscv/net/griscv_greth.c new file mode 100644 index 0000000000..e5c05fd060 --- /dev/null +++ b/bsps/riscv/griscv/net/griscv_greth.c @@ -0,0 +1,59 @@ +/* + * LEON3 Opencores Ethernet MAC Configuration Information + * + * COPYRIGHT (c) 2004. + * Gaisler Research + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include +#include +#include +#include +#include +/*#if (GRETH_DEBUG & GRETH_DEBUG_PRINT_REGISTERS)*/ +#include +/*#endif*/ + +/* + * Default sizes of transmit and receive descriptor areas + */ +#define RDA_COUNT 32 +#define TDA_COUNT 32 + +greth_configuration_t griscv_greth_configuration; + +int rtems_griscv_greth_driver_attach( + struct rtems_bsdnet_ifconfig *config, + int attach +) +{ + unsigned int base_addr = 0; /* avoid warnings */ + unsigned int eth_irq = 0; /* avoid warnings */ + struct ambapp_dev *adev; + struct ambapp_apb_info *apb; + + /* Scan for MAC AHB slave interface */ + adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), + VENDOR_GAISLER, GAISLER_ETHMAC, + ambapp_find_by_idx, NULL); + if (adev) { + apb = DEV_TO_APB(adev); + base_addr = apb->start; + eth_irq = apb->common.irq; + + /* clear control register and reset NIC */ + *(volatile int *) base_addr = 0; + *(volatile int *) base_addr = GRETH_CTRL_RST; + *(volatile int *) base_addr = 0; + griscv_greth_configuration.base_address = (void*)base_addr; + griscv_greth_configuration.vector = eth_irq; /* on LEON vector is IRQ no. */ + griscv_greth_configuration.txd_count = TDA_COUNT; + griscv_greth_configuration.rxd_count = RDA_COUNT; + rtems_greth_driver_attach(config, &griscv_greth_configuration); + } + return 0; +} diff --git a/bsps/shared/grlib/net/greth.c b/bsps/shared/grlib/net/greth.c index bc4d3cc40f..8b19b48211 100644 --- a/bsps/shared/grlib/net/greth.c +++ b/bsps/shared/grlib/net/greth.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -721,10 +722,13 @@ void ipalign(struct mbuf *m) unsigned int tmp = 0; if ((((int) m->m_data) & 2) && (m->m_len)) { +#if CPU_LITTLE_ENDIAN == TRUE + memmove((caddr_t)(((int) m->m_data) + 2), m->m_data, m->m_len); +#else last = (unsigned int *) ((((int) m->m_data) + m->m_len + 8) & ~3); first = (unsigned int *) (((int) m->m_data) & ~3); /* tmp = *first << 16; */ - asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(first) ); + tmp = GRETH_MEM_LOAD(first); tmp = tmp << 16; first++; do { @@ -733,12 +737,12 @@ void ipalign(struct mbuf *m) ** Load with forced cache miss * data = *first; */ - asm volatile (" lda [%1] 1, %0\n" : "=r"(data) : "r"(first) ); + data = GRETH_MEM_LOAD(first); *first = tmp | (data >> 16); tmp = data << 16; first++; } while (first <= last); - +#endif m->m_data = (caddr_t)(((int) m->m_data) + 2); } } @@ -756,7 +760,6 @@ greth_Daemon (void *arg) SPIN_IRQFLAGS(flags); int first; int tmp; - unsigned int addr; for (;;) { @@ -836,14 +839,11 @@ again: #ifdef CPU_U32_FIX if(!dp->gbit_mac) { /* OVERRIDE CACHED ETHERNET HEADER FOR NON-SNOOPING SYSTEMS */ - addr = (unsigned int)eh; - asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr) ); - addr+=4; - asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr) ); - addr+=4; - asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr) ); - addr+=4; - asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp) : "r"(addr) ); + tmp = GRETH_MEM_LOAD((uintptr_t)eh); + tmp = GRETH_MEM_LOAD(4+(uintptr_t)eh); + tmp = GRETH_MEM_LOAD(8+(uintptr_t)eh); + tmp = GRETH_MEM_LOAD(12+(uintptr_t)eh); + (void)tmp; ipalign(m); /* Align packet on 32-bit boundary */ } diff --git a/bsps/shared/net/greth2.c b/bsps/shared/net/greth2.c index 2fc35a5471..13bf7b8884 100644 --- a/bsps/shared/net/greth2.c +++ b/bsps/shared/net/greth2.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -514,6 +515,9 @@ void ipalign(struct mbuf *m) unsigned int tmp; if ((((int) m->m_data) & 2) && (m->m_len)) { +#if CPU_LITTLE_ENDIAN == TRUE + memmove((caddr_t)(((int) m->m_data) + 2), m->m_data, m->m_len); +#else last = (unsigned int *) ((((int) m->m_data) + m->m_len + 8) & ~3); first = (unsigned int *) (((int) m->m_data) & ~3); tmp = GRETH_MEM_LOAD(first); @@ -529,7 +533,7 @@ void ipalign(struct mbuf *m) tmp = data << 16; first++; } while (first <= last); - +#endif m->m_data = (caddr_t)(((int) m->m_data) + 2); } } diff --git a/c/src/lib/libbsp/riscv/griscv/Makefile.am b/c/src/lib/libbsp/riscv/griscv/Makefile.am index e04598e4bf..07f5cc03ca 100644 --- a/c/src/lib/libbsp/riscv/griscv/Makefile.am +++ b/c/src/lib/libbsp/riscv/griscv/Makefile.am @@ -64,6 +64,12 @@ if HAS_SMP librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/griscv/start/bspsmp.c endif +if HAS_NETWORKING +if !HAS_SMP +librtemsbsp_a_SOURCES += ../../../../../../bsps/riscv/griscv/net/griscv_greth.c +endif +endif + include $(srcdir)/../../../../../../bsps/shared/irq-sources.am include $(srcdir)/../../../../../../bsps/shared/grlib-sources.am include $(srcdir)/../../../../../../bsps/shared/shared-sources.am diff --git a/spec/build/bsps/riscv/griscv/grp.yml b/spec/build/bsps/riscv/griscv/grp.yml index 1945d984f5..056af047b6 100644 --- a/spec/build/bsps/riscv/griscv/grp.yml +++ b/spec/build/bsps/riscv/griscv/grp.yml @@ -23,6 +23,8 @@ links: uid: abi - role: build-dependency uid: obj +- role: build-dependency + uid: objnetnosmp - role: build-dependency uid: objsmp - role: build-dependency diff --git a/spec/build/bsps/riscv/griscv/objnetnosmp.yml b/spec/build/bsps/riscv/griscv/objnetnosmp.yml new file mode 100644 index 0000000000..105a23351d --- /dev/null +++ b/spec/build/bsps/riscv/griscv/objnetnosmp.yml @@ -0,0 +1,18 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: objects +cflags: [] +copyrights: +- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) +cppflags: [] +cxxflags: [] +enabled-by: +- and: + - RTEMS_NETWORKING + - not: RTEMS_SMP +includes: +- cpukit/libnetworking +install: [] +links: [] +source: +- bsps/riscv/griscv/net/griscv_greth.c +type: build -- cgit v1.2.3