[PATCH] RTEMS libbsd changes for cpsw driver
ragunath
ragunath3252 at gmail.com
Sun Jun 28 09:58:03 UTC 2015
---
Makefile | 1 +
freebsd/sys/arm/ti/cpsw/if_cpsw.c | 64 +++++++++++++++++++++-
freebsd/sys/arm/ti/cpsw/if_cpswreg.h | 3 +
freebsd/sys/arm/ti/cpsw/if_cpswvar.h | 2 +
rtemsbsd/include/bsp/nexus-devices.h | 34 ++++++++++++
rtemsbsd/include/machine/rtems-bsd-cache.h | 2 +-
.../include/rtems/bsd/test/network-config.h.in | 2 +
7 files changed, 106 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 4b9f2c7..8b46db7 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ COMMON_FLAGS += -Ifreebsd/lib/libkvm
COMMON_FLAGS += -Ifreebsd/lib/libmemstat
COMMON_FLAGS += -Ifreebsd/lib/libipsec
COMMON_FLAGS += -Irtemsbsd/sys
+COMMON_FLAGS += -Irtemsbsd/include/rtems/bsd/local
COMMON_FLAGS += -ImDNSResponder/mDNSCore
COMMON_FLAGS += -ImDNSResponder/mDNSShared
COMMON_FLAGS += -ImDNSResponder/mDNSPosix
diff --git a/freebsd/sys/arm/ti/cpsw/if_cpsw.c b/freebsd/sys/arm/ti/cpsw/if_cpsw.c
index c3ba0c8..47c99b3 100644
--- a/freebsd/sys/arm/ti/cpsw/if_cpsw.c
+++ b/freebsd/sys/arm/ti/cpsw/if_cpsw.c
@@ -52,7 +52,11 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/endian.h>
#include <sys/mbuf.h>
+#ifndef __rtems__
#include <sys/lock.h>
+#else
+#include <rtems/bsd/sys/lock.h>
+#endif /* __rtems__ */
#include <sys/mutex.h>
#include <sys/kernel.h>
#include <sys/module.h>
@@ -82,14 +86,18 @@ __FBSDID("$FreeBSD$");
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
+#ifndef __rtems__
#include <dev/fdt/fdt_common.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#endif /* __rtems__ */
#include "if_cpswreg.h"
#include "if_cpswvar.h"
+#ifndef __rtems__
#include <arm/ti/ti_scm.h>
+#endif /* __rtems__ */
#include "miibus_if.h"
@@ -140,9 +148,11 @@ static int cpsw_ale_update_addresses(struct cpsw_softc *, int purge);
static void cpsw_ale_dump_table(struct cpsw_softc *);
/* Statistics and sysctls. */
+#ifndef __rtems__
static void cpsw_add_sysctls(struct cpsw_softc *);
static void cpsw_stats_collect(struct cpsw_softc *);
static int cpsw_stats_sysctl(SYSCTL_HANDLER_ARGS);
+#endif /* __rtems__ */
/*
* Arbitrary limit on number of segments in an mbuf to be transmitted.
@@ -192,7 +202,11 @@ static driver_t cpsw_driver = {
static devclass_t cpsw_devclass;
+#ifndef __rtems__
DRIVER_MODULE(cpsw, simplebus, cpsw_driver, cpsw_devclass, 0, 0);
+#else
+DRIVER_MODULE(cpsw, nexus, cpsw_driver, cpsw_devclass, 0, 0);
+#endif /* __rtems__ */
DRIVER_MODULE(miibus, cpsw, miibus_driver, miibus_devclass, 0, 0);
MODULE_DEPEND(cpsw, ether, 1, 1, 1);
MODULE_DEPEND(cpsw, miibus, 1, 1, 1);
@@ -206,6 +220,7 @@ static struct resource_spec res_spec[] = {
{ -1, 0 }
};
+#ifndef __rtems__
/* Number of entries here must match size of stats
* array in struct cpsw_softc. */
static struct cpsw_stat {
@@ -247,6 +262,7 @@ static struct cpsw_stat {
{0x88, "RxMiddleOfFrameOverruns"},
{0x8c, "RxDmaOverruns"}
};
+#endif /* __rtems__ */
/*
* Basic debug support.
@@ -326,6 +342,13 @@ cpsw_debugf(const char *fmt, ...)
*/
#define cpsw_read_4(sc, reg) bus_read_4(sc->res[0], reg)
#define cpsw_write_4(sc, reg, val) bus_write_4(sc->res[0], reg, val)
+#ifdef __rtems__
+#define BUS_SPACE_PHYSADDR(res, offs) \
+ ((u_int)(rman_get_start(res)+(offs)))
+#define cm_read(a) (*(volatile uint32_t *)(a))
+#define cm_write(a,v) (*(volatile uint32_t *)(a) = (v))
+#endif /* __rtems__ */
+
#define cpsw_cpdma_bd_offset(i) (CPSW_CPPI_RAM_OFFSET + ((i)*16))
@@ -447,11 +470,13 @@ static int
cpsw_probe(device_t dev)
{
+#ifndef __rtems__
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "ti,cpsw"))
return (ENXIO);
+#endif /* __rtems__ */
device_set_desc(dev, "3-port Switch Ethernet Subsystem");
return (BUS_PROBE_DEFAULT);
@@ -551,14 +576,18 @@ cpsw_attach(device_t dev)
struct cpsw_softc *sc = device_get_softc(dev);
struct mii_softc *miisc;
struct ifnet *ifp;
+#ifndef __rtems__
void *phy_sc;
- int error, phy, nsegs;
+ int phy;
+#endif /* __rtems__ */
+ int error, nsegs;
uint32_t reg;
CPSW_DEBUGF((""));
getbinuptime(&sc->attach_uptime);
sc->dev = dev;
+#ifndef __rtems__
sc->node = ofw_bus_get_node(dev);
/* Get phy address from fdt */
@@ -566,6 +595,7 @@ cpsw_attach(device_t dev)
device_printf(dev, "failed to get PHY address from FDT\n");
return (ENXIO);
}
+#endif /* __rtems__ */
/* Initialize mutexes */
mtx_init(&sc->tx.lock, device_get_nameunit(dev),
"cpsw TX lock", MTX_DEF);
@@ -584,7 +614,9 @@ cpsw_attach(device_t dev)
device_printf(dev, "CPSW SS Version %d.%d (%d)\n", (reg >> 8 & 0x7),
reg & 0xFF, (reg >> 11) & 0x1F);
+#ifndef __rtems__
cpsw_add_sysctls(sc);
+#endif /* __rtems__ */
/* Allocate a busdma tag and DMA safe memory for mbufs. */
error = bus_dma_tag_create(
@@ -657,14 +689,22 @@ cpsw_attach(device_t dev)
/* Get high part of MAC address from control module (mac_id0_hi) */
/* TODO: Get MAC ID1 as well as MAC ID0. */
+#ifndef __rtems__
ti_scm_reg_read_4(0x634, ®);
+#else
+ reg = cm_read(CONTROL_MOD_BASE+0x634);
+#endif /* __rtems__ */
sc->mac_addr[0] = reg & 0xFF;
sc->mac_addr[1] = (reg >> 8) & 0xFF;
sc->mac_addr[2] = (reg >> 16) & 0xFF;
sc->mac_addr[3] = (reg >> 24) & 0xFF;
/* Get low part of MAC address from control module (mac_id0_lo) */
+#ifndef __rtems__
ti_scm_reg_read_4(0x630, ®);
+#else
+ reg = cm_read(CONTROL_MOD_BASE+0x630);
+#endif /* __rtems__ */
sc->mac_addr[4] = reg & 0xFF;
sc->mac_addr[5] = (reg >> 8) & 0xFF;
@@ -677,7 +717,11 @@ cpsw_attach(device_t dev)
/* Attach PHY(s) */
error = mii_attach(dev, &sc->miibus, ifp, cpsw_ifmedia_upd,
+#ifndef __rtems__
cpsw_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
+#else
+ cpsw_ifmedia_sts, BMSR_DEFCAPMASK,MII_PHY_ANY, MII_OFFSET_ANY, 0);
+#endif /* __rtems__ */
if (error) {
device_printf(dev, "attaching PHYs failed\n");
cpsw_detach(dev);
@@ -1029,8 +1073,10 @@ cpsw_shutdown_locked(struct cpsw_softc *sc)
cpsw_rx_teardown_locked(sc);
cpsw_tx_teardown_locked(sc);
+#ifndef __rtems__
/* Capture stats before we reset controller. */
cpsw_stats_collect(sc);
+#endif /* __rtems__ */
cpsw_reset(sc);
}
@@ -1194,7 +1240,11 @@ cpsw_miibus_readreg(device_t dev, int phy, int reg)
r = cpsw_read_4(sc, MDIOUSERACCESS0);
if((r & 1 << 29) == 0) {
+#ifndef __rtems__
device_printf(dev, "Failed to read from PHY.\n");
+#else
+ CPSW_DEBUGF(("Failed to read from PHY.\n"));
+#endif /* __rtems__ */
r = 0;
}
return (r & 0xFFFF);
@@ -1222,7 +1272,11 @@ cpsw_miibus_writereg(device_t dev, int phy, int reg, int value)
}
if((cpsw_read_4(sc, MDIOUSERACCESS0) & (1 << 29)) == 0)
+#ifndef __rtems__
device_printf(dev, "Failed to write to PHY.\n");
+#else
+ CPSW_DEBUGF(("Failed to write to PHY.\n"));
+#endif /* __rtems__ */
return 0;
}
@@ -1749,8 +1803,10 @@ cpsw_intr_misc(void *arg)
if (stat & 16)
CPSW_DEBUGF(("Time sync event interrupt unimplemented"));
+#ifndef __rtems__
if (stat & 8)
cpsw_stats_collect(sc);
+#endif /* __rtems__ */
if (stat & 4)
cpsw_intr_misc_host_error(sc);
if (stat & 2)
@@ -1848,7 +1904,11 @@ cpsw_tx_watchdog(struct cpsw_softc *sc)
++sc->watchdog.timer;
if (sc->watchdog.timer > 2) {
sc->watchdog.timer = 0;
+#ifndef __rtems__
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
+#else
+ sc->ifp->if_oerrors++;
+#endif /* __rtems__ */
++sc->watchdog.resets;
cpsw_tx_watchdog_full_reset(sc);
}
@@ -2045,6 +2105,7 @@ cpsw_stats_dump(struct cpsw_softc *sc)
}
#endif
+#ifndef __rtems__
static void
cpsw_stats_collect(struct cpsw_softc *sc)
{
@@ -2196,3 +2257,4 @@ cpsw_add_sysctls(struct cpsw_softc *sc)
CTLFLAG_RD, NULL, "Watchdog Statistics");
cpsw_add_watchdog_sysctls(ctx, node, sc);
}
+#endif /* __rtems__ */
diff --git a/freebsd/sys/arm/ti/cpsw/if_cpswreg.h b/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
index 46f8417..cb51b51 100644
--- a/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
+++ b/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
@@ -134,4 +134,7 @@ struct cpsw_cpdma_bd {
volatile uint16_t flags;
};
+#ifdef __rtems__
+#define CONTROL_MOD_BASE 0x44E10000
+#endif
#endif /*_IF_CPSWREG_H */
diff --git a/freebsd/sys/arm/ti/cpsw/if_cpswvar.h b/freebsd/sys/arm/ti/cpsw/if_cpswvar.h
index 2aebb0f..7ca640f 100644
--- a/freebsd/sys/arm/ti/cpsw/if_cpswvar.h
+++ b/freebsd/sys/arm/ti/cpsw/if_cpswvar.h
@@ -66,7 +66,9 @@ struct cpsw_queue {
struct cpsw_softc {
struct ifnet *ifp;
+#ifndef __rtems__
phandle_t node;
+#endif
device_t dev;
struct bintime attach_uptime; /* system uptime when attach happened. */
struct bintime init_uptime; /* system uptime when init happened. */
diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h
index fcd8775..5b3e811 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -52,6 +52,40 @@ static const rtems_bsd_device_resource smc0_res[] = {
RTEMS_BSD_DEFINE_NEXUS_DEVICE(smc, 0, RTEMS_ARRAY_SIZE(smc0_res),
&smc0_res[0]);
+#elif defined(LIBBSP_ARM_BEAGLE_BSP_H)
+
+static const rtems_bsd_device_resource cpsw0_res[] = {
+ {
+ .type = RTEMS_BSD_RES_MEMORY,
+ .start_request = 0,
+ .start_actual = 0x4a100000
+ }, {
+ .type = RTEMS_BSD_RES_IRQ,
+ .start_request = 0,
+ .start_actual = 0x28
+ },
+ {
+ .type = RTEMS_BSD_RES_IRQ,
+ .start_request = 1,
+ .start_actual = 0x29
+ },
+ {
+ .type = RTEMS_BSD_RES_IRQ,
+ .start_request = 2,
+ .start_actual = 0x2a
+ },
+ {
+ .type = RTEMS_BSD_RES_IRQ,
+ .start_request = 3,
+ .start_actual = 0x2b
+ }
+};
+
+RTEMS_BSD_DEFINE_NEXUS_DEVICE(cpsw, 0, RTEMS_ARRAY_SIZE(cpsw0_res),
+ &cpsw0_res[0]);
+
+SYSINIT_DRIVER_REFERENCE(smscphy, miibus);
+
#elif defined(__GENMCF548X_BSP_H)
RTEMS_BSD_DEFINE_NEXUS_DEVICE(fec, 0, 0, NULL);
diff --git a/rtemsbsd/include/machine/rtems-bsd-cache.h b/rtemsbsd/include/machine/rtems-bsd-cache.h
index b8c4ce7..b8914ec 100644
--- a/rtemsbsd/include/machine/rtems-bsd-cache.h
+++ b/rtemsbsd/include/machine/rtems-bsd-cache.h
@@ -45,7 +45,7 @@
#if defined(LIBBSP_ARM_LPC24XX_BSP_H)
/* No cache */
#elif defined(LIBBSP_ARM_ALTERA_CYCLONE_V_BSP_H) || \
- defined(LIBBSP_ARM_XILINX_ZYNQ_BSP_H)
+ defined(LIBBSP_ARM_XILINX_ZYNQ_BSP_H) || defined(LIBBSP_ARM_BEAGLE_BSP_H)
/* With cache, no coherency support in hardware */
#define CPU_DATA_CACHE_ALIGNMENT 32
#elif defined(LIBBSP_ARM_LPC32XX_BSP_H)
diff --git a/testsuite/include/rtems/bsd/test/network-config.h.in b/testsuite/include/rtems/bsd/test/network-config.h.in
index 30a9c5a..3169e76 100644
--- a/testsuite/include/rtems/bsd/test/network-config.h.in
+++ b/testsuite/include/rtems/bsd/test/network-config.h.in
@@ -42,6 +42,8 @@
#define NET_CFG_INTERFACE_0 "cgem0"
#elif defined(__GENMCF548X_BSP_H)
#define NET_CFG_INTERFACE_0 "fec0"
+#elif defined(LIBBSP_ARM_BEAGLE_BSP_H)
+ #define NET_CFG_INTERFACE_0 "cpsw0"
#else
#define NET_CFG_INTERFACE_0 "lo0"
#endif
--
1.9.1
More information about the devel
mailing list