[PATCH] RTEMS related changes for cpsw ethernet driver

Gedare Bloom gedare at gwu.edu
Fri Jun 26 20:53:48 UTC 2015


On Fri, Jun 26, 2015 at 4:41 PM, ragunath <ragunath3252 at gmail.com> wrote:
> ---
>  Makefile                                           |  1 +
>  freebsd/sys/arm/ti/cpsw/if_cpsw.c                  | 56 ++++++++++++++++++++--
>  freebsd/sys/arm/ti/cpsw/if_cpswreg.h               |  1 +
>  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, 93 insertions(+), 5 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..7fda577 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
I think something like /* __rtems__ */ is supposed to go after the endifs.

>  #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
>
>  #include "if_cpswreg.h"
>  #include "if_cpswvar.h"
>
> +#ifndef __rtems__
>  #include <arm/ti/ti_scm.h>
> +#endif
>
>  #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
>
>  /*
>   * 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
>  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
>
>  /*
>   * Basic debug support.
> @@ -326,6 +342,11 @@ 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)
> +#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))
> +
Make sure everything added has the __rtems__ guards.

>
>  #define        cpsw_cpdma_bd_offset(i) (CPSW_CPPI_RAM_OFFSET + ((i)*16))
>
> @@ -447,11 +468,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
>
>         device_set_desc(dev, "3-port Switch Ethernet Subsystem");
>         return (BUS_PROBE_DEFAULT);
> @@ -551,14 +574,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
> +       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 +593,7 @@ cpsw_attach(device_t dev)
>                 device_printf(dev, "failed to get PHY address from FDT\n");
>                 return (ENXIO);
>         }
> +#endif
>         /* Initialize mutexes */
>         mtx_init(&sc->tx.lock, device_get_nameunit(dev),
>             "cpsw TX lock", MTX_DEF);
> @@ -584,7 +612,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
>
>         /* Allocate a busdma tag and DMA safe memory for mbufs. */
>         error = bus_dma_tag_create(
> @@ -657,14 +687,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, &reg);
> +#else
> +        reg = cm_read(CONTROL_MOD_BASE+0x634);
> +#endif
>         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, &reg);
> +#else
> +        reg = cm_read(CONTROL_MOD_BASE+0x630);
> +#endif
>         sc->mac_addr[4] = reg & 0xFF;
>         sc->mac_addr[5] = (reg >>  8) & 0xFF;
>
> @@ -677,7 +715,7 @@ cpsw_attach(device_t dev)
>
>         /* Attach PHY(s) */
>         error = mii_attach(dev, &sc->miibus, ifp, cpsw_ifmedia_upd,
> -           cpsw_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
> +           cpsw_ifmedia_sts, BMSR_DEFCAPMASK,MII_PHY_ANY, MII_OFFSET_ANY, 0);
>         if (error) {
>                 device_printf(dev, "attaching PHYs failed\n");
>                 cpsw_detach(dev);
> @@ -1029,8 +1067,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
>
>         cpsw_reset(sc);
>  }
> @@ -1194,7 +1234,7 @@ cpsw_miibus_readreg(device_t dev, int phy, int reg)
>
>         r = cpsw_read_4(sc, MDIOUSERACCESS0);
>         if((r & 1 << 29) == 0) {
> -               device_printf(dev, "Failed to read from PHY.\n");
> +               CPSW_DEBUGF(("Failed to read from PHY.\n"));
>                 r = 0;
>         }
>         return (r & 0xFFFF);
> @@ -1222,7 +1262,7 @@ cpsw_miibus_writereg(device_t dev, int phy, int reg, int value)
>         }
>
>         if((cpsw_read_4(sc, MDIOUSERACCESS0) & (1 << 29)) == 0)
> -               device_printf(dev, "Failed to write to PHY.\n");
> +               CPSW_DEBUGF(("Failed to write to PHY.\n"));
>
>         return 0;
>  }
> @@ -1749,8 +1789,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
>         if (stat & 4)
>                 cpsw_intr_misc_host_error(sc);
>         if (stat & 2)
> @@ -1848,7 +1890,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
>                         ++sc->watchdog.resets;
>                         cpsw_tx_watchdog_full_reset(sc);
>                 }
> @@ -2045,6 +2091,7 @@ cpsw_stats_dump(struct cpsw_softc *sc)
>  }
>  #endif
>
> +#ifndef __rtems__
>  static void
>  cpsw_stats_collect(struct cpsw_softc *sc)
>  {
> @@ -2196,3 +2243,4 @@ cpsw_add_sysctls(struct cpsw_softc *sc)
>             CTLFLAG_RD, NULL, "Watchdog Statistics");
>         cpsw_add_watchdog_sysctls(ctx, node, sc);
>  }
> +#endif
> diff --git a/freebsd/sys/arm/ti/cpsw/if_cpswreg.h b/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
> index 46f8417..7a8d6a2 100644
> --- a/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
> +++ b/freebsd/sys/arm/ti/cpsw/if_cpswreg.h
> @@ -134,4 +134,5 @@ struct cpsw_cpdma_bd {
>         volatile uint16_t flags;
>  };
>
> +#define CONTROL_MOD_BASE 0x44E10000
>  #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
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list