<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 10/25/20 6:35 PM, Joel Sherrill
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAF9ehCVhszq1OFj5oAM049X2Q6O30H6-d=OGdbT9rnuyTQz8rg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">Is the code deleted referenced in the new build
        system?</div>
    </blockquote>
    Good question! I don't really know how the new systems works to
    answer that. I could only remove the references from the .am
    files...  <br>
    <blockquote type="cite"
cite="mid:CAF9ehCVhszq1OFj5oAM049X2Q6O30H6-d=OGdbT9rnuyTQz8rg@mail.gmail.com"><br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sun, Oct 25, 2020, 5:26 PM
          Jiri Gaisler <<a href="mailto:jiri@gaisler.se"
            moz-do-not-send="true">jiri@gaisler.se</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">        *
          bsps/shared/net/greth2.c is being used instead<br>
          ---<br>
           bsps/shared/<a href="http://grlib-sources.am" rel="noreferrer
            noreferrer" target="_blank" moz-do-not-send="true">grlib-sources.am</a> 
                          |    4 -<br>
           bsps/shared/grlib/net/README                  |    7 -<br>
           bsps/shared/grlib/net/greth.c                 | 1655
          -----------------<br>
           bsps/shared/grlib/net/network_interface_add.c |   62 -<br>
           4 files changed, 1728 deletions(-)<br>
           delete mode 100644 bsps/shared/grlib/net/README<br>
           delete mode 100644 bsps/shared/grlib/net/greth.c<br>
           delete mode 100644
          bsps/shared/grlib/net/network_interface_add.c<br>
          <br>
          diff --git a/bsps/shared/<a href="http://grlib-sources.am"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">grlib-sources.am</a> b/bsps/shared/<a
            href="http://grlib-sources.am" rel="noreferrer noreferrer"
            target="_blank" moz-do-not-send="true">grlib-sources.am</a><br>
          index 512a48c7f7..2261eb957f 100644<br>
          --- a/bsps/shared/<a href="http://grlib-sources.am"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">grlib-sources.am</a><br>
          +++ b/bsps/shared/<a href="http://grlib-sources.am"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">grlib-sources.am</a><br>
          @@ -34,10 +34,6 @@ librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/iommu/griommu.c<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/irq/genirq.c<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/l2c/l2c.c<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/mem/mctrl.c<br>
          -if HAS_NETWORKING<br>
          -librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/net/greth.c<br>
          -librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/net/network_interface_add.c<br>
          -endif<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/pci/gr_701.c<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/pci/grpci2.c<br>
           librtemsbsp_a_SOURCES +=
          ../../../../../../bsps/shared/grlib/pci/grpci2dma.c<br>
          diff --git a/bsps/shared/grlib/net/README
          b/bsps/shared/grlib/net/README<br>
          deleted file mode 100644<br>
          index 3ef086f223..0000000000<br>
          --- a/bsps/shared/grlib/net/README<br>
          +++ /dev/null<br>
          @@ -1,7 +0,0 @@<br>
          -A non Driver Manager GRETH driver is located in
          libchip/network/greth.c. This<br>
          -version requires the driver manager.<br>
          -<br>
          -network_interface_add is used to assign IP/NETMASK and MAC
          address to<br>
          -GRETH interfaces dynamically according to in which order
          devices are<br>
          -registered. The function takes the settings from the user
          defined<br>
          -interface_configs[] array, defined in the project
          configuration.<br>
          diff --git a/bsps/shared/grlib/net/greth.c
          b/bsps/shared/grlib/net/greth.c<br>
          deleted file mode 100644<br>
          index bc4d3cc40f..0000000000<br>
          --- a/bsps/shared/grlib/net/greth.c<br>
          +++ /dev/null<br>
          @@ -1,1655 +0,0 @@<br>
          -/*<br>
          - * Gaisler Research ethernet MAC driver<br>
          - * adapted from Opencores driver by Marko Isomaki<br>
          - *<br>
          - *  The license and distribution terms for this file may be<br>
          - *  found in found in the file LICENSE in this distribution
          or at<br>
          - *  <a href="http://www.rtems.org/license/LICENSE"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">http://www.rtems.org/license/LICENSE</a>.<br>
          - *<br>
          - *<br>
          - *  2008-12-10, Converted to driver manager and added support
          for<br>
          - *              multiple GRETH cores. <<a
            href="mailto:daniel@gaisler.com" target="_blank"
            rel="noreferrer" moz-do-not-send="true">daniel@gaisler.com</a>><br>
          - *  2007-09-07, Ported GBIT support from 4.6.5<br>
          - */<br>
          -<br>
          -#include <machine/rtems-bsd-kernel-space.h><br>
          -<br>
          -#include <rtems.h><br>
          -#define CPU_U32_FIX<br>
          -#include <bsp.h><br>
          -<br>
          -#ifdef GRETH_SUPPORTED<br>
          -<br>
          -#include <inttypes.h><br>
          -#include <errno.h><br>
          -#include <rtems/bspIo.h><br>
          -#include <stdlib.h><br>
          -#include <stdio.h><br>
          -#include <stdarg.h><br>
          -#include <rtems/error.h><br>
          -#include <rtems/rtems_bsdnet.h><br>
          -<br>
          -#include <grlib/greth.h><br>
          -#include <drvmgr/drvmgr.h><br>
          -#include <grlib/ambapp_bus.h><br>
          -#include <grlib/ambapp.h><br>
          -<br>
          -#include <sys/param.h><br>
          -#include <sys/mbuf.h><br>
          -<br>
          -#include <sys/socket.h><br>
          -#include <sys/sockio.h><br>
          -#include <net/if.h><br>
          -#include <netinet/in.h><br>
          -#include <netinet/if_ether.h><br>
          -<br>
          -#ifdef malloc<br>
          -#undef malloc<br>
          -#endif<br>
          -#ifdef free<br>
          -#undef free<br>
          -#endif<br>
          -<br>
          -#include <grlib/grlib_impl.h><br>
          -<br>
          -#if defined(__m68k__)<br>
          -extern m68k_isr_entry set_vector( rtems_isr_entry,
          rtems_vector_number, int );<br>
          -#else<br>
          -extern rtems_isr_entry set_vector( rtems_isr_entry,
          rtems_vector_number, int );<br>
          -#endif<br>
          -<br>
          -<br>
          -/* #define GRETH_DEBUG */<br>
          -<br>
          -#ifdef GRETH_DEBUG<br>
          -#define DBG(args...) printk(args)<br>
          -#else<br>
          -#define DBG(args...)<br>
          -#endif<br>
          -<br>
          -/* #define GRETH_DEBUG_MII */<br>
          -<br>
          -#ifdef GRETH_DEBUG_MII<br>
          -#define MIIDBG(args...) printk(args)<br>
          -#else<br>
          -#define MIIDBG(args...)<br>
          -#endif<br>
          -<br>
          -#ifdef CPU_U32_FIX<br>
          -extern void ipalign(struct mbuf *m);<br>
          -#endif<br>
          -<br>
          -/* Used when reading from memory written by GRETH DMA unit */<br>
          -#ifndef GRETH_MEM_LOAD<br>
          -#define GRETH_MEM_LOAD(addr) (*(volatile unsigned int
          *)(addr))<br>
          -#endif<br>
          -<br>
          -/*<br>
          - * Number of OCs supported by this driver<br>
          - */<br>
          -#define NOCDRIVER      1<br>
          -<br>
          -/*<br>
          - * Receive buffer size -- Allow for a full ethernet packet
          including CRC<br>
          - */<br>
          -#define RBUF_SIZE 1518<br>
          -<br>
          -#define        ET_MINLEN 64            /* minimum message
          length */<br>
          -<br>
          -/*<br>
          - * RTEMS event used by interrupt handler to signal driver
          tasks.<br>
          - * This must not be any of the events used by the network
          task synchronization.<br>
          - */<br>
          -#define INTERRUPT_EVENT        RTEMS_EVENT_1<br>
          -<br>
          -/*<br>
          - * RTEMS event used to start transmit daemon.<br>
          - * This must not be the same as INTERRUPT_EVENT.<br>
          - */<br>
          -#define START_TRANSMIT_EVENT   RTEMS_EVENT_2<br>
          -<br>
          - /* event to send when tx buffers become available */<br>
          -#define GRETH_TX_WAIT_EVENT  RTEMS_EVENT_3<br>
          -<br>
          -#if (MCLBYTES < RBUF_SIZE)<br>
          -# error "Driver must have MCLBYTES > RBUF_SIZE"<br>
          -#endif<br>
          -<br>
          -/* 4s Autonegotiation Timeout */<br>
          -#ifndef GRETH_AUTONEGO_TIMEOUT_MS<br>
          -#define GRETH_AUTONEGO_TIMEOUT_MS 4000<br>
          -#endif<br>
          -const struct timespec greth_tan = {<br>
          -   GRETH_AUTONEGO_TIMEOUT_MS/1000,<br>
          -   (GRETH_AUTONEGO_TIMEOUT_MS % 1000) * 1000000<br>
          -};<br>
          -<br>
          -/* For optimizing the autonegotiation time */<br>
          -#define GRETH_AUTONEGO_PRINT_TIME<br>
          -<br>
          -/* Ethernet buffer descriptor */<br>
          -<br>
          -typedef struct _greth_rxtxdesc {<br>
          -   volatile uint32_t ctrl; /* Length and status */<br>
          -   uint32_t *addr;         /* Buffer pointer */<br>
          -} greth_rxtxdesc;<br>
          -<br>
          -<br>
          -/*<br>
          - * Per-device data<br>
          - */<br>
          -struct greth_softc<br>
          -{<br>
          -<br>
          -   struct arpcom arpcom;<br>
          -   struct drvmgr_dev *dev;             /* Driver manager
          device */<br>
          -   char devName[32];<br>
          -<br>
          -   greth_regs *regs;<br>
          -   int minor;<br>
          -   int phyaddr;  /* PHY Address configured by user (or -1 to
          autodetect) */<br>
          -   unsigned int edcl_dis;<br>
          -   int greth_rst;<br>
          -<br>
          -   int acceptBroadcast;<br>
          -   rtems_id daemonTid;<br>
          -   <br>
          -   unsigned int tx_ptr;<br>
          -   unsigned int tx_dptr;<br>
          -   unsigned int tx_cnt;<br>
          -   unsigned int rx_ptr;<br>
          -   unsigned int txbufs;<br>
          -   unsigned int rxbufs;<br>
          -   greth_rxtxdesc *txdesc;<br>
          -   greth_rxtxdesc *rxdesc;<br>
          -   unsigned int txdesc_remote;<br>
          -   unsigned int rxdesc_remote;<br>
          -   struct mbuf **rxmbuf;<br>
          -   struct mbuf **txmbuf;<br>
          -   rtems_vector_number vector;<br>
          -   <br>
          -   /* TX descriptor interrupt generation */<br>
          -   int tx_int_gen;<br>
          -   int tx_int_gen_cur;<br>
          -   struct mbuf *next_tx_mbuf;<br>
          -   int max_fragsize;<br>
          -   <br>
          -   /*Status*/<br>
          -   struct phy_device_info phydev;<br>
          -   int phy_read_access;<br>
          -   int phy_write_access;<br>
          -   int fd;<br>
          -   int sp;<br>
          -   int gb;<br>
          -   int gbit_mac;<br>
          -   int auto_neg;<br>
          -   unsigned int advmodes; /* advertise ethernet speed modes.
          0 = all modes. */<br>
          -   struct timespec auto_neg_time;<br>
          -   int mc_available;<br>
          -<br>
          -   /*<br>
          -    * Statistics<br>
          -    */<br>
          -   unsigned long rxInterrupts;<br>
          -   <br>
          -   unsigned long rxPackets;<br>
          -   unsigned long rxLengthError;<br>
          -   unsigned long rxNonOctet;<br>
          -   unsigned long rxBadCRC;<br>
          -   unsigned long rxOverrun;<br>
          -   <br>
          -   unsigned long txInterrupts;<br>
          -   <br>
          -   unsigned long txDeferred;<br>
          -   unsigned long txHeartbeat;<br>
          -   unsigned long txLateCollision;<br>
          -   unsigned long txRetryLimit;<br>
          -   unsigned long txUnderrun;<br>
          -<br>
          -   /* Spin-lock ISR protection */<br>
          -   SPIN_DECLARE(devlock);<br>
          -};<br>
          -<br>
          -int greth_process_tx_gbit(struct greth_softc *sc);<br>
          -int greth_process_tx(struct greth_softc *sc);<br>
          -<br>
          -static char *almalloc(int sz, int alignment)<br>
          -{<br>
          -        char *tmp;<br>
          -        tmp = grlib_calloc(1, sz + (alignment-1));<br>
          -        tmp = (char *) (((int)tmp+alignment) &
          ~(alignment -1));<br>
          -        return(tmp);<br>
          -}<br>
          -<br>
          -/* GRETH interrupt handler */<br>
          -<br>
          -static void greth_interrupt (void *arg)<br>
          -{<br>
          -        uint32_t status;<br>
          -        uint32_t ctrl;<br>
          -        rtems_event_set events = 0;<br>
          -        struct greth_softc *greth = arg;<br>
          -        SPIN_ISR_IRQFLAGS(flags);<br>
          -<br>
          -        /* read and clear interrupt cause */<br>
          -        status = greth->regs->status;<br>
          -        greth->regs->status = status;<br>
          -<br>
          -        SPIN_LOCK(&greth->devlock, flags);<br>
          -        ctrl = greth->regs->ctrl;<br>
          -<br>
          -        /* Frame received? */<br>
          -        if ((ctrl & GRETH_CTRL_RXIRQ) && (status
          & (GRETH_STATUS_RXERR | GRETH_STATUS_RXIRQ)))<br>
          -        {<br>
          -                greth->rxInterrupts++;<br>
          -                /* Stop RX-Error and RX-Packet interrupts */<br>
          -                ctrl &= ~GRETH_CTRL_RXIRQ;<br>
          -                events |= INTERRUPT_EVENT;<br>
          -        }<br>
          -<br>
          -        if ( (ctrl & GRETH_CTRL_TXIRQ) && (status
          & (GRETH_STATUS_TXERR | GRETH_STATUS_TXIRQ)) )<br>
          -        {<br>
          -                greth->txInterrupts++;<br>
          -                ctrl &= ~GRETH_CTRL_TXIRQ;<br>
          -                events |= GRETH_TX_WAIT_EVENT;<br>
          -        }<br>
          -<br>
          -        /* Clear interrupt sources */<br>
          -        greth->regs->ctrl = ctrl;<br>
          -        SPIN_UNLOCK(&greth->devlock, flags);<br>
          -<br>
          -        /* Send the event(s) */<br>
          -        if ( events )<br>
          -            rtems_bsdnet_event_send(greth->daemonTid,
          events);<br>
          -}<br>
          -<br>
          -static uint32_t read_mii(struct greth_softc *sc, uint32_t
          phy_addr, uint32_t reg_addr)<br>
          -{<br>
          -    sc->phy_read_access++;<br>
          -    while (sc->regs->mdio_ctrl & GRETH_MDIO_BUSY)
          {}<br>
          -    sc->regs->mdio_ctrl = (phy_addr << 11) |
          (reg_addr << 6) | GRETH_MDIO_READ;<br>
          -    while (sc->regs->mdio_ctrl & GRETH_MDIO_BUSY)
          {}<br>
          -    if (!(sc->regs->mdio_ctrl &
          GRETH_MDIO_LINKFAIL)) {<br>
          -        MIIDBG("greth%d: mii read[%d] OK to %" PRIx32 ".%"
          PRIx32<br>
          -               " (0x%08" PRIx32 ",0x%08" PRIx32 ")\n",<br>
          -               sc->minor, sc->phy_read_access,
          phy_addr, reg_addr,<br>
          -               sc->regs->ctrl,
          sc->regs->mdio_ctrl);<br>
          -        return((sc->regs->mdio_ctrl >> 16) &
          0xFFFF);<br>
          -    } else {<br>
          -        printf("greth%d: mii read[%d] failed to %" PRIx32
          ".%" PRIx32<br>
          -               " (0x%08" PRIx32 ",0x%08" PRIx32 ")\n",<br>
          -               sc->minor, sc->phy_read_access,
          phy_addr, reg_addr,<br>
          -               sc->regs->ctrl,
          sc->regs->mdio_ctrl);<br>
          -        return (0xffff);<br>
          -    }<br>
          -}<br>
          -<br>
          -static void write_mii(struct greth_softc *sc, uint32_t
          phy_addr, uint32_t reg_addr, uint32_t data)<br>
          -{<br>
          -    sc->phy_write_access++;<br>
          -    while (sc->regs->mdio_ctrl & GRETH_MDIO_BUSY)
          {}<br>
          -    sc->regs->mdio_ctrl =<br>
          -     ((data & 0xFFFF) << 16) | (phy_addr <<
          11) | (reg_addr << 6) | GRETH_MDIO_WRITE;<br>
          -    while (sc->regs->mdio_ctrl & GRETH_MDIO_BUSY)
          {}<br>
          -    if (!(sc->regs->mdio_ctrl &
          GRETH_MDIO_LINKFAIL)) {<br>
          -        MIIDBG("greth%d: mii write[%d] OK to  to %" PRIx32
          ".%" PRIx32<br>
          -               "(0x%08" PRIx32 ",0x%08" PRIx32 ")\n",<br>
          -               sc->minor, sc->phy_write_access,
          phy_addr, reg_addr,<br>
          -               sc->regs->ctrl,
          sc->regs->mdio_ctrl);<br>
          -    } else {<br>
          -        printf("greth%d: mii write[%d] failed to to %" PRIx32
          ".%" PRIx32<br>
          -               " (0x%08" PRIx32 ",0x%08" PRIx32 ")\n",<br>
          -               sc->minor, sc->phy_write_access,
          phy_addr, reg_addr,<br>
          -               sc->regs->ctrl,
          sc->regs->mdio_ctrl);<br>
          -    }<br>
          -}<br>
          -<br>
          -static void print_init_info(struct greth_softc *sc) <br>
          -{<br>
          -    printf("greth: driver attached\n");<br>
          -    if ( sc->auto_neg == -1 ){<br>
          -        printf("Auto negotiation timed out. Selecting default
          config\n");<br>
          -    }<br>
          -    printf("**** PHY ****\n");<br>
          -    printf("Vendor: %x   Device: %x   Revision:
          %d\n",sc->phydev.vendor, sc->phydev.device,
          sc->phydev.rev);<br>
          -    printf("Current Operating Mode: ");<br>
          -    if (sc->gb) {<br>
          -        printf("1000 Mbit ");<br>
          -    } else if (sc->sp) {<br>
          -        printf("100 Mbit ");<br>
          -    } else {<br>
          -        printf("10 Mbit ");<br>
          -    }<br>
          -    if (sc->fd) {<br>
          -        printf("Full Duplex\n");<br>
          -    } else {<br>
          -        printf("Half Duplex\n");<br>
          -    }<br>
          -#ifdef GRETH_AUTONEGO_PRINT_TIME<br>
          -    if ( sc->auto_neg ) {<br>
          -        printf("Autonegotiation Time: %" PRIdMAX "ms\n",<br>
          -               (intmax_t)sc->auto_neg_time.tv_sec * 1000 +<br>
          -               sc->auto_neg_time.tv_nsec / 1000000);<br>
          -    }<br>
          -#endif<br>
          -}<br>
          -<br>
          -/*<br>
          - * Generates the hash words based on CRCs of the enabled MAC
          addresses that are<br>
          - * allowed to be received. The allowed MAC addresses are
          maintained in a linked<br>
          - * "multi-cast" list available in the arpcom structure.<br>
          - *<br>
          - * Returns the number of MAC addresses that were processed
          (in the list)<br>
          - */<br>
          -static int<br>
          -greth_mac_filter_calc(struct arpcom *ac, uint32_t *msb,
          uint32_t *lsb)<br>
          -{<br>
          -    struct ether_multistep step;<br>
          -    struct ether_multi *enm;<br>
          -    int cnt = 0;<br>
          -    uint32_t crc, htindex, ht[2] = {0, 0};<br>
          -<br>
          -    /* Go through the Ethernet Multicast addresses one by one
          and add their<br>
          -     * CRC contribution to the MAC filter.<br>
          -     */<br>
          -    ETHER_FIRST_MULTI(step, ac, enm);<br>
          -    while (enm) {<br>
          -        crc = ether_crc32_be((uint8_t *)enm->enm_addrlo,
          6);<br>
          -        htindex = crc & 0x3f;<br>
          -        ht[htindex >> 5] |= (1 << (htindex &
          0x1F));<br>
          -        cnt++;<br>
          -        ETHER_NEXT_MULTI(step, enm);<br>
          -    }<br>
          -<br>
          -    if (cnt > 0) {<br>
          -        *msb = ht[1];<br>
          -        *lsb = ht[0];<br>
          -    }<br>
          -<br>
          -    return cnt;<br>
          -}<br>
          -<br>
          -/*<br>
          - * Initialize the ethernet hardware<br>
          - */<br>
          -static int greth_mac_filter_set(struct greth_softc *sc)<br>
          -{<br>
          -    struct ifnet *ifp = &sc->arpcom.ac_if;<br>
          -    uint32_t hash_msb, hash_lsb, ctrl;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -<br>
          -    hash_msb = 0;<br>
          -    hash_lsb = 0;<br>
          -    ctrl = 0;<br>
          -    if (ifp->if_flags & IFF_PROMISC) {<br>
          -        /* No need to enable multi-cast when promiscous mode
          accepts all */<br>
          -        ctrl |= GRETH_CTRL_PRO;<br>
          -    } else if(!sc->mc_available) {<br>
          -        return EINVAL; /* no hardware support for multicast
          filtering. */<br>
          -    } else if (ifp->if_flags & IFF_ALLMULTI) {<br>
          -        /* We should accept all multicast addresses */<br>
          -        ctrl |= GRETH_CTRL_MCE;<br>
          -        hash_msb = 0xFFFFFFFF;<br>
          -        hash_lsb = 0xFFFFFFFF;<br>
          -    } else if (greth_mac_filter_calc(&sc->arpcom,
          &hash_msb, &hash_lsb) > 0) {<br>
          -        /* Generate hash for MAC filtering out multicast
          addresses */<br>
          -        ctrl |= GRETH_CTRL_MCE;<br>
          -    } else {<br>
          -        /* Multicast list is empty .. disable multicast */<br>
          -    }<br>
          -    SPIN_LOCK_IRQ(&sc->devlock, flags);<br>
          -    sc->regs->ht_msb = hash_msb;<br>
          -    sc->regs->ht_lsb = hash_lsb;<br>
          -    sc->regs->ctrl = (sc->regs->ctrl &
          ~(GRETH_CTRL_PRO | GRETH_CTRL_MCE)) |<br>
          -                     ctrl;<br>
          -    SPIN_UNLOCK_IRQ(&sc->devlock, flags);<br>
          -<br>
          -    return 0;<br>
          -}<br>
          -<br>
          -/*<br>
          - * Initialize the ethernet hardware<br>
          - */<br>
          -static void<br>
          -greth_initialize_hardware (struct greth_softc *sc)<br>
          -{<br>
          -    struct mbuf *m;<br>
          -    int i;<br>
          -    int phyaddr;<br>
          -    int phyctrl;<br>
          -    int phystatus;<br>
          -    int tmp1;<br>
          -    int tmp2;<br>
          -    struct timespec tstart, tnow;<br>
          -    greth_regs *regs;<br>
          -    unsigned int advmodes, speed;<br>
          -<br>
          -    regs = sc->regs;<br>
          -<br>
          -    /* Reset the controller.  */<br>
          -    sc->rxInterrupts = 0;<br>
          -    sc->rxPackets = 0;<br>
          -<br>
          -    if (sc->greth_rst) {<br>
          -        /* Reset ON */<br>
          -        regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD |
          GRETH_CTRL_ED;<br>
          -        for (i = 0; i<100 && (regs->ctrl &
          GRETH_CTRL_RST); i++)<br>
          -            ;<br>
          -        speed = 0; /* probe mode below */<br>
          -    } else {<br>
          -        /* inherit EDCL mode for now */<br>
          -        speed = sc->regs->ctrl &
          (GRETH_CTRL_GB|GRETH_CTRL_SP|GRETH_CTRL_FULLD);<br>
          -    }<br>
          -    /* Reset OFF and RX/TX DMA OFF. SW do PHY Init */<br>
          -    regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED | speed;<br>
          -<br>
          -    /* Check if mac is gbit capable*/<br>
          -    sc->gbit_mac = (regs->ctrl >> 27) & 1;<br>
          -<br>
          -    /* Get the phy address which assumed to have been set<br>
          -       correctly with the reset value in hardware*/<br>
          -    if ( sc->phyaddr == -1 ) {<br>
          -        phyaddr = (regs->mdio_ctrl >> 11) &
          0x1F;<br>
          -    } else {<br>
          -        phyaddr = sc->phyaddr;<br>
          -    }<br>
          -    sc->phy_read_access = 0;<br>
          -    sc->phy_write_access = 0;<br>
          -<br>
          -    /* As I understand the PHY comes back to a good default
          state after<br>
          -     * Power-down or Reset, so we do both just in case.
          Power-down bit should<br>
          -     * be cleared.<br>
          -     * Wait for old reset (if asserted by boot loader) to
          complete, otherwise<br>
          -     * power-down instruction might not have any effect.<br>
          -     */<br>
          -    while (read_mii(sc, phyaddr, 0) & 0x8000) {}<br>
          -    write_mii(sc, phyaddr, 0, 0x0800); /* Power-down */<br>
          -    write_mii(sc, phyaddr, 0, 0x0000); /* Power-Up */<br>
          -    write_mii(sc, phyaddr, 0, 0x8000); /* Reset */<br>
          -<br>
          -    /* We wait about 30ms */<br>
          -   
          rtems_task_wake_after(rtems_clock_get_ticks_per_second()/32);<br>
          -<br>
          -    /* Wait for reset to complete and get default values */<br>
          -    while ((phyctrl = read_mii(sc, phyaddr, 0)) & 0x8000)
          {}<br>
          -<br>
          -    /* Set up PHY advertising modes for auto-negotiation */<br>
          -    advmodes = sc->advmodes;<br>
          -    if (advmodes == 0)<br>
          -        advmodes = GRETH_ADV_ALL;<br>
          -    if (!sc->gbit_mac)<br>
          -        advmodes &= ~(GRETH_ADV_1000_FD |
          GRETH_ADV_1000_HD);<br>
          -<br>
          -    /* Enable/Disable GBit auto-neg advetisement so that the
          link partner<br>
          -     * know that we have/haven't GBit capability. The MAC may
          not support<br>
          -     * Gbit even though PHY does...<br>
          -     */<br>
          -    phystatus = read_mii(sc, phyaddr, 1);<br>
          -    if (phystatus & 0x0100) {<br>
          -        tmp1 = read_mii(sc, phyaddr, 9);<br>
          -        tmp1 &= ~0x300;<br>
          -        if (advmodes & GRETH_ADV_1000_FD)<br>
          -            tmp1 |= 0x200;<br>
          -        if (advmodes & GRETH_ADV_1000_HD)<br>
          -            tmp1 |= 0x100;<br>
          -        write_mii(sc, phyaddr, 9, tmp1);<br>
          -    }<br>
          -<br>
          -    /* Optionally limit the 10/100 modes as configured by
          user */<br>
          -    tmp1 = read_mii(sc, phyaddr, 4);<br>
          -    tmp1 &= ~0x1e0;<br>
          -    if (advmodes & GRETH_ADV_100_FD)<br>
          -        tmp1 |= 0x100;<br>
          -    if (advmodes & GRETH_ADV_100_HD)<br>
          -        tmp1 |= 0x080;<br>
          -    if (advmodes & GRETH_ADV_10_FD)<br>
          -        tmp1 |= 0x040;<br>
          -    if (advmodes & GRETH_ADV_10_HD)<br>
          -        tmp1 |= 0x020;<br>
          -    write_mii(sc, phyaddr, 4, tmp1);<br>
          -<br>
          -    /* If autonegotiation implemented we start it */<br>
          -    if (phystatus & 0x0008) {<br>
          -        write_mii(sc, phyaddr, 0, phyctrl | 0x1200);<br>
          -        phyctrl = read_mii(sc, phyaddr, 0);<br>
          -    }<br>
          -<br>
          -    /* Check if PHY is autoneg capable and then determine
          operating mode, <br>
          -       otherwise force it to 10 Mbit halfduplex */<br>
          -    sc->gb = 0;<br>
          -    sc->fd = 0;<br>
          -    sc->sp = 0;<br>
          -    sc->auto_neg = 0;<br>
          -    timespecclear(&sc->auto_neg_time);<br>
          -    if ((phyctrl >> 12) & 1) {<br>
          -            /*wait for auto negotiation to complete*/<br>
          -            sc->auto_neg = 1;<br>
          -            if (rtems_clock_get_uptime(&tstart) !=
          RTEMS_SUCCESSFUL)<br>
          -                    printk("rtems_clock_get_uptime
          failed\n");<br>
          -            while (!(((phystatus = read_mii(sc, phyaddr, 1))
          >> 5) & 1)) {<br>
          -                    if (rtems_clock_get_uptime(&tnow) !=
          RTEMS_SUCCESSFUL)<br>
          -                            printk("rtems_clock_get_uptime
          failed\n");<br>
          -                    timespecsub(&tnow, &tstart,
          &sc->auto_neg_time);<br>
          -                    if
          (timespeccmp(&sc->auto_neg_time, &greth_tan, >))
          {<br>
          -                            sc->auto_neg = -1; /* Failed
          */<br>
          -                            tmp1 = read_mii(sc, phyaddr, 0);<br>
          -                            sc->gb = ((phyctrl >> 6)
          & 1) && !((phyctrl >> 13) & 1);<br>
          -                            sc->sp = !((phyctrl >>
          6) & 1) && ((phyctrl >> 13) & 1);<br>
          -                            sc->fd = (phyctrl >> 8)
          & 1;<br>
          -                            goto auto_neg_done;<br>
          -                    }<br>
          -                    /* Wait about 30ms, time is PHY dependent
          */<br>
          -                   
          rtems_task_wake_after(rtems_clock_get_ticks_per_second()/32);<br>
          -            }<br>
          -            sc->phydev.adv = read_mii(sc, phyaddr, 4);<br>
          -            sc->phydev.part = read_mii(sc, phyaddr, 5);<br>
          -            if ((phystatus >> 8) & 1) {<br>
          -                    sc->phydev.extadv = read_mii(sc,
          phyaddr, 9);<br>
          -                    sc->phydev.extpart = read_mii(sc,
          phyaddr, 10);<br>
          -                       if ( (sc->phydev.extadv &
          GRETH_MII_EXTADV_1000HD) &&<br>
          -                            (sc->phydev.extpart &
          GRETH_MII_EXTPRT_1000HD)) {<br>
          -                               sc->gb = 1;<br>
          -                               sc->fd = 0;<br>
          -                       }<br>
          -                       if ( (sc->phydev.extadv &
          GRETH_MII_EXTADV_1000FD) &&<br>
          -                            (sc->phydev.extpart &
          GRETH_MII_EXTPRT_1000FD)) {<br>
          -                               sc->gb = 1;<br>
          -                               sc->fd = 1;<br>
          -                       }<br>
          -            }<br>
          -            if ((sc->gb == 0) || ((sc->gb == 1)
          && (sc->gbit_mac == 0))) {<br>
          -                    if ( (sc->phydev.adv &
          GRETH_MII_100TXFD) &&<br>
          -                         (sc->phydev.part &
          GRETH_MII_100TXFD)) {<br>
          -                            sc->sp = 1;<br>
          -                            sc->fd = 1;<br>
          -                    } else if ( (sc->phydev.adv &
          GRETH_MII_100TXHD) &&<br>
          -                                (sc->phydev.part &
          GRETH_MII_100TXHD)) {<br>
          -                            sc->sp = 1;<br>
          -                            sc->fd = 0;<br>
          -                    } else if ( (sc->phydev.adv &
          GRETH_MII_10FD) &&<br>
          -                                (sc->phydev.part &
          GRETH_MII_10FD)) {<br>
          -                            sc->fd = 1;<br>
          -                    }<br>
          -            }<br>
          -    }<br>
          -auto_neg_done:<br>
          -    sc->phydev.vendor = 0;<br>
          -    sc->phydev.device = 0;<br>
          -    sc->phydev.rev = 0;<br>
          -    phystatus = read_mii(sc, phyaddr, 1);<br>
          -<br>
          -    /* Read out PHY info if extended registers are available
          */<br>
          -    if (phystatus & 1) {  <br>
          -            tmp1 = read_mii(sc, phyaddr, 2);<br>
          -            tmp2 = read_mii(sc, phyaddr, 3);<br>
          -<br>
          -            sc->phydev.vendor = (tmp1 << 6) | ((tmp2
          >> 10) & 0x3F);<br>
          -            sc->phydev.rev = tmp2 & 0xF;<br>
          -            sc->phydev.device = (tmp2 >> 4) &
          0x3F;<br>
          -    }<br>
          -<br>
          -    /* Force to 10 mbit half duplex if the 10/100 MAC is used
          with a 1000 PHY */<br>
          -    if (((sc->gb) && !(sc->gbit_mac)) ||
          !((phyctrl >> 12) & 1)) {<br>
          -        write_mii(sc, phyaddr, 0, sc->sp << 13);<br>
          -<br>
          -        /* check if marvell 88EE1111 PHY. Needs special reset
          handling */<br>
          -        if ((phystatus & 1) &&
          (sc->phydev.vendor == 0x005043) &&<br>
          -            (sc->phydev.device == 0x0C))<br>
          -            write_mii(sc, phyaddr, 0, 0x8000);<br>
          -<br>
          -        sc->gb = 0;<br>
          -        sc->sp = 0;<br>
          -        sc->fd = 0;<br>
          -    }<br>
          -    while ((read_mii(sc, phyaddr, 0)) & 0x8000) {}<br>
          -<br>
          -    if (sc->greth_rst) {<br>
          -        /* Reset ON */<br>
          -        regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD |
          GRETH_CTRL_ED;<br>
          -        for (i = 0; i < 100 && (regs->ctrl
          & GRETH_CTRL_RST); i++)<br>
          -            ;<br>
          -    }<br>
          -    /* Reset OFF. Set mode matching PHY settings. */<br>
          -    speed = (sc->gb << 8) | (sc->sp << 7) |
          (sc->fd << 4);<br>
          -    regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis | speed;<br>
          -<br>
          -    /* Initialize rx/tx descriptor table pointers. Due to
          alignment we <br>
          -     * always allocate maximum table size.<br>
          -     */<br>
          -    sc->txdesc = (greth_rxtxdesc *) almalloc(0x800,
          0x400);<br>
          -    sc->rxdesc = (greth_rxtxdesc *)
          &sc->txdesc[128];<br>
          -    sc->tx_ptr = 0;<br>
          -    sc->tx_dptr = 0;<br>
          -    sc->tx_cnt = 0;<br>
          -    sc->rx_ptr = 0;<br>
          -<br>
          -    /* Translate the Descriptor DMA table base address into
          an address that<br>
          -     * the GRETH core can understand<br>
          -     */<br>
          -    drvmgr_translate_check(<br>
          -        sc->dev,<br>
          -        CPUMEM_TO_DMA,<br>
          -        (void *)sc->txdesc,<br>
          -        (void **)&sc->txdesc_remote,<br>
          -        0x800);<br>
          -    sc->rxdesc_remote = sc->txdesc_remote + 0x400;<br>
          -    regs->txdesc = (int) sc->txdesc_remote;<br>
          -    regs->rxdesc = (int) sc->rxdesc_remote;<br>
          -<br>
          -    sc->rxmbuf = grlib_calloc(sc->rxbufs,
          sizeof(*sc->rxmbuf));<br>
          -    sc->txmbuf = grlib_calloc(sc->txbufs,
          sizeof(*sc->txmbuf));<br>
          -<br>
          -    for (i = 0; i < sc->txbufs; i++)<br>
          -      {<br>
          -        sc->txdesc[i].ctrl = 0;<br>
          -        if (!(sc->gbit_mac)) {<br>
          -            drvmgr_translate_check(<br>
          -                sc->dev, <br>
          -                CPUMEM_TO_DMA,<br>
          -                (void *)grlib_malloc(GRETH_MAXBUF_LEN),<br>
          -                (void **)&sc->txdesc[i].addr,<br>
          -                GRETH_MAXBUF_LEN);<br>
          -        }<br>
          -#ifdef GRETH_DEBUG<br>
          -              /* printf("TXBUF: %08x\n", (int)
          sc->txdesc[i].addr); */<br>
          -#endif<br>
          -      }<br>
          -    for (i = 0; i < sc->rxbufs; i++)<br>
          -      {<br>
          -         MGETHDR (m, M_WAIT, MT_DATA);<br>
          -          MCLGET (m, M_WAIT);<br>
          -          if (sc->gbit_mac)<br>
          -                  m->m_data += 2;<br>
          -         m->m_pkthdr.rcvif = &sc->arpcom.ac_if;<br>
          -          sc->rxmbuf[i] = m;<br>
          -          drvmgr_translate_check(<br>
          -            sc->dev,<br>
          -            CPUMEM_TO_DMA,<br>
          -            (void *)mtod(m, uint32_t *),<br>
          -            (void **)&sc->rxdesc[i].addr,<br>
          -            GRETH_MAXBUF_LEN);<br>
          -          sc->rxdesc[i].ctrl = GRETH_RXD_ENABLE |
          GRETH_RXD_IRQ;<br>
          -#ifdef GRETH_DEBUG<br>
          -/*       printf("RXBUF: %08x\n", (int)
          sc->rxdesc[i].addr); */<br>
          -#endif<br>
          -      }<br>
          -    sc->rxdesc[sc->rxbufs - 1].ctrl |= GRETH_RXD_WRAP;<br>
          -<br>
          -    /* set ethernet address.  */<br>
          -    regs->mac_addr_msb = <br>
          -      sc->arpcom.ac_enaddr[0] << 8 |
          sc->arpcom.ac_enaddr[1];<br>
          -    regs->mac_addr_lsb = <br>
          -      sc->arpcom.ac_enaddr[2] << 24 |
          sc->arpcom.ac_enaddr[3] << 16 |<br>
          -      sc->arpcom.ac_enaddr[4] << 8 |
          sc->arpcom.ac_enaddr[5];<br>
          -<br>
          -    if ( sc->rxbufs < 10 ) {<br>
          -        sc->tx_int_gen = sc->tx_int_gen_cur = 1;<br>
          -    }else{<br>
          -        sc->tx_int_gen = sc->tx_int_gen_cur =
          sc->txbufs/2;<br>
          -    }<br>
          -    sc->next_tx_mbuf = NULL;<br>
          -<br>
          -    if ( !sc->gbit_mac )<br>
          -        sc->max_fragsize = 1;<br>
          -<br>
          -    /* clear all pending interrupts */<br>
          -    regs->status = 0xffffffff;<br>
          -<br>
          -    /* install interrupt handler */<br>
          -    drvmgr_interrupt_register(sc->dev, 0, "greth",
          greth_interrupt, sc);<br>
          -<br>
          -    regs->ctrl |= GRETH_CTRL_RXEN | GRETH_CTRL_RXIRQ;<br>
          -<br>
          -    print_init_info(sc);<br>
          -}<br>
          -<br>
          -#ifdef CPU_U32_FIX<br>
          -<br>
          -/*<br>
          - * Routine to align the received packet so that the ip header<br>
          - * is on a 32-bit boundary. Necessary for cpu's that do not<br>
          - * allow unaligned loads and stores and when the 32-bit DMA<br>
          - * mode is used.<br>
          - *<br>
          - * Transfers are done on word basis to avoid possibly slow
          byte<br>
          - * and half-word writes.<br>
          - */<br>
          -<br>
          -void ipalign(struct mbuf *m)<br>
          -{<br>
          -  unsigned int *first, *last, data;<br>
          -  unsigned int tmp = 0;<br>
          -<br>
          -  if ((((int) m->m_data) & 2) &&
          (m->m_len)) {<br>
          -    last = (unsigned int *) ((((int) m->m_data) +
          m->m_len + 8) & ~3);<br>
          -    first = (unsigned int *) (((int) m->m_data) & ~3);<br>
          -               /* tmp = *first << 16; */<br>
          -               asm volatile (" lda [%1] 1, %0\n" : "=r"(tmp)
          : "r"(first) );<br>
          -               tmp = tmp << 16;<br>
          -    first++;<br>
          -    do {<br>
          -                       /* When snooping is not available the
          LDA instruction must be used<br>
          -                        * to avoid the cache to return an
          illegal value.<br>
          -                        ** Load with forced cache miss<br>
          -                        * data = *first; <br>
          -                        */<br>
          -      asm volatile (" lda [%1] 1, %0\n" : "=r"(data) :
          "r"(first) );<br>
          -      *first = tmp | (data >> 16);<br>
          -      tmp = data << 16;<br>
          -      first++;<br>
          -    } while (first <= last);<br>
          -<br>
          -    m->m_data = (caddr_t)(((int) m->m_data) + 2);<br>
          -  }<br>
          -}<br>
          -#endif<br>
          -<br>
          -static void<br>
          -greth_Daemon (void *arg)<br>
          -{<br>
          -    struct ether_header *eh;<br>
          -    struct greth_softc *dp = (struct greth_softc *) arg;<br>
          -    struct ifnet *ifp = &dp->arpcom.ac_if;<br>
          -    struct mbuf *m;<br>
          -    unsigned int len, len_status, bad;<br>
          -    rtems_event_set events;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -    int first;<br>
          -    int tmp;<br>
          -    unsigned int addr;<br>
          -<br>
          -    for (;;)<br>
          -      {<br>
          -        rtems_bsdnet_event_receive (INTERRUPT_EVENT |
          GRETH_TX_WAIT_EVENT,<br>
          -                                    RTEMS_WAIT |
          RTEMS_EVENT_ANY,<br>
          -                                    RTEMS_NO_TIMEOUT,
          &events);<br>
          -        <br>
          -        if ( events & GRETH_TX_WAIT_EVENT ){<br>
          -            /* TX interrupt.<br>
          -             * We only end up here when all TX descriptors
          has been used,<br>
          -             * and <br>
          -             */<br>
          -            if ( dp->gbit_mac )<br>
          -                greth_process_tx_gbit(dp);<br>
          -            else<br>
          -                greth_process_tx(dp);<br>
          -            <br>
          -            /* If we didn't get a RX interrupt we don't
          process it */<br>
          -            if ( (events & INTERRUPT_EVENT) == 0 )<br>
          -                continue;<br>
          -        }<br>
          -        <br>
          -        <br>
          -#ifdef GRETH_ETH_DEBUG<br>
          -    printf ("r\n");<br>
          -#endif<br>
          -    first=1;<br>
          -    /* Scan for Received packets */<br>
          -again:<br>
          -    while (!((len_status =<br>
          -                 
           GRETH_MEM_LOAD(&dp->rxdesc[dp->rx_ptr].ctrl)) &
          GRETH_RXD_ENABLE))<br>
          -           {<br>
          -                    bad = 0;<br>
          -                    if (len_status & GRETH_RXD_TOOLONG)<br>
          -                    {<br>
          -                            dp->rxLengthError++;<br>
          -                            bad = 1;<br>
          -                    }<br>
          -                    if (len_status & GRETH_RXD_DRIBBLE)<br>
          -                    {<br>
          -                            dp->rxNonOctet++;<br>
          -                            bad = 1;<br>
          -                    }<br>
          -                    if (len_status & GRETH_RXD_CRCERR)<br>
          -                    {<br>
          -                            dp->rxBadCRC++;<br>
          -                            bad = 1;<br>
          -                    }<br>
          -                    if (len_status & GRETH_RXD_OVERRUN)<br>
          -                    {<br>
          -                            dp->rxOverrun++;<br>
          -                            bad = 1;<br>
          -                    }<br>
          -                    if (len_status & GRETH_RXD_LENERR)<br>
          -                    {<br>
          -                            dp->rxLengthError++;<br>
          -                            bad = 1;<br>
          -                    }<br>
          -                    if (!bad)<br>
          -                    {<br>
          -                            /* pass on the packet in the
          receive buffer */<br>
          -                            len = len_status & 0x7FF;<br>
          -                            m = dp->rxmbuf[dp->rx_ptr];<br>
          -#ifdef GRETH_DEBUG<br>
          -                            int i;<br>
          -                            printf("RX: 0x%08x, Len: %d : ",
          (int) m->m_data, len);<br>
          -                            for (i=0; i<len; i++)<br>
          -                                    printf("%x%x",
          (m->m_data[i] >> 4) & 0x0ff, m->m_data[i]
          & 0x0ff);<br>
          -                            printf("\n");<br>
          -#endif<br>
          -                            m->m_len = m->m_pkthdr.len
          =<br>
          -                                    len - sizeof (struct
          ether_header);<br>
          -<br>
          -                            eh = mtod (m, struct ether_header
          *);<br>
          -<br>
          -                            m->m_data += sizeof (struct
          ether_header);<br>
          -#ifdef CPU_U32_FIX<br>
          -                            if(!dp->gbit_mac) {<br>
          -                                    /* OVERRIDE CACHED
          ETHERNET HEADER FOR NON-SNOOPING SYSTEMS */<br>
          -                                    addr = (unsigned int)eh;<br>
          -                                    asm volatile (" lda [%1]
          1, %0\n" : "=r"(tmp) : "r"(addr) );<br>
          -                                    addr+=4;<br>
          -                                    asm volatile (" lda [%1]
          1, %0\n" : "=r"(tmp) : "r"(addr) );<br>
          -                                    addr+=4;<br>
          -                                    asm volatile (" lda [%1]
          1, %0\n" : "=r"(tmp) : "r"(addr) );<br>
          -                                    addr+=4;<br>
          -                                    asm volatile (" lda [%1]
          1, %0\n" : "=r"(tmp) : "r"(addr) );<br>
          -<br>
          -                                    ipalign(m);        /*
          Align packet on 32-bit boundary */<br>
          -                            }<br>
          -#endif<br>
          -/*<br>
          -                            if(!(dp->gbit_mac) &&
          !CPU_SPARC_HAS_SNOOPING) {<br>
          -                                   
          rtems_cache_invalidate_entire_data();<br>
          -                            }<br>
          -*/<br>
          -                            ether_input (ifp, eh, m);<br>
          -                            MGETHDR (m, M_WAIT, MT_DATA);<br>
          -                            MCLGET (m, M_WAIT);<br>
          -                            if (dp->gbit_mac)<br>
          -                                    m->m_data += 2;<br>
          -                            dp->rxmbuf[dp->rx_ptr] = m;<br>
          -                            m->m_pkthdr.rcvif = ifp;<br>
          -                            drvmgr_translate_check(<br>
          -                                dp->dev,<br>
          -                                CPUMEM_TO_DMA,<br>
          -                                (void *)mtod (m, uint32_t *),<br>
          -                                (void
          **)&dp->rxdesc[dp->rx_ptr].addr,<br>
          -                                GRETH_MAXBUF_LEN);<br>
          -                            dp->rxPackets++;<br>
          -                    }<br>
          -                    if (dp->rx_ptr == dp->rxbufs - 1) {<br>
          -                            dp->rxdesc[dp->rx_ptr].ctrl
          = GRETH_RXD_ENABLE | GRETH_RXD_IRQ | GRETH_RXD_WRAP;<br>
          -                    } else {<br>
          -                            dp->rxdesc[dp->rx_ptr].ctrl
          = GRETH_RXD_ENABLE | GRETH_RXD_IRQ;<br>
          -                    }<br>
          -                    SPIN_LOCK_IRQ(&dp->devlock,
          flags);<br>
          -                    dp->regs->ctrl |= GRETH_CTRL_RXEN;<br>
          -                    SPIN_UNLOCK_IRQ(&dp->devlock,
          flags);<br>
          -                    dp->rx_ptr = (dp->rx_ptr + 1) %
          dp->rxbufs;<br>
          -            }<br>
          -<br>
          -        /* Always scan twice to avoid deadlock */<br>
          -        if ( first ){<br>
          -            first=0;<br>
          -            SPIN_LOCK_IRQ(&dp->devlock, flags);<br>
          -            dp->regs->ctrl |= GRETH_CTRL_RXIRQ;<br>
          -            SPIN_UNLOCK_IRQ(&dp->devlock, flags);<br>
          -            goto again;<br>
          -        }<br>
          -<br>
          -      }<br>
          -}<br>
          -<br>
          -static int<br>
          -sendpacket (struct ifnet *ifp, struct mbuf *m)<br>
          -{<br>
          -    struct greth_softc *dp = ifp->if_softc;<br>
          -    unsigned char *temp;<br>
          -    struct mbuf *n;<br>
          -    unsigned int len;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -<br>
          -    /*<br>
          -     * Is there a free descriptor available?<br>
          -     */<br>
          -    if
          (GRETH_MEM_LOAD(&dp->txdesc[dp->tx_ptr].ctrl) &
          GRETH_TXD_ENABLE){<br>
          -            /* No. */<br>
          -            return 1;<br>
          -    }<br>
          -    <br>
          -    /* Remember head of chain */<br>
          -    n = m;<br>
          -<br>
          -    len = 0;<br>
          -    temp = (unsigned char *)
          GRETH_MEM_LOAD(&dp->txdesc[dp->tx_ptr].addr);<br>
          -    drvmgr_translate(dp->dev, CPUMEM_FROM_DMA, (void
          *)temp, (void **)&temp);<br>
          -#ifdef GRETH_DEBUG<br>
          -    printf("TXD: 0x%08x : BUF: 0x%08x\n", (int) m->m_data,
          (int) temp);<br>
          -#endif<br>
          -    for (;;)<br>
          -    {<br>
          -#ifdef GRETH_DEBUG<br>
          -            int i;<br>
          -            printf("MBUF: 0x%08x : ", (int) m->m_data);<br>
          -            for (i=0;i<m->m_len;i++)<br>
          -                    printf("%x%x", (m->m_data[i] >>
          4) & 0x0ff, m->m_data[i] & 0x0ff);<br>
          -            printf("\n");<br>
          -#endif<br>
          -            len += m->m_len;<br>
          -            if (len <= RBUF_SIZE)<br>
          -                    memcpy ((void *) temp, (char *)
          m->m_data, m->m_len);<br>
          -            temp += m->m_len;<br>
          -            if ((m = m->m_next) == NULL)<br>
          -                    break;<br>
          -    }<br>
          -<br>
          -    m_freem (n);<br>
          -<br>
          -    /* don't send long packets */<br>
          -<br>
          -    if (len <= GRETH_MAXBUF_LEN) {<br>
          -            if (dp->tx_ptr < dp->txbufs-1) {<br>
          -                    dp->txdesc[dp->tx_ptr].ctrl =
          GRETH_TXD_IRQ |<br>
          -                                                 
          GRETH_TXD_ENABLE | len;<br>
          -            } else {<br>
          -                    dp->txdesc[dp->tx_ptr].ctrl =
          GRETH_TXD_IRQ |<br>
          -                            GRETH_TXD_WRAP | GRETH_TXD_ENABLE
          | len;<br>
          -            }<br>
          -            dp->tx_ptr = (dp->tx_ptr + 1) %
          dp->txbufs;<br>
          -            SPIN_LOCK_IRQ(&dp->devlock, flags);<br>
          -            dp->regs->ctrl = dp->regs->ctrl |
          GRETH_CTRL_TXEN;<br>
          -            SPIN_UNLOCK_IRQ(&dp->devlock, flags);<br>
          -    }<br>
          -<br>
          -    return 0;<br>
          -}<br>
          -<br>
          -<br>
          -static int<br>
          -sendpacket_gbit (struct ifnet *ifp, struct mbuf *m)<br>
          -{<br>
          -        struct greth_softc *dp = ifp->if_softc;<br>
          -        unsigned int len;<br>
          -        <br>
          -        unsigned int ctrl;<br>
          -        int frags;<br>
          -        struct mbuf *mtmp;<br>
          -        int int_en;<br>
          -        SPIN_IRQFLAGS(flags);<br>
          -<br>
          -        len = 0;<br>
          -#ifdef GRETH_DEBUG<br>
          -        printf("TXD: 0x%08x\n", (int) m->m_data);<br>
          -#endif<br>
          -        /* Get number of fragments too see if we have enough<br>
          -         * resources.<br>
          -         */<br>
          -        frags=1;<br>
          -        mtmp=m;<br>
          -        while(mtmp->m_next){<br>
          -            frags++;<br>
          -            mtmp = mtmp->m_next;<br>
          -        }<br>
          -<br>
          -        if ( frags > dp->max_fragsize ) <br>
          -            dp->max_fragsize = frags;<br>
          -        <br>
          -        if ( frags > dp->txbufs ){<br>
          -            printf("GRETH: MBUF-chain cannot be sent.
          Increase descriptor count.\n");<br>
          -            return -1;<br>
          -        }<br>
          -        <br>
          -        if ( frags > (dp->txbufs-dp->tx_cnt) ){<br>
          -            /* Return number of fragments */<br>
          -            return frags;<br>
          -        }<br>
          -        <br>
          -        <br>
          -        /* Enable interrupt from descriptor every tx_int_gen<br>
          -         * descriptor. Typically every 16 descriptor. This<br>
          -         * is only to reduce the number of interrupts during<br>
          -         * heavy load.<br>
          -         */<br>
          -        dp->tx_int_gen_cur-=frags;<br>
          -        if ( dp->tx_int_gen_cur <= 0 ){<br>
          -            dp->tx_int_gen_cur = dp->tx_int_gen;<br>
          -            int_en = GRETH_TXD_IRQ;<br>
          -        }else{<br>
          -            int_en = 0;<br>
          -        }<br>
          -        <br>
          -        /* At this stage we know that enough descriptors are
          available */<br>
          -        for (;;)<br>
          -        {<br>
          -                <br>
          -#ifdef GRETH_DEBUG<br>
          -            int i;<br>
          -            printf("MBUF: 0x%08x, Len: %d : ", (int)
          m->m_data, m->m_len);<br>
          -            for (i=0; i<m->m_len; i++)<br>
          -                printf("%x%x", (m->m_data[i] >> 4)
          & 0x0ff, m->m_data[i] & 0x0ff);<br>
          -            printf("\n");<br>
          -#endif<br>
          -            len += m->m_len;<br>
          -            drvmgr_translate_check(<br>
          -                dp->dev,<br>
          -                CPUMEM_TO_DMA,<br>
          -                (void *)(uint32_t *)m->m_data,<br>
          -                (void
          **)&dp->txdesc[dp->tx_ptr].addr,<br>
          -                m->m_len);<br>
          -<br>
          -            /* Wrap around? */<br>
          -            if (dp->tx_ptr < dp->txbufs-1) {<br>
          -                ctrl = GRETH_TXD_ENABLE;<br>
          -            }else{<br>
          -                ctrl = GRETH_TXD_ENABLE | GRETH_TXD_WRAP;<br>
          -            }<br>
          -<br>
          -            /* Enable Descriptor */  <br>
          -            if ((m->m_next) == NULL) {<br>
          -                dp->txdesc[dp->tx_ptr].ctrl = ctrl |
          int_en | m->m_len;<br>
          -                break;<br>
          -            }else{<br>
          -                dp->txdesc[dp->tx_ptr].ctrl =
          GRETH_TXD_MORE | ctrl | int_en | m->m_len;<br>
          -            }<br>
          -<br>
          -            /* Next */<br>
          -            dp->txmbuf[dp->tx_ptr] = m;<br>
          -            dp->tx_ptr = (dp->tx_ptr + 1) %
          dp->txbufs;<br>
          -            dp->tx_cnt++;<br>
          -            m = m->m_next;<br>
          -        }<br>
          -        dp->txmbuf[dp->tx_ptr] = m;<br>
          -        dp->tx_ptr = (dp->tx_ptr + 1) % dp->txbufs;<br>
          -        dp->tx_cnt++;<br>
          -      <br>
          -        /* Tell Hardware about newly enabled descriptor */<br>
          -        SPIN_LOCK_IRQ(&dp->devlock, flags);<br>
          -        dp->regs->ctrl = dp->regs->ctrl |
          GRETH_CTRL_TXEN;<br>
          -        SPIN_UNLOCK_IRQ(&dp->devlock, flags);<br>
          -<br>
          -        return 0;<br>
          -}<br>
          -<br>
          -int greth_process_tx_gbit(struct greth_softc *sc)<br>
          -{<br>
          -    struct ifnet *ifp = &sc->arpcom.ac_if;<br>
          -    struct mbuf *m;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -    int first=1;<br>
          -<br>
          -    /*<br>
          -     * Send packets till queue is empty<br>
          -     */<br>
          -    for (;;){<br>
          -        /* Reap Sent packets */<br>
          -        while((sc->tx_cnt > 0) &&
          !(GRETH_MEM_LOAD(&sc->txdesc[sc->tx_dptr].ctrl)
          & GRETH_TXD_ENABLE)) {<br>
          -            m_free(sc->txmbuf[sc->tx_dptr]);<br>
          -            sc->tx_dptr = (sc->tx_dptr + 1) %
          sc->txbufs;<br>
          -            sc->tx_cnt--;<br>
          -        }<br>
          -        <br>
          -        if ( sc->next_tx_mbuf ){<br>
          -            /* Get packet we tried but faild to transmit last
          time */<br>
          -            m = sc->next_tx_mbuf;<br>
          -            sc->next_tx_mbuf = NULL; /* Mark packet taken
          */<br>
          -        }else{<br>
          -            /*<br>
          -             * Get the next mbuf chain to transmit from
          Stack.<br>
          -             */<br>
          -            IF_DEQUEUE (&ifp->if_snd, m);<br>
          -            if (!m){<br>
          -                /* Hardware has sent all schedule packets,
          this<br>
          -                 * makes the stack enter at greth_start next
          time<br>
          -                 * a packet is to be sent.<br>
          -                 */<br>
          -                ifp->if_flags &= ~IFF_OACTIVE;<br>
          -                break;<br>
          -            }<br>
          -        }<br>
          -<br>
          -        /* Are there free descriptors available? */<br>
          -        /* Try to send packet, if it a negative number is
          returned. */<br>
          -        if ( (sc->tx_cnt >= sc->txbufs) ||
          sendpacket_gbit(ifp, m) ){<br>
          -            /* Not enough resources */<br>
          -             <br>
          -            /* Since we have taken the mbuf out of the "send
          chain"<br>
          -             * we must remember to use that next time we come
          back.<br>
          -             * or else we have dropped a packet.<br>
          -             */<br>
          -            sc->next_tx_mbuf = m;<br>
          -            <br>
          -            /* Not enough resources, enable interrupt for
          transmissions<br>
          -             * this way we will be informed when more
          TX-descriptors are <br>
          -             * available.<br>
          -             */<br>
          -            if ( first ){<br>
          -                first = 0;<br>
          -                SPIN_LOCK_IRQ(&sc->devlock, flags);<br>
          -                ifp->if_flags |= IFF_OACTIVE;<br>
          -                sc->regs->ctrl |= GRETH_CTRL_TXIRQ;<br>
          -                SPIN_UNLOCK_IRQ(&sc->devlock, flags);<br>
          -                <br>
          -                /* We must check again to be sure that we
          didn't <br>
          -                 * miss an interrupt (if a packet was sent
          just before<br>
          -                 * enabling interrupts)<br>
          -                 */<br>
          -                continue;<br>
          -            }<br>
          -<br>
          -            return -1;<br>
          -        }else{<br>
          -            /* Sent Ok, proceed to process more packets if
          available */<br>
          -        }<br>
          -    }<br>
          -    return 0;<br>
          -}<br>
          -<br>
          -int greth_process_tx(struct greth_softc *sc)<br>
          -{<br>
          -    struct ifnet *ifp = &sc->arpcom.ac_if;<br>
          -    struct mbuf *m;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -    int first=1;<br>
          -<br>
          -    /*<br>
          -     * Send packets till queue is empty<br>
          -     */<br>
          -    for (;;){<br>
          -        if ( sc->next_tx_mbuf ){<br>
          -            /* Get packet we tried but failed to transmit
          last time */<br>
          -            m = sc->next_tx_mbuf;<br>
          -            sc->next_tx_mbuf = NULL; /* Mark packet taken
          */<br>
          -        }else{<br>
          -            /*<br>
          -             * Get the next mbuf chain to transmit from
          Stack.<br>
          -             */<br>
          -            IF_DEQUEUE (&ifp->if_snd, m);<br>
          -            if (!m){<br>
          -                /* Hardware has sent all schedule packets,
          this<br>
          -                 * makes the stack enter at greth_start next
          time<br>
          -                 * a packet is to be sent.<br>
          -                 */<br>
          -                ifp->if_flags &= ~IFF_OACTIVE;<br>
          -                break;<br>
          -            }<br>
          -        }<br>
          -<br>
          -        /* Try to send packet, failed if it a non-zero number
          is returned. */<br>
          -        if ( sendpacket(ifp, m) ){<br>
          -            /* Not enough resources */<br>
          -             <br>
          -            /* Since we have taken the mbuf out of the "send
          chain"<br>
          -             * we must remember to use that next time we come
          back.<br>
          -             * or else we have dropped a packet.<br>
          -             */<br>
          -            sc->next_tx_mbuf = m;<br>
          -            <br>
          -            /* Not enough resources, enable interrupt for
          transmissions<br>
          -             * this way we will be informed when more
          TX-descriptors are <br>
          -             * available.<br>
          -             */<br>
          -            if ( first ){<br>
          -                first = 0;<br>
          -                SPIN_LOCK_IRQ(&sc->devlock, flags);<br>
          -                ifp->if_flags |= IFF_OACTIVE;<br>
          -                sc->regs->ctrl |= GRETH_CTRL_TXIRQ;<br>
          -                SPIN_UNLOCK_IRQ(&sc->devlock, flags);<br>
          -<br>
          -                /* We must check again to be sure that we
          didn't <br>
          -                 * miss an interrupt (if a packet was sent
          just before<br>
          -                 * enabling interrupts)<br>
          -                 */<br>
          -                continue;<br>
          -            }<br>
          -<br>
          -            return -1;<br>
          -        }else{<br>
          -            /* Sent Ok, proceed to process more packets if
          available */<br>
          -        }<br>
          -    }<br>
          -    return 0;<br>
          -}<br>
          -<br>
          -static void<br>
          -greth_start (struct ifnet *ifp)<br>
          -{<br>
          -    struct greth_softc *sc = ifp->if_softc;<br>
          -    <br>
          -    if ( ifp->if_flags & IFF_OACTIVE )<br>
          -            return;<br>
          -    <br>
          -    if ( sc->gbit_mac ){<br>
          -        /* No use trying to handle this if we are waiting on
          GRETH<br>
          -         * to send the previously scheduled packets.<br>
          -         */<br>
          -        <br>
          -        greth_process_tx_gbit(sc);<br>
          -    }else{<br>
          -        greth_process_tx(sc);<br>
          -    }<br>
          -    <br>
          -}<br>
          -<br>
          -/*<br>
          - * Initialize and start the device<br>
          - */<br>
          -static void<br>
          -greth_init (void *arg)<br>
          -{<br>
          -    struct greth_softc *sc = arg;<br>
          -    struct ifnet *ifp = &sc->arpcom.ac_if;<br>
          -    char name[4] = {'E', 'T', 'H', '0'};<br>
          -<br>
          -    if (sc->daemonTid == 0)<br>
          -      {<br>
          -          /*<br>
          -           * Start driver tasks<br>
          -           */<br>
          -          name[3] += sc->minor;<br>
          -          sc->daemonTid = rtems_bsdnet_newproc (name,
          4096,<br>
          -                                                greth_Daemon,
          sc);<br>
          -<br>
          -          /*<br>
          -           * Set up GRETH hardware<br>
          -           */<br>
          -          greth_initialize_hardware (sc);<br>
          -      }<br>
          -<br>
          -    /*<br>
          -     * Setup promiscous/multi-cast MAC address filters if
          user enabled it<br>
          -     */<br>
          -    greth_mac_filter_set(sc);<br>
          -<br>
          -    /*<br>
          -     * Tell the world that we're running.<br>
          -     */<br>
          -    ifp->if_flags |= IFF_RUNNING;<br>
          -}<br>
          -<br>
          -/*<br>
          - * Stop the device<br>
          - */<br>
          -static void<br>
          -greth_stop (struct greth_softc *sc)<br>
          -{<br>
          -    struct ifnet *ifp = &sc->arpcom.ac_if;<br>
          -    SPIN_IRQFLAGS(flags);<br>
          -    unsigned int speed;<br>
          -<br>
          -    SPIN_LOCK_IRQ(&sc->devlock, flags);<br>
          -    ifp->if_flags &= ~IFF_RUNNING;<br>
          -<br>
          -    speed = sc->regs->ctrl & (GRETH_CTRL_GB |
          GRETH_CTRL_SP | GRETH_CTRL_FULLD);<br>
          -<br>
          -    /* RX/TX OFF */<br>
          -    sc->regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED |
          speed;<br>
          -    /* Reset ON */<br>
          -    if (sc->greth_rst)<br>
          -        sc->regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD
          | GRETH_CTRL_ED | speed;<br>
          -    /* Reset OFF and restore link settings previously
          detected if any */<br>
          -    sc->regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis |
          speed;<br>
          -    SPIN_UNLOCK_IRQ(&sc->devlock, flags);<br>
          -<br>
          -    sc->next_tx_mbuf = NULL;<br>
          -}<br>
          -<br>
          -<br>
          -/*<br>
          - * Show interface statistics<br>
          - */<br>
          -static void<br>
          -greth_stats (struct greth_softc *sc)<br>
          -{<br>
          -  printf ("      Rx Interrupts:%-8lu", sc->rxInterrupts);<br>
          -  printf ("      Rx Packets:%-8lu", sc->rxPackets);<br>
          -  printf ("          Length:%-8lu", sc->rxLengthError);<br>
          -  printf ("       Non-octet:%-8lu\n", sc->rxNonOctet);<br>
          -  printf ("            Bad CRC:%-8lu", sc->rxBadCRC);<br>
          -  printf ("         Overrun:%-8lu", sc->rxOverrun);<br>
          -  printf ("      Tx Interrupts:%-8lu", sc->txInterrupts);<br>
          -  printf ("      Maximal Frags:%-8d", sc->max_fragsize);<br>
          -  printf ("      GBIT MAC:%-8d", sc->gbit_mac);<br>
          -}<br>
          -<br>
          -/*<br>
          - * Driver ioctl handler<br>
          - */<br>
          -static int<br>
          -greth_ioctl (struct ifnet *ifp, ioctl_command_t command,
          caddr_t data)<br>
          -{<br>
          -    struct greth_softc *sc = ifp->if_softc;<br>
          -    int error = 0;<br>
          -    struct ifreq *ifr;<br>
          -<br>
          -    switch (command)<br>
          -      {<br>
          -      case SIOCGIFADDR:<br>
          -      case SIOCSIFADDR:<br>
          -         ether_ioctl (ifp, command, data);<br>
          -         break;<br>
          -<br>
          -      case SIOCSIFFLAGS:<br>
          -         switch (ifp->if_flags & (IFF_UP |
          IFF_RUNNING))<br>
          -           {<br>
          -           case IFF_RUNNING:<br>
          -               greth_stop (sc);<br>
          -                break;<br>
          -<br>
          -           case IFF_UP:<br>
          -               greth_init (sc);<br>
          -               break;<br>
          -<br>
          -           case IFF_UP | IFF_RUNNING:<br>
          -               greth_stop (sc);<br>
          -               greth_init (sc);<br>
          -               break;<br>
          -       default:<br>
          -               break;<br>
          -           }<br>
          -         break;<br>
          -<br>
          -      case SIO_RTEMS_SHOW_STATS:<br>
          -         greth_stats (sc);<br>
          -         break;<br>
          -<br>
          -         /*<br>
          -          * Multicast commands: Enabling/disabling filtering
          of MAC addresses<br>
          -          */<br>
          -      case SIOCADDMULTI:<br>
          -      case SIOCDELMULTI:<br>
          -      ifr = (struct ifreq *)data;<br>
          -      if (command == SIOCADDMULTI) {<br>
          -        error = ether_addmulti(ifr, &sc->arpcom);<br>
          -      } else {<br>
          -        error = ether_delmulti(ifr, &sc->arpcom);<br>
          -      }<br>
          -      if (error == ENETRESET) {<br>
          -        error = greth_mac_filter_set(sc);<br>
          -      }<br>
          -      break;<br>
          -<br>
          -      default:<br>
          -         error = EINVAL;<br>
          -         break;<br>
          -      }<br>
          -<br>
          -    return error;<br>
          -}<br>
          -<br>
          -/*<br>
          - * Attach an GRETH driver to the system<br>
          - */<br>
          -static int<br>
          -greth_interface_driver_attach (<br>
          -    struct rtems_bsdnet_ifconfig *config,<br>
          -    int attach<br>
          -    )<br>
          -{<br>
          -    struct greth_softc *sc;<br>
          -    struct ifnet *ifp;<br>
          -    int mtu;<br>
          -    int unitNumber;<br>
          -    char *unitName;<br>
          -    <br>
          -      /* parse driver name */<br>
          -    if ((unitNumber = rtems_bsdnet_parse_driver_name (config,
          &unitName)) < 0)<br>
          -       return 0;<br>
          -<br>
          -    sc = config->drv_ctrl;<br>
          -    ifp = &sc->arpcom.ac_if;<br>
          -#ifdef GRETH_DEBUG<br>
          -    printf("GRETH[%d]: %s, sc %p, dev %p on %s\n",
          unitNumber, config->ip_address, sc, sc->dev,
          sc->dev->parent->dev->name);<br>
          -#endif<br>
          -    if (config->hardware_address)<br>
          -      {<br>
          -         memcpy (sc->arpcom.ac_enaddr,
          config->hardware_address,<br>
          -                 ETHER_ADDR_LEN);<br>
          -      }<br>
          -    else<br>
          -      {<br>
          -         memset (sc->arpcom.ac_enaddr, 0x08,
          ETHER_ADDR_LEN);<br>
          -      }<br>
          -<br>
          -    if (config->mtu)<br>
          -       mtu = config->mtu;<br>
          -    else<br>
          -       mtu = ETHERMTU;<br>
          -<br>
          -    sc->acceptBroadcast = !config->ignore_broadcast;<br>
          -<br>
          -    /*<br>
          -     * Set up network interface values<br>
          -     */<br>
          -    ifp->if_softc = sc;<br>
          -    ifp->if_unit = unitNumber;<br>
          -    ifp->if_name = unitName;<br>
          -    ifp->if_mtu = mtu;<br>
          -    ifp->if_init = greth_init;<br>
          -    ifp->if_ioctl = greth_ioctl;<br>
          -    ifp->if_start = greth_start;<br>
          -    ifp->if_output = ether_output;<br>
          -    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;<br>
          -    if (sc->mc_available)<br>
          -        ifp->if_flags |= IFF_MULTICAST;<br>
          -    if (ifp->if_snd.ifq_maxlen == 0)<br>
          -       ifp->if_snd.ifq_maxlen = ifqmaxlen;<br>
          -<br>
          -    /*<br>
          -     * Attach the interface<br>
          -     */<br>
          -    if_attach (ifp);<br>
          -    ether_ifattach (ifp);<br>
          -<br>
          -#ifdef GRETH_DEBUG<br>
          -    printf ("GRETH : driver has been attached\n");<br>
          -#endif<br>
          -    return 1;<br>
          -}<br>
          -<br>
          -/******************* Driver manager interface
          ***********************/<br>
          -<br>
          -/* Driver prototypes */<br>
          -int greth_register_io(rtems_device_major_number *m);<br>
          -int greth_device_init(struct greth_softc *sc);<br>
          -int network_interface_add(struct rtems_bsdnet_ifconfig
          *interface);<br>
          -<br>
          -#ifdef GRETH_INFO_AVAIL<br>
          -static int greth_info(<br>
          -       struct drvmgr_dev *dev,<br>
          -       void (*print_line)(void *p, char *str),<br>
          -       void *p, int argc, char *argv[]);<br>
          -#define GRETH_INFO_FUNC greth_info<br>
          -#else<br>
          -#define GRETH_INFO_FUNC NULL<br>
          -#endif<br>
          -<br>
          -int greth_init2(struct drvmgr_dev *dev);<br>
          -int greth_init3(struct drvmgr_dev *dev);<br>
          -<br>
          -struct drvmgr_drv_ops greth_ops = <br>
          -{<br>
          -       .init   =<br>
          -               {<br>
          -                       NULL,<br>
          -                       greth_init2,<br>
          -                       greth_init3,<br>
          -                       NULL<br>
          -               },<br>
          -       .remove = NULL,<br>
          -       .info = GRETH_INFO_FUNC,<br>
          -};<br>
          -<br>
          -struct amba_dev_id greth_ids[] = <br>
          -{<br>
          -       {VENDOR_GAISLER, GAISLER_ETHMAC},<br>
          -       {0, 0}          /* Mark end of table */<br>
          -};<br>
          -<br>
          -struct amba_drv_info greth_drv_info =<br>
          -{<br>
          -       {<br>
          -               DRVMGR_OBJ_DRV,                 /* Driver */<br>
          -               NULL,                           /* Next driver
          */<br>
          -               NULL,                           /* Device list
          */<br>
          -               DRIVER_AMBAPP_GAISLER_GRETH_ID, /* Driver ID
          */<br>
          -               "GRETH_DRV",                    /* Driver Name
          */<br>
          -               DRVMGR_BUS_TYPE_AMBAPP,         /* Bus Type */<br>
          -               &greth_ops,<br>
          -               NULL,                           /* Funcs */<br>
          -               0,                              /* No devices
          yet */<br>
          -               0,<br>
          -       },<br>
          -       &greth_ids[0]<br>
          -};<br>
          -<br>
          -void greth_register_drv (void)<br>
          -{<br>
          -       DBG("Registering GRETH driver\n");<br>
          -       drvmgr_drv_register(&greth_drv_info.general);<br>
          -}<br>
          -<br>
          -int greth_init2(struct drvmgr_dev *dev)<br>
          -{<br>
          -       struct greth_softc *priv;<br>
          -<br>
          -       DBG("GRETH[%d] on bus %s\n", dev->minor_drv,
          dev->parent->dev->name);<br>
          -       priv = dev->priv = grlib_calloc(1, sizeof(*priv));<br>
          -       if ( !priv )<br>
          -               return DRVMGR_NOMEM;<br>
          -       priv->dev = dev;<br>
          -<br>
          -       /* This core will not find other cores, so we wait for
          init3() */<br>
          -<br>
          -       return DRVMGR_OK;<br>
          -}<br>
          -<br>
          -int greth_init3(struct drvmgr_dev *dev)<br>
          -{<br>
          -    struct greth_softc *sc;<br>
          -    struct rtems_bsdnet_ifconfig *ifp;<br>
          -    rtems_status_code status;<br>
          -<br>
          -    sc = dev->priv;<br>
          -    sprintf(sc->devName, "gr_eth%d",
          (dev->minor_drv+1));<br>
          -<br>
          -    /* Init GRETH device */<br>
          -    if ( greth_device_init(sc) ) {<br>
          -        printk("GRETH: Failed to init device\n");<br>
          -        return DRVMGR_FAIL;<br>
          -    }<br>
          -<br>
          -    /* Initialize Spin-lock for GRSPW Device. This is to
          protect<br>
          -     * CTRL and DMACTRL registers from ISR.<br>
          -     */<br>
          -    SPIN_INIT(&sc->devlock, sc->devName);<br>
          -<br>
          -    /* Register GRETH device as an Network interface */<br>
          -    ifp = grlib_calloc(1, sizeof(*ifp));<br>
          -<br>
          -    ifp->name = sc->devName;<br>
          -    ifp->drv_ctrl = sc;<br>
          -    ifp->attach = greth_interface_driver_attach;<br>
          -<br>
          -    status = network_interface_add(ifp);<br>
          -    if (status != 0) {<br>
          -        return DRVMGR_FAIL;<br>
          -    }<br>
          -<br>
          -    return DRVMGR_OK;<br>
          -}<br>
          -<br>
          -int greth_device_init(struct greth_softc *sc)<br>
          -{<br>
          -    struct amba_dev_info *ambadev;<br>
          -    struct ambapp_core *pnpinfo;<br>
          -    union drvmgr_key_value *value;<br>
          -    unsigned int speed;<br>
          -<br>
          -    /* Get device information from AMBA PnP information */<br>
          -    ambadev = (struct amba_dev_info *)sc->dev->businfo;<br>
          -    if ( ambadev == NULL ) {<br>
          -        return -1;<br>
          -    }<br>
          -    pnpinfo = &ambadev->info;<br>
          -    sc->regs = (greth_regs
          *)pnpinfo->apb_slv->start;<br>
          -    sc->minor = sc->dev->minor_drv;<br>
          -    sc->greth_rst = 1;<br>
          -<br>
          -    /* Remember EDCL enabled/disable state before reset */<br>
          -    sc->edcl_dis = sc->regs->ctrl &
          GRETH_CTRL_ED;<br>
          -<br>
          -    /* Default is to inherit EDCL Disable bit from HW. User
          can force En/Dis */<br>
          -    value = drvmgr_dev_key_get(sc->dev, "edclDis",
          DRVMGR_KT_INT);<br>
          -    if ( value ) {<br>
          -        /* Force EDCL mode. Has an effect later when
          GRETH+PHY is initialized */<br>
          -        if (value->i > 0) {<br>
          -            sc->edcl_dis = GRETH_CTRL_ED;<br>
          -        } else {<br>
          -            /* Default to avoid soft-reset the GRETH when
          EDCL is forced */<br>
          -            sc->edcl_dis = 0;<br>
          -            sc->greth_rst = 0;<br>
          -       }<br>
          -    }<br>
          -<br>
          -    /* let user control soft-reset of GRETH (for debug) */<br>
          -    value = drvmgr_dev_key_get(sc->dev, "soft-reset",
          DRVMGR_KT_INT);<br>
          -    if ( value) {<br>
          -        sc->greth_rst = value->i ? 1 : 0;<br>
          -    }<br>
          -<br>
          -    /* clear control register and reset NIC and keep current
          speed modes.<br>
          -     * This should be done as quick as possible during
          startup, this is to<br>
          -     * stop DMA transfers after a reboot.<br>
          -     *<br>
          -     * When EDCL is forced enabled reset is skipped,
          disabling RX/TX DMA is<br>
          -     * is enough during debug.<br>
          -     */<br>
          -    speed = sc->regs->ctrl & (GRETH_CTRL_GB |
          GRETH_CTRL_SP | GRETH_CTRL_FULLD);<br>
          -    sc->regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED |
          speed;<br>
          -    if (sc->greth_rst)<br>
          -        sc->regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD
          | GRETH_CTRL_ED | speed;<br>
          -    sc->regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis |
          speed;<br>
          -<br>
          -    /* Configure driver by overriding default config with the
          bus resources <br>
          -     * configured by the user<br>
          -     */<br>
          -    sc->txbufs = 32;<br>
          -    sc->rxbufs = 32;<br>
          -    sc->phyaddr = -1;<br>
          -<br>
          -    value = drvmgr_dev_key_get(sc->dev, "txDescs",
          DRVMGR_KT_INT);<br>
          -    if ( value && (value->i <= 128) )<br>
          -        sc->txbufs = value->i;<br>
          -<br>
          -    value = drvmgr_dev_key_get(sc->dev, "rxDescs",
          DRVMGR_KT_INT);<br>
          -    if ( value && (value->i <= 128) )<br>
          -        sc->rxbufs = value->i;<br>
          -<br>
          -    value = drvmgr_dev_key_get(sc->dev, "phyAdr",
          DRVMGR_KT_INT);<br>
          -    if ( value && (value->i < 32) )<br>
          -        sc->phyaddr = value->i;<br>
          -<br>
          -    value = drvmgr_dev_key_get(sc->dev, "advModes",
          DRVMGR_KT_INT);<br>
          -    if ( value )<br>
          -        sc->advmodes = value->i;<br>
          -<br>
          -    /* Check if multicast support is available */<br>
          -    sc->mc_available = sc->regs->ctrl &
          GRETH_CTRL_MC;<br>
          -<br>
          -    return 0;<br>
          -}<br>
          -<br>
          -#ifdef GRETH_INFO_AVAIL<br>
          -static int greth_info(<br>
          -       struct drvmgr_dev *dev,<br>
          -       void (*print_line)(void *p, char *str),<br>
          -       void *p, int argc, char *argv[])<br>
          -{<br>
          -       struct greth_softc *sc;<br>
          -       char buf[64];<br>
          -<br>
          -       if (dev->priv == NULL)<br>
          -               return -DRVMGR_EINVAL;<br>
          -       sc = dev->priv;<br>
          -<br>
          -       sprintf(buf, "IFACE NAME:  %s", sc->devName);<br>
          -       print_line(p, buf);<br>
          -       sprintf(buf, "GBIT MAC:    %s", sc->gbit_mac ?
          "YES" : "NO");<br>
          -       print_line(p, buf);<br>
          -<br>
          -       return DRVMGR_OK;<br>
          -}<br>
          -#endif<br>
          -<br>
          -#endif<br>
          diff --git a/bsps/shared/grlib/net/network_interface_add.c
          b/bsps/shared/grlib/net/network_interface_add.c<br>
          deleted file mode 100644<br>
          index 011137404f..0000000000<br>
          --- a/bsps/shared/grlib/net/network_interface_add.c<br>
          +++ /dev/null<br>
          @@ -1,62 +0,0 @@<br>
          -/*  Network interface register help function<br>
          - * <br>
          - *  COPYRIGHT (c) 2008.<br>
          - *  Cobham Gaisler AB.<br>
          - *<br>
          - *  This function adds a network interface to the <br>
          - *  rtems_bsdnet_config.ifconfig linked list of interfaces.<br>
          - *  The interface configuration is taken from the user
          defined<br>
          - *  array interface_configs. This function is useful for PnP<br>
          - *  systems when an unknown number of interfaces are
          available.<br>
          - *<br>
          - *  The license and distribution terms for this file may be<br>
          - *  found in found in the file LICENSE in this distribution
          or at<br>
          - *  <a href="http://www.rtems.org/license/LICENSE"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">http://www.rtems.org/license/LICENSE</a>.<br>
          - */<br>
          -<br>
          -#include <rtems/rtems_bsdnet.h><br>
          -#include <stdio.h><br>
          -<br>
          -#include <grlib/network_interface_add.h><br>
          -<br>
          -extern struct rtems_bsdnet_config rtems_bsdnet_config;<br>
          -<br>
          -/* Number of interfaces taken */<br>
          -int network_interface_cnt = 0;<br>
          -<br>
          -int network_interface_add(struct rtems_bsdnet_ifconfig
          *interface)<br>
          -{<br>
          -       struct ethernet_config *cfg = NULL;<br>
          -       int i, last_entry = 1;<br>
          -<br>
          -       /* Init interface description */<br>
          -       interface->next = NULL;<br>
          -<br>
          -       cfg = &interface_configs[network_interface_cnt];<br>
          -       for(i=0; i<6; i++) {<br>
          -               if ( cfg->eth_adr[i] != 0 ) {<br>
          -                       last_entry = 0;<br>
          -                       break;<br>
          -               }<br>
          -       }<br>
          -       /* Do we have a valid configuration? */<br>
          -       if ( last_entry == 0 ) {<br>
          -               cfg =
          &interface_configs[network_interface_cnt];<br>
          -<br>
          -               interface->ip_address = cfg->ip_addr;<br>
          -               interface->ip_netmask = cfg->ip_netmask;<br>
          -               interface->hardware_address =
          cfg->eth_adr;<br>
          -<br>
          -               network_interface_cnt++;<br>
          -       } else {<br>
          -               interface->ip_address = NULL;<br>
          -               interface->ip_netmask = NULL;<br>
          -               interface->hardware_address = NULL;<br>
          -       }<br>
          -<br>
          -       /* Insert interface first into list */<br>
          -       interface->next = rtems_bsdnet_config.ifconfig;<br>
          -       rtems_bsdnet_config.ifconfig = interface;<br>
          -<br>
          -       return 0;<br>
          -}<br>
          -- <br>
          2.17.1<br>
          <br>
          _______________________________________________<br>
          devel mailing list<br>
          <a href="mailto:devel@rtems.org" target="_blank"
            rel="noreferrer" moz-do-not-send="true">devel@rtems.org</a><br>
          <a href="http://lists.rtems.org/mailman/listinfo/devel"
            rel="noreferrer noreferrer" target="_blank"
            moz-do-not-send="true">http://lists.rtems.org/mailman/listinfo/devel</a><br>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>