* Only GRETH device supported for now * Fix endian problem in GRETH driver --- bsps/riscv/griscv/include/bsp.h | 14 ++++++ bsps/riscv/griscv/net/leon_greth.c | 59 +++++++++++++++++++++++ bsps/shared/net/greth2.c | 6 ++- c/src/lib/libbsp/riscv/griscv/Makefile.am | 6 +++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 bsps/riscv/griscv/net/leon_greth.c
diff --git a/bsps/riscv/griscv/include/bsp.h b/bsps/riscv/griscv/include/bsp.h index 95cccd3d0a..b0d72475cc 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, use leon3 version + */ +struct rtems_bsdnet_ifconfig; +extern int rtems_leon_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_leon_greth_driver_attach +#define GRETH_SUPPORTED +#define CPU_U32_FIX + #ifdef __cplusplus } #endif diff --git a/bsps/riscv/griscv/net/leon_greth.c b/bsps/riscv/griscv/net/leon_greth.c new file mode 100644 index 0000000000..eb5dedd413 --- /dev/null +++ b/bsps/riscv/griscv/net/leon_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 <machine/rtems-bsd-kernel-space.h> +#include <bsp.h> +#include <amba.h> +#include <grlib/ambapp.h> +#include <libchip/greth.h> +/*#if (GRETH_DEBUG & GRETH_DEBUG_PRINT_REGISTERS)*/ +#include <stdio.h> +/*#endif*/ + +/* + * Default sizes of transmit and receive descriptor areas + */ +#define RDA_COUNT 32 +#define TDA_COUNT 32 + +greth_configuration_t leon_greth_configuration; + +int rtems_leon_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->irq; + + /* clear control register and reset NIC */ + *(volatile int *) base_addr = 0; + *(volatile int *) base_addr = GRETH_CTRL_RST; + *(volatile int *) base_addr = 0; + leon_greth_configuration.base_address = (void*)base_addr; + leon_greth_configuration.vector = eth_irq; /* on LEON vector is IRQ no. */ + leon_greth_configuration.txd_count = TDA_COUNT; + leon_greth_configuration.rxd_count = RDA_COUNT; + rtems_greth_driver_attach(config, &leon_greth_configuration); + } + return 0; +} 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 <rtems/bspIo.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #include <stdarg.h> #include <rtems/error.h> #include <rtems/rtems_bsdnet.h> @@ -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..221255d0c7 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/leon_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 -- 2.17.1 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel