summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/threadresettimeslice.c
diff options
context:
space:
mode:
authorRalf Corsepius <ralf.corsepius@rtems.org>2005-01-27 05:57:05 +0000
committerRalf Corsepius <ralf.corsepius@rtems.org>2005-01-27 05:57:05 +0000
commita8eed2387c28bb56ada10f815874cc55b8d820a5 (patch)
tree88a38afe4060bea6f2c179f87ff8cfce6e359d11 /cpukit/score/src/threadresettimeslice.c
parent2005-01-26 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-a8eed2387c28bb56ada10f815874cc55b8d820a5.tar.bz2
Include config.h.
Diffstat (limited to 'cpukit/score/src/threadresettimeslice.c')
-rw-r--r--cpukit/score/src/threadresettimeslice.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/cpukit/score/src/threadresettimeslice.c b/cpukit/score/src/threadresettimeslice.c
index 64734b2e6d..ff383834df 100644
--- a/cpukit/score/src/threadresettimeslice.c
+++ b/cpukit/score/src/threadresettimeslice.c
@@ -12,6 +12,10 @@
* $Id$
*/
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <rtems/system.h>
#include <rtems/score/apiext.h>
#include <rtems/score/context.h>
: 0.0%;'/> -rw-r--r--bsps/m68k/mvme167/net/network.c3098
-rw-r--r--bsps/m68k/mvme167/net/uti596.h369
-rw-r--r--bsps/m68k/uC5282/net/network.c1013
9 files changed, 0 insertions, 10898 deletions
diff --git a/bsps/m68k/av5282/net/network.c b/bsps/m68k/av5282/net/network.c
deleted file mode 100644
index 8c37e67fd6..0000000000
--- a/bsps/m68k/av5282/net/network.c
+++ /dev/null
@@ -1,940 +0,0 @@
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <bsp.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <string.h>
-#include <rtems.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/ethernet.h>
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-
-
-/*
- * Number of interfaces supported by this driver
- */
-#define NIFACES 1
-
-#define FEC_INTC0_TX_VECTOR (64+23)
-#define FEC_INTC0_RX_VECTOR (64+27)
-
-#define FEC_INTC0_TX_VECTOR (64+23)
-#define FEC_INTC0_RX_VECTOR (64+27)
-#define MII_VECTOR (64+7) /* IRQ7* pin connected to external transceiver */
-#define MII_EPPAR MCF5282_EPORT_EPPAR_EPPA7_LEVEL
-#define MII_EPDDR MCF5282_EPORT_EPDDR_EPDD7
-#define MII_EPIER MCF5282_EPORT_EPIER_EPIE7
-#define MII_EPPDR MCF5282_EPORT_EPPDR_EPPD7
-/*
- * Default number of buffer descriptors set aside for this driver.
- * The number of transmit buffer descriptors has to be quite large
- * since a single frame often uses three or more buffer descriptors.
- */
-#define RX_BUF_COUNT 32
-#define TX_BUF_COUNT 20
-#define TX_BD_PER_BUF 3
-
-#define INET_ADDR_MAX_BUF_SIZE (sizeof "255.255.255.255")
-
-/*
- * RTEMS event used by interrupt handler to signal daemons.
- * This must *not* be the same event used by the TCP/IP task synchronization.
- */
-#define TX_INTERRUPT_EVENT RTEMS_EVENT_1
-#define RX_INTERRUPT_EVENT RTEMS_EVENT_1
-
-/*
- * RTEMS event used to start transmit daemon.
- * This must not be the same as INTERRUPT_EVENT.
- */
-#define START_TRANSMIT_EVENT RTEMS_EVENT_2
-
-/*
- * Receive buffer size -- Allow for a full ethernet packet plus CRC (1518).
- * Round off to nearest multiple of RBUF_ALIGN.
- */
-#define MAX_MTU_SIZE 1518
-#define RBUF_ALIGN 4
-#define RBUF_SIZE ((MAX_MTU_SIZE + RBUF_ALIGN) & ~RBUF_ALIGN)
-
-#if (MCLBYTES < RBUF_SIZE)
- #error "Driver must have MCLBYTES > RBUF_SIZE"
-#endif
-
-typedef struct mcf5282BufferDescriptor_ {
- volatile uint16_t status;
- uint16_t length;
- volatile void *buffer;
-} mcf5282BufferDescriptor_t;
-
-/*
- * Per-device data
- */
-struct mcf5282_enet_struct {
- struct arpcom arpcom;
- struct mbuf **rxMbuf;
- struct mbuf **txMbuf;
- int acceptBroadcast;
- int rxBdCount;
- int txBdCount;
- int txBdHead;
- int txBdTail;
- int txBdActiveCount;
- mcf5282BufferDescriptor_t *rxBdBase;
- mcf5282BufferDescriptor_t *txBdBase;
- rtems_id rxDaemonTid;
- rtems_id txDaemonTid;
-
- /*
- * Statistics
- */
- unsigned long rxInterrupts;
- unsigned long txInterrupts;
- unsigned long miiInterrupts;
- unsigned long txRawWait;
- unsigned long txRealign;
- unsigned long txRealignDrop;
- uint16_t mii_sr2;
-};
-static struct mcf5282_enet_struct enet_driver[NIFACES];
-
-static int
-getMII(int phyNumber, int regNumber);
-
-
-static rtems_isr
-mcf5282_fec_rx_interrupt_handler( rtems_vector_number v )
-{
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_RXF;
- MCF5282_FEC_EIMR &= ~MCF5282_FEC_EIMR_RXF;
- enet_driver[0].rxInterrupts++;
- rtems_bsdnet_event_send(enet_driver[0].rxDaemonTid, RX_INTERRUPT_EVENT);
-}
-
-static rtems_isr
-mcf5282_fec_tx_interrupt_handler( rtems_vector_number v )
-{
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_TXF;
- MCF5282_FEC_EIMR &= ~MCF5282_FEC_EIMR_TXF;
- enet_driver[0].txInterrupts++;
- rtems_bsdnet_event_send(enet_driver[0].txDaemonTid, TX_INTERRUPT_EVENT);
-}
-
-static rtems_isr
-mcf5282_mii_interrupt_handler( rtems_vector_number v )
-{
- uint16_t sr2;
-
- enet_driver[0].miiInterrupts++;
- getMII(1, 19); /* Read and clear interrupt status bits */
- enet_driver[0].mii_sr2 = sr2 = getMII(1, 17);
- if (((sr2 & 0x200) != 0)
- && ((MCF5282_FEC_TCR & MCF5282_FEC_TCR_FDEN) == 0))
- MCF5282_FEC_TCR |= MCF5282_FEC_TCR_FDEN;
- else if (((sr2 & 0x200) == 0)
- && ((MCF5282_FEC_TCR & MCF5282_FEC_TCR_FDEN) != 0))
- MCF5282_FEC_TCR &= ~MCF5282_FEC_TCR_FDEN;
-}
-
-/*
- * Allocate buffer descriptors from (non-cached) on-chip static RAM
- * Ensure 128-bit (16-byte) alignment
- */
-extern char __SRAMBASE[];
-
-static mcf5282BufferDescriptor_t *
-mcf5282_bd_allocate(unsigned int count)
-{
- static mcf5282BufferDescriptor_t *bdp = (mcf5282BufferDescriptor_t *)__SRAMBASE;
- mcf5282BufferDescriptor_t *p = bdp;
-
- bdp += count;
- if ((int)bdp & 0xF)
- bdp = (mcf5282BufferDescriptor_t *)((char *)bdp + (16 - ((int)bdp & 0xF)));
- return p;
-}
-
-
-/*
- * Read MII register
- * Busy-waits, but transfer time should be short!
- */
-static int
-getMII(int phyNumber, int regNumber)
-{
- MCF5282_FEC_MMFR = (0x1 << 30) |
- (0x2 << 28) |
- (phyNumber << 23) |
- (regNumber << 18) |
- (0x2 << 16);
- while ((MCF5282_FEC_EIR & MCF5282_FEC_EIR_MII) == 0);
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_MII;
- return MCF5282_FEC_MMFR & 0xFFFF;
-}
-
-
-/*
- * Write MII register
- * Busy-waits, but transfer time should be short!
- */
-static void
-setMII(int phyNumber, int regNumber, int value)
-{
- MCF5282_FEC_MMFR = (0x1 << 30) |
- (0x1 << 28) |
- (phyNumber << 23) |
- (regNumber << 18) |
- (0x2 << 16) |
- (value & 0xFFFF);
- while ((MCF5282_FEC_EIR & MCF5282_FEC_EIR_MII) == 0);
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_MII;
-}
-
-static void
-mcf5282_fec_initialize_hardware(struct mcf5282_enet_struct *sc)
-{
- int i;
- const unsigned char *hwaddr;
- rtems_status_code status;
- rtems_isr_entry old_handler;
- uint32_t clock_speed = get_CPU_clock_speed();
-
- /*
- * Issue reset to FEC
- */
- MCF5282_FEC_ECR = MCF5282_FEC_ECR_RESET;
- rtems_task_wake_after(1);
- MCF5282_FEC_ECR = 0;
-
- /*
- * Configuration of I/O ports is done outside of this function
- */
-#if 0
- imm->gpio.pbcnt |= MCF5282_GPIO_PBCNT_SET_FEC; /* Set up port b FEC pins */
-#endif
-
- /*
- * Set our physical address
- */
- hwaddr = sc->arpcom.ac_enaddr;
- MCF5282_FEC_PALR = (hwaddr[0] << 24) | (hwaddr[1] << 16) |
- (hwaddr[2] << 8) | (hwaddr[3] << 0);
- MCF5282_FEC_PAUR = (hwaddr[4] << 24) | (hwaddr[5] << 16);
-
-
- /*
- * Clear the hash table
- */
- MCF5282_FEC_GAUR = 0;
- MCF5282_FEC_GALR = 0;
-
- /*
- * Set up receive buffer size
- */
- MCF5282_FEC_EMRBR = 1520; /* Standard Ethernet */
-
- /*
- * Allocate mbuf pointers
- */
- sc->rxMbuf = malloc(sc->rxBdCount * sizeof *sc->rxMbuf, M_MBUF, M_NOWAIT);
- sc->txMbuf = malloc(sc->txBdCount * sizeof *sc->txMbuf, M_MBUF, M_NOWAIT);
- if (!sc->rxMbuf || !sc->txMbuf)
- rtems_panic("No memory for mbuf pointers");
-
- /*
- * Set receiver and transmitter buffer descriptor bases
- */
- sc->rxBdBase = mcf5282_bd_allocate(sc->rxBdCount);
- sc->txBdBase = mcf5282_bd_allocate(sc->txBdCount);
- MCF5282_FEC_ERDSR = (int)sc->rxBdBase;
- MCF5282_FEC_ETDSR = (int)sc->txBdBase;
-
- /*
- * Set up Receive Control Register:
- * Not promiscuous
- * MII mode
- * Full duplex
- * No loopback
- */
- MCF5282_FEC_RCR = MCF5282_FEC_RCR_MAX_FL(MAX_MTU_SIZE) |
- MCF5282_FEC_RCR_MII_MODE;
-
- /*
- * Set up Transmit Control Register:
- * Full duplex
- * No heartbeat
- */
- MCF5282_FEC_TCR = MCF5282_FEC_TCR_FDEN;
-
- /*
- * Initialize statistic counters
- */
- MCF5282_FEC_MIBC = MCF5282_FEC_MIBC_MIB_DISABLE;
- {
- vuint32 *vuip = &MCF5282_FEC_RMON_T_DROP;
- while (vuip <= &MCF5282_FEC_IEEE_R_OCTETS_OK)
- *vuip++ = 0;
- }
- MCF5282_FEC_MIBC = 0;
-
- /*
- * Set MII speed to <= 2.5 MHz
- */
- i = (clock_speed + 5000000 - 1) / 5000000;
- MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(i);
-
- /*
- * Set PHYS to 100 Mb/s, full duplex
- */
- setMII(1, 0, 0x2100);
- setMII(1, 4, 0x0181);
- setMII(1, 0, 0x0000);
- rtems_task_wake_after(2);
- sc->mii_sr2 = getMII(1, 17);
- setMII(1, 18, 0x0072);
- setMII(1, 0, 0x1000);
- /*
- * Set up receive buffer descriptors
- */
- for (i = 0 ; i < sc->rxBdCount ; i++)
- (sc->rxBdBase + i)->status = 0;
-
- /*
- * Set up transmit buffer descriptors
- */
- for (i = 0 ; i < sc->txBdCount ; i++) {
- sc->txBdBase[i].status = 0;
- sc->txMbuf[i] = NULL;
- }
- sc->txBdHead = sc->txBdTail = 0;
- sc->txBdActiveCount = 0;
-
- /*
- * Set up interrupts
- */
- status = rtems_interrupt_catch( mcf5282_fec_tx_interrupt_handler, FEC_INTC0_TX_VECTOR, &old_handler );
- if (status != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't attach MCF5282 FEC TX interrupt handler: %s\n",
- rtems_status_text(status));
- status = rtems_interrupt_catch(mcf5282_fec_rx_interrupt_handler, FEC_INTC0_RX_VECTOR, &old_handler);
- if (status != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't attach MCF5282 FEC RX interrupt handler: %s\n",
- rtems_status_text(status));
- MCF5282_INTC0_ICR23 = MCF5282_INTC_ICR_IL(FEC_IRQ_LEVEL) |
- MCF5282_INTC_ICR_IP(FEC_IRQ_TX_PRIORITY);
- MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT23 | MCF5282_INTC_IMRL_MASKALL);
- MCF5282_INTC0_ICR27 = MCF5282_INTC_ICR_IL(FEC_IRQ_LEVEL) |
- MCF5282_INTC_ICR_IP(FEC_IRQ_RX_PRIORITY);
- MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT27 | MCF5282_INTC_IMRL_MASKALL);
-
- status = rtems_interrupt_catch(mcf5282_mii_interrupt_handler, MII_VECTOR, &old_handler);
- if (status != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't attach MCF5282 FEC MII interrupt handler: %s\n",
- rtems_status_text(status));
- MCF5282_EPORT_EPPAR &= ~MII_EPPAR;
- MCF5282_EPORT_EPDDR &= ~MII_EPDDR;
- MCF5282_EPORT_EPIER |= MII_EPIER;
- MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT7 | MCF5282_INTC_IMRL_MASKALL);
-}
-
-/*
- * Soak up buffer descriptors that have been sent.
- */
-void
-fec_retire_tx_bd(volatile struct mcf5282_enet_struct *sc )
-{
- struct mbuf *m, *n;
- uint16_t status;
-
- while ((sc->txBdActiveCount != 0)
- && (((status = sc->txBdBase[sc->txBdTail].status) & MCF5282_FEC_TxBD_R) == 0)) {
- if ((status & MCF5282_FEC_TxBD_TO1) == 0) {
- m = sc->txMbuf[sc->txBdTail];
- MFREE(m, n);
- }
- if (++sc->txBdTail == sc->txBdCount)
- sc->txBdTail = 0;
- sc->txBdActiveCount--;
- }
-}
-
-static void
-fec_rxDaemon (void *arg)
-{
- volatile struct mcf5282_enet_struct *sc = (volatile struct mcf5282_enet_struct *)arg;
- struct ifnet *ifp = (struct ifnet* )&sc->arpcom.ac_if;
- struct mbuf *m;
- volatile uint16_t status;
- volatile mcf5282BufferDescriptor_t *rxBd;
- int rxBdIndex;
-
- /*
- * Allocate space for incoming packets and start reception
- */
- for (rxBdIndex = 0 ; ;) {
- rxBd = sc->rxBdBase + rxBdIndex;
- MGETHDR(m, M_WAIT, MT_DATA);
- MCLGET(m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod(m, void *);
- rxBd->status = MCF5282_FEC_RxBD_E;
- if (++rxBdIndex == sc->rxBdCount) {
- rxBd->status |= MCF5282_FEC_RxBD_W;
- break;
- }
- }
-
- /*
- * Input packet handling loop
- */
- /* Indicate we have some ready buffers available */
- MCF5282_FEC_RDAR = 0;
-
- rxBdIndex = 0;
- for (;;) {
- rxBd = sc->rxBdBase + rxBdIndex;
-
- /*
- * Wait for packet if there's not one ready
- */
- if ((status = rxBd->status) & MCF5282_FEC_RxBD_E) {
- /*
- * Clear old events.
- */
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_RXF;
-
- /*
- * Wait for packet to arrive.
- * Check the buffer descriptor before waiting for the event.
- * This catches the case when a packet arrives between the
- * `if' above, and the clearing of the RXF bit in the EIR.
- */
- while ((status = rxBd->status) & MCF5282_FEC_RxBD_E) {
- rtems_event_set events;
- int level;
-
- rtems_interrupt_disable(level);
- MCF5282_FEC_EIMR |= MCF5282_FEC_EIMR_RXF;
- rtems_interrupt_enable(level);
- rtems_bsdnet_event_receive (RX_INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- }
- }
-
- /*
- * Check that packet is valid
- */
- if (status & MCF5282_FEC_RxBD_L) {
- /*
- * Pass the packet up the chain.
- * FIXME: Packet filtering hook could be done here.
- */
- struct ether_header *eh;
- int len = rxBd->length - sizeof(uint32_t);
-
- /*
- * Invalidate the cache and push the packet up.
- * The cache is so small that it's more efficient to just
- * invalidate the whole thing unless the packet is very small.
- */
- m = sc->rxMbuf[rxBdIndex];
- if (len < 128)
- rtems_cache_invalidate_multiple_data_lines(m->m_data, len);
- else
- rtems_cache_invalidate_entire_data();
- m->m_len = m->m_pkthdr.len = len - sizeof(struct ether_header);
- eh = mtod(m, struct ether_header *);
- m->m_data += sizeof(struct ether_header);
- ether_input(ifp, eh, m);
-
- /*
- * Allocate a new mbuf
- */
- MGETHDR(m, M_WAIT, MT_DATA);
- MCLGET(m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod(m, void *);
- }
-
- /*
- * Reenable the buffer descriptor
- */
- rxBd->status = (status & MCF5282_FEC_RxBD_W) | MCF5282_FEC_RxBD_E;
- MCF5282_FEC_RDAR = 0;
-
- /*
- * Move to next buffer descriptor
- */
- if (++rxBdIndex == sc->rxBdCount)
- rxBdIndex = 0;
- }
-}
-
-static void
-fec_sendpacket(struct ifnet *ifp, struct mbuf *m)
-{
- struct mcf5282_enet_struct *sc = ifp->if_softc;
- volatile mcf5282BufferDescriptor_t *firstTxBd, *txBd;
- int nAdded;
- uint16_t status;
-
- /*
- * Free up buffer descriptors
- */
- fec_retire_tx_bd(sc);
-
- /*
- * Set up the transmit buffer descriptors.
- * No need to pad out short packets since the
- * hardware takes care of that automatically.
- * No need to copy the packet to a contiguous buffer
- * since the hardware is capable of scatter/gather DMA.
- */
- nAdded = 0;
- firstTxBd = sc->txBdBase + sc->txBdHead;
-
- while(m != NULL) {
- /*
- * Wait for buffer descriptor to become available
- */
- if ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- /*
- * Clear old events.
- */
- MCF5282_FEC_EIR = MCF5282_FEC_EIR_TXF;
-
- /*
- * Wait for buffer descriptor to become available.
- * Check for buffer descriptors before waiting for the event.
- * This catches the case when a buffer became available between
- * the `if' above, and the clearing of the TXF bit in the EIR.
- */
- fec_retire_tx_bd(sc);
- while ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- rtems_event_set events;
- int level;
-
- rtems_interrupt_disable(level);
- MCF5282_FEC_EIMR |= MCF5282_FEC_EIMR_TXF;
- rtems_interrupt_enable(level);
- sc->txRawWait++;
- rtems_bsdnet_event_receive(TX_INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- fec_retire_tx_bd(sc);
- }
- }
-
- /*
- * Don't set the READY flag on the first fragment
- * until the whole packet has been readied.
- */
- status = nAdded ? MCF5282_FEC_TxBD_R : 0;
-
- /*
- * The IP fragmentation routine in ip_output
- * can produce fragments with zero length.
- */
- if (m->m_len){
- char *p = mtod(m, char *);
- int offset = (int) p & 0x3;
- txBd = sc->txBdBase + sc->txBdHead;
- if (offset == 0) {
- txBd->buffer = p;
- txBd->length = m->m_len;
- sc->txMbuf[sc->txBdHead] = m;
- m = m->m_next;
- }
- else {
- /*
- * Stupid FEC can't handle misaligned data!
- * Move offending bytes to a local buffer.
- * Use buffer descriptor TO1 bit to indicate this.
- */
- int nmove = 4 - offset;
- char *d = (char *)&sc->txMbuf[sc->txBdHead];
- status |= MCF5282_FEC_TxBD_TO1;
- sc->txRealign++;
- if (nmove > m->m_len)
- nmove = m->m_len;
- m->m_data += nmove;
- m->m_len -= nmove;
- txBd->buffer = d;
- txBd->length = nmove;
- while (nmove--)
- *d++ = *p++;
- if (m->m_len == 0) {
- struct mbuf *n;
- sc->txRealignDrop++;
- MFREE(m, n);
- m = n;
- }
- }
- nAdded++;
- if (++sc->txBdHead == sc->txBdCount) {
- status |= MCF5282_FEC_TxBD_W;
- sc->txBdHead = 0;
- }
- txBd->status = status;
- }
- else {
- /*
- * Just toss empty mbufs
- */
- struct mbuf *n;
- MFREE(m, n);
- m = n;
- }
- }
- if (nAdded) {
- txBd->status = status | MCF5282_FEC_TxBD_R
- | MCF5282_FEC_TxBD_L
- | MCF5282_FEC_TxBD_TC;
- if (nAdded > 1)
- firstTxBd->status |= MCF5282_FEC_TxBD_R;
- MCF5282_FEC_TDAR = 0;
- sc->txBdActiveCount += nAdded;
- }
-}
-
-void
-fec_txDaemon(void *arg)
-{
- struct mcf5282_enet_struct *sc = (struct mcf5282_enet_struct *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mbuf *m;
- rtems_event_set events;
-
- for (;;) {
- /*
- * Wait for packet
- */
- rtems_bsdnet_event_receive(START_TRANSMIT_EVENT,
- RTEMS_EVENT_ANY | RTEMS_WAIT,
- RTEMS_NO_TIMEOUT,
- &events);
-
- /*
- * Send packets till queue is empty
- */
- for (;;) {
- /*
- * Get the next mbuf chain to transmit.
- */
- IF_DEQUEUE(&ifp->if_snd, m);
- if (!m)
- break;
- fec_sendpacket(ifp, m);
- }
- ifp->if_flags &= ~IFF_OACTIVE;
- }
-}
-
-
-/*
- * Send packet (caller provides header).
- */
-static void
-mcf5282_enet_start(struct ifnet *ifp)
-{
- struct mcf5282_enet_struct *sc = ifp->if_softc;
-
- rtems_bsdnet_event_send(sc->txDaemonTid, START_TRANSMIT_EVENT);
- ifp->if_flags |= IFF_OACTIVE;
-}
-
-static void
-fec_init(void *arg)
-{
- struct mcf5282_enet_struct *sc = arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- if (sc->txDaemonTid == 0) {
- /*
- * Set up hardware
- */
- mcf5282_fec_initialize_hardware(sc);
-
- /*
- * Start driver tasks
- */
- sc->txDaemonTid = rtems_bsdnet_newproc("FECtx", 4096, fec_txDaemon, sc);
- sc->rxDaemonTid = rtems_bsdnet_newproc("FECrx", 4096, fec_rxDaemon, sc);
- }
-
- /*
- * Set flags appropriately
- */
- if (ifp->if_flags & IFF_PROMISC)
- MCF5282_FEC_RCR |= MCF5282_FEC_RCR_PROM;
- else
- MCF5282_FEC_RCR &= ~MCF5282_FEC_RCR_PROM;
-
- /*
- * Tell the world that we're running.
- */
- ifp->if_flags |= IFF_RUNNING;
-
- /*
- * Enable receiver and transmitter
- */
- MCF5282_FEC_ECR = MCF5282_FEC_ECR_ETHER_EN;
-}
-
-
-static void
-fec_stop(struct mcf5282_enet_struct *sc)
-{
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- ifp->if_flags &= ~IFF_RUNNING;
-
- /*
- * Shut down receiver and transmitter
- */
- MCF5282_FEC_ECR = 0x0;
-}
-
-/*
- * Show interface statistics
- */
-static void
-enet_stats(struct mcf5282_enet_struct *sc)
-{
- printf(" Rx Interrupts:%-10lu", sc->rxInterrupts);
- printf("Rx Packet Count:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_PACKETS);
- printf(" Rx Broadcast:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_R_BC_PKT);
- printf(" Rx Multicast:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_MC_PKT);
- printf("CRC/Align error:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_CRC_ALIGN);
- printf(" Rx Undersize:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_R_UNDERSIZE);
- printf(" Rx Oversize:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_OVERSIZE);
- printf(" Rx Fragment:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_FRAG);
- printf(" Rx Jabber:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_R_JAB);
- printf(" Rx 64:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_P64);
- printf(" Rx 65-127:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_P65T0127);
- printf(" Rx 128-255:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_R_P128TO255);
- printf(" Rx 256-511:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_P256TO511);
- printf(" Rx 511-1023:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_P512TO1023);
- printf(" Rx 1024-2047:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_R_P1024TO2047);
- printf(" Rx >=2048:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_GTE2048);
- printf(" Rx Octets:%-10lu", (uint32_t) MCF5282_FEC_RMON_R_OCTETS);
- printf(" Rx Dropped:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_R_DROP);
- printf(" Rx frame OK:%-10lu", (uint32_t) MCF5282_FEC_IEEE_R_FRAME_OK);
- printf(" Rx CRC error:%-10lu", (uint32_t) MCF5282_FEC_IEEE_R_CRC);
- printf(" Rx Align error:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_R_ALIGN);
- printf(" FIFO Overflow:%-10lu", (uint32_t) MCF5282_FEC_IEEE_R_MACERR);
- printf("Rx Pause Frames:%-10lu", (uint32_t) MCF5282_FEC_IEEE_R_FDXFC);
- printf(" Rx Octets OK:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_R_OCTETS_OK);
- printf(" Tx Interrupts:%-10lu", sc->txInterrupts);
- printf("Tx Output Waits:%-10lu", sc->txRawWait);
- printf("Tx mbuf realign:%-10lu\n", sc->txRealign);
- printf("Tx realign drop:%-10lu", sc->txRealignDrop);
- printf(" Tx Unaccounted:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_DROP);
- printf("Tx Packet Count:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_PACKETS);
- printf(" Tx Broadcast:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_BC_PKT);
- printf(" Tx Multicast:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_MC_PKT);
- printf("CRC/Align error:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_CRC_ALIGN);
- printf(" Tx Undersize:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_UNDERSIZE);
- printf(" Tx Oversize:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_OVERSIZE);
- printf(" Tx Fragment:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_FRAG);
- printf(" Tx Jabber:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_JAB);
- printf(" Tx Collisions:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_COL);
- printf(" Tx 64:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_P64);
- printf(" Tx 65-127:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_P65TO127);
- printf(" Tx 128-255:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_P128TO255);
- printf(" Tx 256-511:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_P256TO511);
- printf(" Tx 511-1023:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_P512TO1023);
- printf(" Tx 1024-2047:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_P1024TO2047);
- printf(" Tx >=2048:%-10lu\n", (uint32_t) MCF5282_FEC_RMON_T_P_GTE2048);
- printf(" Tx Octets:%-10lu", (uint32_t) MCF5282_FEC_RMON_T_OCTETS);
- printf(" Tx Dropped:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_DROP);
- printf(" Tx Frame OK:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_T_FRAME_OK);
- printf(" Tx 1 Collision:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_1COL);
- printf("Tx >1 Collision:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_MCOL);
- printf(" Tx Deferred:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_T_DEF);
- printf(" Late Collision:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_LCOL);
- printf(" Excessive Coll:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_EXCOL);
- printf(" FIFO Underrun:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_T_MACERR);
- printf(" Carrier Error:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_CSERR);
- printf(" Tx SQE Error:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_SQE);
- printf("Tx Pause Frames:%-10lu\n", (uint32_t) MCF5282_FEC_IEEE_T_FDXFC);
- printf(" Tx Octets OK:%-10lu", (uint32_t) MCF5282_FEC_IEEE_T_OCTETS_OK);
- printf(" MII interrupts:%-10lu\n", sc->miiInterrupts);
-
- printf(" EIR:%8.8lx ", (uint32_t) MCF5282_FEC_EIR);
- printf("EIMR:%8.8lx ", (uint32_t) MCF5282_FEC_EIMR);
- printf("RDAR:%8.8lx ", (uint32_t) MCF5282_FEC_RDAR);
- printf("TDAR:%8.8lx\n", (uint32_t) MCF5282_FEC_TDAR);
- printf(" ECR:%8.8lx ", (uint32_t) MCF5282_FEC_ECR);
- printf(" RCR:%8.8lx ", (uint32_t) MCF5282_FEC_RCR);
- printf(" TCR:%8.8lx\n", (uint32_t) MCF5282_FEC_TCR);
- printf("FRBR:%8.8lx ", (uint32_t) MCF5282_FEC_FRBR);
- printf("FRSR:%8.8lx\n", (uint32_t) MCF5282_FEC_FRSR);
- if (sc->txBdActiveCount != 0) {
- int i, n;
- /*
- * Yes, there are races here with adding and retiring descriptors,
- * but this diagnostic is more for when things have backed up.
- */
- printf("Transmit Buffer Descriptors (Tail %d, Head %d, Unretired %d):\n",
- sc->txBdTail,
- sc->txBdHead,
- sc->txBdActiveCount);
- i = sc->txBdTail;
- for (n = 0 ; n < sc->txBdCount ; n++) {
- if ((sc->txBdBase[i].status & MCF5282_FEC_TxBD_R) != 0)
- printf(" %3d: status:%4.4x length:%-4d buffer:%p\n",
- i,
- sc->txBdBase[i].status,
- sc->txBdBase[i].length,
- sc->txBdBase[i].buffer);
- if (++i == sc->txBdCount)
- i = 0;
- }
- }
-}
-
-static int
-fec_ioctl(struct ifnet *ifp, ioctl_command_t command, caddr_t data)
-{
- struct mcf5282_enet_struct *sc = ifp->if_softc;
- int error = 0;
-
- switch (command) {
- case SIOCGIFADDR:
- case SIOCSIFADDR:
- ether_ioctl(ifp, command, data);
- break;
-
- case SIOCSIFFLAGS:
- switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
- case IFF_RUNNING:
- fec_stop(sc);
- break;
-
- case IFF_UP:
- fec_init(sc);
- break;
-
- case IFF_UP | IFF_RUNNING:
- fec_stop(sc);
- fec_init(sc);
- break;
-
- default:
- break;
- }
- break;
-
- case SIO_RTEMS_SHOW_STATS:
- enet_stats(sc);
- break;
-
- /*
- * FIXME: All sorts of multicast commands need to be added here!
- */
- default:
- error = EINVAL;
- break;
- }
- return error;
-}
-
-int
-rtems_fec_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching )
-{
- struct mcf5282_enet_struct *sc;
- struct ifnet *ifp;
- int mtu;
- int unitNumber;
- char *unitName;
- unsigned char *hwaddr;
-
- /*
- * Parse driver name
- */
- if ((unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName)) < 0)
- return 0;
-
- /*
- * Is driver free?
- */
- if ((unitNumber <= 0) || (unitNumber > NIFACES)) {
- printf("Bad FEC unit number.\n");
- return 0;
- }
- sc = &enet_driver[unitNumber - 1];
- ifp = &sc->arpcom.ac_if;
- if (ifp->if_softc != NULL) {
- printf("Driver already in use.\n");
- return 0;
- }
-
- /*
- * Process options
- */
- printf("%s%d: Ethernet address: ", unitName, unitNumber );
- if (config->hardware_address) {
- hwaddr = config->hardware_address;
- printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
- hwaddr[0], hwaddr[1], hwaddr[2],
- hwaddr[3], hwaddr[4], hwaddr[5]);
- memcpy(sc->arpcom.ac_enaddr, hwaddr, ETHER_ADDR_LEN);
- } else {
- printf("UNKNOWN\n");
- }
-
- if (config->mtu)
- mtu = config->mtu;
- else
- mtu = ETHERMTU;
- if (config->rbuf_count)
- sc->rxBdCount = config->rbuf_count;
- else
- sc->rxBdCount = RX_BUF_COUNT;
- if (config->xbuf_count)
- sc->txBdCount = config->xbuf_count;
- else
- sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;
-
- sc->acceptBroadcast = !config->ignore_broadcast;
-
- /*
- * Set up network interface values
- */
- ifp->if_softc = sc;
- ifp->if_unit = unitNumber;
- ifp->if_name = unitName;
- ifp->if_mtu = mtu;
- ifp->if_init = fec_init;
- ifp->if_ioctl = fec_ioctl;
- ifp->if_start = mcf5282_enet_start;
- ifp->if_output = ether_output;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
- if (ifp->if_snd.ifq_maxlen == 0)
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
-
- /*
- * Attach the interface
- */
- if_attach(ifp);
- ether_ifattach(ifp);
- return 1;
-};
-
diff --git a/bsps/m68k/csb360/net/network.c b/bsps/m68k/csb360/net/network.c
deleted file mode 100644
index 95769bf26a..0000000000
--- a/bsps/m68k/csb360/net/network.c
+++ /dev/null
@@ -1,984 +0,0 @@
-/*
- * RTEMS/TCPIP driver for MCF5272 Ethernet
- *
- * Modified for MPC860 by Jay Monkman (jmonkman@lopingdog.com)
- *
- * This supports Ethernet on either SCC1 or the FEC of the MPC860T.
- * Right now, we only do 10 Mbps, even with the FEC. The function
- * rtems_enet_driver_attach determines which one to use. Currently,
- * only one may be used at a time.
- *
- * Based on the MC68360 network driver by
- * W. Eric Norum
- * Saskatchewan Accelerator Laboratory
- * University of Saskatchewan
- * Saskatoon, Saskatchewan, CANADA
- * eric@skatter.usask.ca
- *
- * This supports ethernet on SCC1. Right now, we only do 10 Mbps.
- *
- * Modifications by Darlene Stewart <Darlene.Stewart@iit.nrc.ca>
- * and Charles-Antoine Gauthier <charles.gauthier@iit.nrc.ca>
- * Copyright (c) 1999, National Research Council of Canada
- */
-
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <bsp.h>
-#include <stdio.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-/*
- * Number of interfaces supported by this driver
- */
-#define NIFACES 1
-
-/*
- * Default number of buffer descriptors set aside for this driver.
- * The number of transmit buffer descriptors has to be quite large
- * since a single frame often uses four or more buffer descriptors.
- */
-#define RX_BUF_COUNT 32
-#define TX_BUF_COUNT 16
-#define TX_BD_PER_BUF 4
-
-#define INET_ADDR_MAX_BUF_SIZE (sizeof "255.255.255.255")
-
-
-/*
- * RTEMS event used by interrupt handler to signal daemons.
- * This must *not* be the same event used by the TCP/IP task synchronization.
- */
-#define INTERRUPT_EVENT RTEMS_EVENT_1
-
-/*
- * RTEMS event used to start transmit daemon.
- * This must not be the same as INTERRUPT_EVENT.
- */
-#define START_TRANSMIT_EVENT RTEMS_EVENT_2
-
-/*
- * Receive buffer size -- Allow for a full ethernet packet plus CRC (1518).
- * Round off to nearest multiple of RBUF_ALIGN.
- */
-#define MAX_MTU_SIZE 1518
-#define RBUF_ALIGN 4
-#define RBUF_SIZE ((MAX_MTU_SIZE + RBUF_ALIGN) & ~RBUF_ALIGN)
-
-#if (MCLBYTES < RBUF_SIZE)
-# error "Driver must have MCLBYTES > RBUF_SIZE"
-#endif
-
-typedef struct {
- uint16_t status;
- uint16_t length;
- void *buffer;
-} bd_t;
-#define MCF5272_BD_READY (bit(15))
-#define MCF5272_BD_TO1 (bit(14))
-#define MCF5272_BD_WRAP (bit(13))
-#define MCF5272_BD_TO2 (bit(12))
-#define MCF5272_BD_LAST (bit(11))
-#define MCF5272_BD_TX_CRC (bit(10))
-#define MCF5272_BD_DEFER (bit(9))
-#define MCF5272_BD_HEARTBEAT (bit(8))
-#define MCF5272_BD_LATE_COLLISION (bit(7))
-#define MCF5272_BD_RETRY_LIMIT (bit(6))
-#define MCF5272_BD_UNDERRUN (bit(1))
-#define MCF5272_BD_CARRIER_LOST (bit(0))
-
-#define MCF5272_BD_EMPTY (bit(15))
-#define MCF5272_BD_RO1 (bit(14))
-#define MCF5272_BD_WRAP (bit(13))
-#define MCF5272_BD_RO2 (bit(12))
-#define MCF5272_BD_M (bit(8))
-#define MCF5272_BD_BC (bit(7))
-#define MCF5272_BD_MC (bit(6))
-#define MCF5272_BD_LONG (bit(5))
-#define MCF5272_BD_NONALIGNED (bit(4))
-#define MCF5272_BD_SHORT (bit(3))
-#define MCF5272_BD_CRC_ERROR (bit(2))
-#define MCF5272_BD_OVERRUN (bit(1))
-#define MCF5272_BD_TRUNCATED (bit(0))
-
-
-/*
- * Per-device data
- */
-struct mcf5272_enet_struct {
- struct arpcom arpcom;
- struct mbuf **rxMbuf;
- struct mbuf **txMbuf;
- int acceptBroadcast;
- int rxBdCount;
- int txBdCount;
- int txBdHead;
- int txBdTail;
- int txBdActiveCount;
- bd_t *rxBdBase;
- bd_t *txBdBase;
- rtems_id rxDaemonTid;
- rtems_id txDaemonTid;
-
- /*
- * Statistics
- */
- unsigned long rxInterrupts;
- unsigned long rxNotFirst;
- unsigned long rxNotLast;
- unsigned long rxGiant;
- unsigned long rxNonOctet;
- unsigned long rxRunt;
- unsigned long rxBadCRC;
- unsigned long rxOverrun;
- unsigned long rxTruncated;
-
- unsigned long txInterrupts;
- unsigned long txDeferred;
- unsigned long txHeartbeat;
- unsigned long txLateCollision;
- unsigned long txRetryLimit;
- unsigned long txUnderrun;
- unsigned long txLostCarrier;
- unsigned long txRawWait;
-};
-static struct mcf5272_enet_struct enet_driver[NIFACES];
-
-
-void dump_enet_regs(void)
-{
- printf("**************************************************************\n");
- printf("ecr: 0x%08x eir: 0x%08x eimr: 0x%08x ivsr: 0x%08x\n\r",
- g_enet_regs->ecr, g_enet_regs->eir,
- g_enet_regs->eimr, g_enet_regs->ivsr);
- printf("rdar: 0x%08x tdar: 0x%08x mmfr: 0x%08x mscr: 0x%08x\n\r",
- g_enet_regs->rdar, g_enet_regs->tdar,
- g_enet_regs->mmfr, g_enet_regs->mscr);
- printf("frbr: 0x%08x frsr: 0x%08x tfwr: 0x%08x tfsr: 0x%08x\n\r",
- g_enet_regs->frbr, g_enet_regs->frsr,
- g_enet_regs->tfwr, g_enet_regs->tfsr);
- printf("rcr: 0x%08x mflr: 0x%08x tcr: 0x%08x malr: 0x%08x\n\r",
- g_enet_regs->rcr, g_enet_regs->mflr,
- g_enet_regs->tcr, g_enet_regs->malr);
- printf("maur: 0x%08x htur: 0x%08x htlr: 0x%08x erdsr: 0x%08x\n\r",
- g_enet_regs->maur, g_enet_regs->htur,
- g_enet_regs->htlr, g_enet_regs->erdsr);
- printf("etdsr: 0x%08x emrbr: 0x%08x\n\r",
- g_enet_regs->etdsr, g_enet_regs->emrbr);
-}
-
-
-
-
-/*#define cp printk("%s:%d\n\r", __FUNCTION__, __LINE__) */
-#define cp
-#define mcf5272_bd_allocate(_n_) malloc((_n_) * sizeof(bd_t), 0, M_NOWAIT)
-
-
-
-rtems_isr enet_rx_isr(rtems_vector_number vector)
-{
- cp;
- /*
- * Frame received?
- */
- if (g_enet_regs->eir & MCF5272_ENET_EIR_RXF) {
- cp;
- g_enet_regs->eir = MCF5272_ENET_EIR_RXF;
- enet_driver[0].rxInterrupts++;
- rtems_bsdnet_event_send (enet_driver[0].rxDaemonTid, INTERRUPT_EVENT);
- }
- cp;
-}
-
-rtems_isr enet_tx_isr(rtems_vector_number vector)
-{
- cp;
- /*
- * Buffer transmitted or transmitter error?
- */
- if (g_enet_regs->eir & MCF5272_ENET_EIR_TXF) {
- cp;
- g_enet_regs->eir = MCF5272_ENET_EIR_TXF;
- enet_driver[0].txInterrupts++;
- rtems_bsdnet_event_send (enet_driver[0].txDaemonTid, INTERRUPT_EVENT);
- }
- cp;
-}
-
-
-/*
- * Initialize the ethernet hardware
- */
-
-
-static void
-mcf5272_enet_initialize_hardware (struct mcf5272_enet_struct *sc)
-{
- int i;
- unsigned char *hwaddr;
- uint32_t icr;
- /*
- * Issue reset to FEC
- */
- g_enet_regs->ecr=0x1;
-
- /*
- * Set the TX and RX fifo sizes. For now, we'll split it evenly
- */
- /* If you uncomment these, the FEC will not work right.
- g_enet_regs->r_fstart = ((g_enet_regs->r_bound & 0x3ff) >> 2) & 0x3ff;
- g_enet_regs->x_fstart = 0;
- */
-
- /* Copy mac address to device */
-
- hwaddr = sc->arpcom.ac_enaddr;
-
- g_enet_regs->malr = (hwaddr[0] << 24 |
- hwaddr[1] << 16 |
- hwaddr[2] << 8 |
- hwaddr[3]);
- g_enet_regs->maur = (hwaddr[4] << 24 |
- hwaddr[5] << 16);
-
- /*
- * Clear the hash table
- */
- g_enet_regs->htlr = 0;
- g_enet_regs->htur = 0;
-
- /*
- * Set up receive buffer size
- */
- g_enet_regs->emrbr = 0x5f0; /* set to 1520 */
-
- /*
- * Allocate mbuf pointers
- */
- sc->rxMbuf = malloc (sc->rxBdCount * sizeof *sc->rxMbuf,
- M_MBUF, M_NOWAIT);
- sc->txMbuf = malloc (sc->txBdCount * sizeof *sc->txMbuf,
- M_MBUF, M_NOWAIT);
- if (!sc->rxMbuf || !sc->txMbuf) {
- rtems_panic ("No memory for mbuf pointers");
- }
-
- /*
- * Set receiver and transmitter buffer descriptor bases
- */
- sc->rxBdBase = mcf5272_bd_allocate(sc->rxBdCount);
- sc->txBdBase = mcf5272_bd_allocate(sc->txBdCount);
- g_enet_regs->erdsr = (int)sc->rxBdBase;
- g_enet_regs->etdsr = (int)sc->txBdBase;
-
- /*
- * Set up Receive Control Register:
- * Not promiscuous mode
- * MII mode
- * Full duplex
- * No loopback
- */
- g_enet_regs->rcr = 0x00000004;
-
- /*
- * Set up Transmit Control Register:
- * Full duplex
- * No heartbeat
- */
- g_enet_regs->tcr = 0x00000004;
-
- /*
- * Set MII speed to 2.5 MHz for 25 Mhz system clock
- */
- g_enet_regs->mscr = 0x0a;
- g_enet_regs->mmfr = 0x58021000;
-
- /*
- * Set up receive buffer descriptors
- */
- for (i = 0 ; i < sc->rxBdCount ; i++) {
- (sc->rxBdBase + i)->status = 0;
- }
-
- /*
- * Set up transmit buffer descriptors
- */
- for (i = 0 ; i < sc->txBdCount ; i++) {
- (sc->txBdBase + i)->status = 0;
- sc->txMbuf[i] = NULL;
- }
-
- sc->txBdHead = sc->txBdTail = 0;
- sc->txBdActiveCount = 0;
-
- /*
- * Mask all FEC interrupts and clear events
- */
- g_enet_regs->eimr = (MCF5272_ENET_EIR_TXF |
- MCF5272_ENET_EIR_RXF);
- g_enet_regs->eir = ~0;
-
- /*
- * Set up interrupts
- */
- set_vector(enet_rx_isr, BSP_INTVEC_ERX, 1);
- set_vector(enet_tx_isr, BSP_INTVEC_ETX, 1);
-
- /* Configure ethernet interrupts */
- icr = g_intctrl_regs->icr3;
- icr = icr & ~((MCF5272_ICR3_ERX_MASK | MCF5272_ICR3_ERX_PI) |
- (MCF5272_ICR3_ETX_MASK | MCF5272_ICR3_ETX_PI));
- icr |= ((MCF5272_ICR3_ERX_IPL(BSP_INTLVL_ERX) | MCF5272_ICR3_ERX_PI)|
- (MCF5272_ICR3_ETX_IPL(BSP_INTLVL_ETX) | MCF5272_ICR3_ETX_PI));
- g_intctrl_regs->icr3 = icr;
-
-}
-
-
-/*
- * Soak up buffer descriptors that have been sent.
- * Note that a buffer descriptor can't be retired as soon as it becomes
- * ready. The MPC860 manual (MPC860UM/AD 07/98 Rev.1) and the MPC821
- * manual state that, "If an Ethernet frame is made up of multiple
- * buffers, the user should not reuse the first buffer descriptor until
- * the last buffer descriptor of the frame has had its ready bit cleared
- * by the CPM".
- */
-static void
-mcf5272_enet_retire_tx_bd (struct mcf5272_enet_struct *sc)
-{
- uint16_t status;
- int i;
- int nRetired;
- struct mbuf *m, *n;
-
- i = sc->txBdTail;
- nRetired = 0;
- while ((sc->txBdActiveCount != 0) &&
- (((status = sc->txBdBase[i].status) & MCF5272_BD_READY) == 0)) {
- /*
- * See if anything went wrong
- */
- if (status & (MCF5272_BD_DEFER |
- MCF5272_BD_HEARTBEAT |
- MCF5272_BD_LATE_COLLISION |
- MCF5272_BD_RETRY_LIMIT |
- MCF5272_BD_UNDERRUN |
- MCF5272_BD_CARRIER_LOST)) {
- /*
- * Check for errors which stop the transmitter.
- */
- if (status & (MCF5272_BD_LATE_COLLISION |
- MCF5272_BD_RETRY_LIMIT |
- MCF5272_BD_UNDERRUN)) {
- if (status & MCF5272_BD_LATE_COLLISION) {
- enet_driver[0].txLateCollision++;
- }
- if (status & MCF5272_BD_RETRY_LIMIT) {
- enet_driver[0].txRetryLimit++;
- }
- if (status & MCF5272_BD_UNDERRUN) {
- enet_driver[0].txUnderrun++;
- }
- }
- if (status & MCF5272_BD_DEFER) {
- enet_driver[0].txDeferred++;
- }
- if (status & MCF5272_BD_HEARTBEAT) {
- enet_driver[0].txHeartbeat++;
- }
- if (status & MCF5272_BD_CARRIER_LOST) {
- enet_driver[0].txLostCarrier++;
- }
- }
- nRetired++;
- if (status & MCF5272_BD_LAST) {
- /*
- * A full frame has been transmitted.
- * Free all the associated buffer descriptors.
- */
- sc->txBdActiveCount -= nRetired;
- while (nRetired) {
- nRetired--;
- m = sc->txMbuf[sc->txBdTail];
- MFREE (m, n);
- if (++sc->txBdTail == sc->txBdCount)
- sc->txBdTail = 0;
- }
- }
- if (++i == sc->txBdCount) {
- i = 0;
- }
- }
-}
-
-static void
-mcf5272_enet_rxDaemon (void *arg)
-{
- struct mcf5272_enet_struct *sc = (struct mcf5272_enet_struct *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mbuf *m;
- uint16_t status;
- bd_t *rxBd;
- int rxBdIndex;
-
- /*
- * Allocate space for incoming packets and start reception
- */
- for (rxBdIndex = 0 ; ;) {
- rxBd = sc->rxBdBase + rxBdIndex;
- MGETHDR (m, M_WAIT, MT_DATA);
- MCLGET (m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod (m, void *);
- rxBd->status = MCF5272_BD_EMPTY;
- g_enet_regs->rdar = 0x1000000;
- if (++rxBdIndex == sc->rxBdCount) {
- rxBd->status |= MCF5272_BD_WRAP;
- break;
- }
- }
-
- /*
- * Input packet handling loop
- */
- rxBdIndex = 0;
- for (;;) {
- rxBd = sc->rxBdBase + rxBdIndex;
-
- /*
- * Wait for packet if there's not one ready
- */
- if ((status = rxBd->status) & MCF5272_BD_EMPTY) {
- /*
- * Clear old events
- */
- g_enet_regs->eir = MCF5272_ENET_EIR_RXF;
-
- /*
- * Wait for packet
- * Note that the buffer descriptor is checked
- * *before* the event wait -- this catches the
- * possibility that a packet arrived between the
- * `if' above, and the clearing of the event register.
- */
- while ((status = rxBd->status) & MCF5272_BD_EMPTY) {
- rtems_event_set events;
-
- /*
- * Unmask RXF (Full frame received) event
- */
- g_enet_regs->eir |= MCF5272_ENET_EIR_RXF;
-
- rtems_bsdnet_event_receive (INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- cp;
- }
- }
- cp;
-
- /*
- * Check that packet is valid
- */
- if (status & MCF5272_BD_LAST) {
- /*
- * Pass the packet up the chain.
- * FIXME: Packet filtering hook could be done here.
- */
- struct ether_header *eh;
-
- m = sc->rxMbuf[rxBdIndex];
- m->m_len = m->m_pkthdr.len = (rxBd->length -
- sizeof(uint32_t) -
- sizeof(struct ether_header));
- eh = mtod (m, struct ether_header *);
- m->m_data += sizeof(struct ether_header);
- ether_input (ifp, eh, m);
-
- /*
- * Allocate a new mbuf
- */
- MGETHDR (m, M_WAIT, MT_DATA);
- MCLGET (m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod (m, void *);
- }
- else {
- /*
- * Something went wrong with the reception
- */
- if (!(status & MCF5272_BD_LAST)) {
- sc->rxNotLast++;
- }
- if (status & MCF5272_BD_LONG) {
- sc->rxGiant++;
- }
- if (status & MCF5272_BD_NONALIGNED) {
- sc->rxNonOctet++;
- }
- if (status & MCF5272_BD_SHORT) {
- sc->rxRunt++;
- }
- if (status & MCF5272_BD_CRC_ERROR) {
- sc->rxBadCRC++;
- }
- if (status & MCF5272_BD_OVERRUN) {
- sc->rxOverrun++;
- }
- if (status & MCF5272_BD_TRUNCATED) {
- sc->rxTruncated++;
- }
- }
- /*
- * Reenable the buffer descriptor
- */
- rxBd->status = (status & MCF5272_BD_WRAP) | MCF5272_BD_EMPTY;
- g_enet_regs->rdar = 0x1000000;
- /*
- * Move to next buffer descriptor
- */
- if (++rxBdIndex == sc->rxBdCount) {
- rxBdIndex = 0;
- }
- }
-}
-
-static void
-mcf5272_enet_sendpacket (struct ifnet *ifp, struct mbuf *m)
-{
- struct mcf5272_enet_struct *sc = ifp->if_softc;
- volatile bd_t *firstTxBd, *txBd;
- /* struct mbuf *l = NULL; */
- uint16_t status;
- int nAdded;
- cp;
-
- /*
- * Free up buffer descriptors
- */
- mcf5272_enet_retire_tx_bd (sc);
-
- /*
- * Set up the transmit buffer descriptors.
- * No need to pad out short packets since the
- * hardware takes care of that automatically.
- * No need to copy the packet to a contiguous buffer
- * since the hardware is capable of scatter/gather DMA.
- */
- nAdded = 0;
- txBd = firstTxBd = sc->txBdBase + sc->txBdHead;
- for (;;) {
- cp;
- /*
- * Wait for buffer descriptor to become available.
- */
- if ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- /*
- * Clear old events
- */
- g_enet_regs->eir = MCF5272_ENET_EIR_TXF;
-
- /*
- * Wait for buffer descriptor to become available.
- * Note that the buffer descriptors are checked
- * *before* * entering the wait loop -- this catches
- * the possibility that a buffer descriptor became
- * available between the `if' above, and the clearing
- * of the event register.
- * This is to catch the case where the transmitter
- * stops in the middle of a frame -- and only the
- * last buffer descriptor in a frame can generate
- * an interrupt.
- */
- mcf5272_enet_retire_tx_bd (sc);
- while ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- rtems_event_set events;
-
- cp;
- /*
- * Unmask TXB (buffer transmitted) and
- * TXE (transmitter error) events.
- */
- g_enet_regs->eir |= MCF5272_ENET_EIR_TXF;
- rtems_bsdnet_event_receive (INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- cp;
- mcf5272_enet_retire_tx_bd (sc);
- }
- }
-
- /*
- * Don't set the READY flag till the
- * whole packet has been readied.
- */
- status = nAdded ? MCF5272_BD_READY : 0;
- cp;
-
- /*
- * FIXME: Why not deal with empty mbufs at at higher level?
- * The IP fragmentation routine in ip_output
- * can produce packet fragments with zero length.
- * I think that ip_output should be changed to get
- * rid of these zero-length mbufs, but for now,
- * I'll deal with them here.
- */
- if (m->m_len) {
- cp;
- /*
- * Fill in the buffer descriptor
- */
- txBd->buffer = mtod (m, void *);
- txBd->length = m->m_len;
-
- sc->txMbuf[sc->txBdHead] = m;
- nAdded++;
- if (++sc->txBdHead == sc->txBdCount) {
- status |= MCF5272_BD_WRAP;
- sc->txBdHead = 0;
- }
- /* l = m;*/
- m = m->m_next;
- }
- else {
- /*
- * Just toss empty mbufs
- */
- struct mbuf *n;
- cp;
- MFREE (m, n);
- m = n;
- /*
- if (l != NULL)
- l->m_next = m;
- */
- }
-
- /*
- * Set the transmit buffer status.
- * Break out of the loop if this mbuf is the last in the frame.
- */
- if (m == NULL) {
- cp;
- if (nAdded) {
- cp;
- status |= MCF5272_BD_LAST | MCF5272_BD_TX_CRC;
- txBd->status = status;
- firstTxBd->status |= MCF5272_BD_READY;
- g_enet_regs->tdar = 0x1000000;
- sc->txBdActiveCount += nAdded;
- }
- break;
- }
- txBd->status = status;
- txBd = sc->txBdBase + sc->txBdHead;
- }
- cp;
-/*
- dump_enet_regs();
- dump_intctrl;
-*/
-
-}
-
-
-void
-mcf5272_enet_txDaemon (void *arg)
-{
- struct mcf5272_enet_struct *sc = (struct mcf5272_enet_struct *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mbuf *m;
- rtems_event_set events;
-
- cp;
- for (;;) {
- /*
- * Wait for packet
- */
- rtems_bsdnet_event_receive (START_TRANSMIT_EVENT,
- RTEMS_EVENT_ANY | RTEMS_WAIT,
- RTEMS_NO_TIMEOUT,
- &events);
- cp;
- /*
- * Send packets till queue is empty
- */
- cp;
- for (;;) {
- cp;
- /*
- * Get the next mbuf chain to transmit.
- */
- IF_DEQUEUE(&ifp->if_snd, m);
- if (!m)
- break;
- mcf5272_enet_sendpacket (ifp, m);
- }
- ifp->if_flags &= ~IFF_OACTIVE;
- }
-}
-
-
-/*
- * Send packet (caller provides header).
- */
-static void
-mcf5272_enet_start (struct ifnet *ifp)
-{
- struct mcf5272_enet_struct *sc = ifp->if_softc;
-
- cp;
- rtems_bsdnet_event_send (sc->txDaemonTid, START_TRANSMIT_EVENT);
- cp;
- ifp->if_flags |= IFF_OACTIVE;
-}
-
-
-static void
-mcf5272_enet_init (void *arg)
-{
- struct mcf5272_enet_struct *sc = arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- if (sc->txDaemonTid == 0) {
-
- /*
- * Set up SCC hardware
- */
- mcf5272_enet_initialize_hardware (sc);
-
- /*
- * Start driver tasks
- */
- sc->txDaemonTid = rtems_bsdnet_newproc("SCtx",
- 4096,
- mcf5272_enet_txDaemon,
- sc);
- sc->rxDaemonTid = rtems_bsdnet_newproc("SCrx",
- 4096,
- mcf5272_enet_rxDaemon,
- sc);
-
- }
-
- /*
- * Set flags appropriately
- */
- if (ifp->if_flags & IFF_PROMISC) {
- g_enet_regs->rcr |= 0x8;
- } else {
- g_enet_regs->rcr &= ~0x8;
- }
-
- /*
- * Tell the world that we're running.
- */
- ifp->if_flags |= IFF_RUNNING;
-
- /*
- * Enable receiver and transmitter
- */
- g_enet_regs->ecr = 0x2;
-}
-
-
-static void
-mcf5272_enet_stop (struct mcf5272_enet_struct *sc)
-{
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- ifp->if_flags &= ~IFF_RUNNING;
-
- /*
- * Shut down receiver and transmitter
- */
- g_enet_regs->ecr = 0x0;
-}
-
-
-/*
- * Show interface statistics
- */
-static void
-enet_stats (struct mcf5272_enet_struct *sc)
-{
- printf (" Rx Interrupts:%-8lu", sc->rxInterrupts);
- printf (" Not First:%-8lu", sc->rxNotFirst);
- printf (" Not Last:%-8lu\n", sc->rxNotLast);
- printf (" Giant:%-8lu", sc->rxGiant);
- printf (" Runt:%-8lu", sc->rxRunt);
- printf (" Non-octet:%-8lu\n", sc->rxNonOctet);
- printf (" Bad CRC:%-8lu", sc->rxBadCRC);
- printf (" Overrun:%-8lu", sc->rxOverrun);
- printf (" Truncated:%-8lu\n", sc->rxTruncated);
-/* printf (" Discarded:%-8lu\n", (unsigned long)mcf5272.scc1p.un.ethernet.disfc); */
-
- printf (" Tx Interrupts:%-8lu", sc->txInterrupts);
- printf (" Deferred:%-8lu", sc->txDeferred);
- printf (" Missed Hearbeat:%-8lu\n", sc->txHeartbeat);
- printf (" No Carrier:%-8lu", sc->txLostCarrier);
- printf ("Retransmit Limit:%-8lu", sc->txRetryLimit);
- printf (" Late Collision:%-8lu\n", sc->txLateCollision);
- printf (" Underrun:%-8lu", sc->txUnderrun);
- printf (" Raw output wait:%-8lu\n", sc->txRawWait);
-}
-
-
-/*
- * Driver ioctl handler
- */
-static int
-mcf5272_enet_ioctl (struct ifnet *ifp, int command, caddr_t data)
-{
- struct mcf5272_enet_struct *sc = ifp->if_softc;
- int error = 0;
-
- switch (command) {
- case SIOCGIFADDR:
- case SIOCSIFADDR:
- ether_ioctl (ifp, command, data);
- break;
-
- case SIOCSIFFLAGS:
- switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
- case IFF_RUNNING:
- mcf5272_enet_stop (sc);
- break;
-
- case IFF_UP:
- mcf5272_enet_init (sc);
- break;
-
- case IFF_UP | IFF_RUNNING:
- mcf5272_enet_stop (sc);
- mcf5272_enet_init (sc);
- break;
-
- default:
- break;
- }
- break;
-
- case SIO_RTEMS_SHOW_STATS:
- enet_stats (sc);
- break;
-
- /*
- * FIXME: All sorts of multicast commands need to be added here!
- */
- default:
- error = EINVAL;
- break;
- }
- return error;
-}
-
-
-int
-rtems_enet_driver_attach (struct rtems_bsdnet_ifconfig *config)
-{
- struct mcf5272_enet_struct *sc;
- struct ifnet *ifp;
- int mtu;
- int unitNumber;
- char *unitName;
-
- /*
- * Parse driver name
- */
- unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName);
- if (unitNumber < 0){
- return 0;
- }
-
- /*
- * Is driver free?
- */
- if ((unitNumber < 0) || (unitNumber > NIFACES)) {
- printf ("Bad unit number: %d.\n", unitNumber);
- return 0;
- }
-
- sc = &enet_driver[unitNumber];
- ifp = &sc->arpcom.ac_if;
- if (ifp->if_softc != NULL) {
- printf ("Driver already in use.\n");
- return 0;
- }
-
- /*
- * Process options
- */
-
- sc->arpcom.ac_enaddr[0] = (g_enet_regs->malr >> 24) & 0xff;
- sc->arpcom.ac_enaddr[1] = (g_enet_regs->malr >> 16) & 0xff;
- sc->arpcom.ac_enaddr[2] = (g_enet_regs->malr >> 8) & 0xff;
- sc->arpcom.ac_enaddr[3] = (g_enet_regs->malr >> 0) & 0xff;
- sc->arpcom.ac_enaddr[4] = (g_enet_regs->maur >> 24) & 0xff;
- sc->arpcom.ac_enaddr[5] = (g_enet_regs->maur >> 16) & 0xff;
-
- if (config->mtu) {
- mtu = config->mtu;
- } else {
- mtu = ETHERMTU;
- }
-
- if (config->rbuf_count) {
- sc->rxBdCount = config->rbuf_count;
- } else {
- sc->rxBdCount = RX_BUF_COUNT;
- }
- if (config->xbuf_count) {
- sc->txBdCount = config->xbuf_count;
- } else {
- sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;
- }
- sc->acceptBroadcast = !config->ignore_broadcast;
-
- /*
- * Set up network interface values
- */
- ifp->if_softc = sc;
- ifp->if_unit = unitNumber;
- ifp->if_name = unitName;
- ifp->if_mtu = mtu;
- ifp->if_init = mcf5272_enet_init;
- ifp->if_ioctl = mcf5272_enet_ioctl;
- ifp->if_start = mcf5272_enet_start;
- ifp->if_output = ether_output;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
- if (ifp->if_snd.ifq_maxlen == 0) {
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
- }
-
- /*
- * Attach the interface
- */
- if_attach (ifp);
- cp;
- ether_ifattach (ifp);
- cp;
- return 1;
-};
-
-
diff --git a/bsps/m68k/gen68360/net/network.c b/bsps/m68k/gen68360/net/network.c
deleted file mode 100644
index b0110af064..0000000000
--- a/bsps/m68k/gen68360/net/network.c
+++ /dev/null
@@ -1,1062 +0,0 @@
-/*
- * RTEMS driver for M68360 SCC1 Ethernet
- *
- * W. Eric Norum
- * Saskatchewan Accelerator Laboratory
- * University of Saskatchewan
- * Saskatoon, Saskatchewan, CANADA
- * eric@skatter.usask.ca
- */
-
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <bsp.h>
-#include <rtems/m68k/m68360.h>
-#include <stdio.h>
-#include <errno.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-
-/*
- * Number of SCCs supported by this driver
- */
-#define NSCCDRIVER 1
-
-/*
- * Default number of buffer descriptors set aside for this driver.
- * The number of transmit buffer descriptors has to be quite large
- * since a single frame often uses four or more buffer descriptors.
- */
-#define RX_BUF_COUNT 15
-#define TX_BUF_COUNT 4
-#define TX_BD_PER_BUF 4
-
-/*
- * RTEMS event used by interrupt handler to signal driver tasks.
- * This must not be any of the events used by the network task synchronization.
- */
-#define INTERRUPT_EVENT RTEMS_EVENT_1
-
-/*
- * RTEMS event used to start transmit daemon.
- * This must not be the same as INTERRUPT_EVENT.
- */
-#define START_TRANSMIT_EVENT RTEMS_EVENT_2
-
-/*
- * Receive buffer size -- Allow for a full ethernet packet including CRC
- */
-#define RBUF_SIZE 1520
-
-#if (MCLBYTES < RBUF_SIZE)
-# error "Driver must have MCLBYTES > RBUF_SIZE"
-#endif
-
-/*
- * Per-device data
- */
-struct scc_softc {
- struct arpcom arpcom;
- struct mbuf **rxMbuf;
- struct mbuf **txMbuf;
- int acceptBroadcast;
- int rxBdCount;
- int txBdCount;
- int txBdHead;
- int txBdTail;
- int txBdActiveCount;
- m360BufferDescriptor_t *rxBdBase;
- m360BufferDescriptor_t *txBdBase;
- rtems_id rxDaemonTid;
- rtems_id txDaemonTid;
-
- /*
- * Statistics
- */
- unsigned long rxInterrupts;
- unsigned long rxNotFirst;
- unsigned long rxNotLast;
- unsigned long rxGiant;
- unsigned long rxNonOctet;
- unsigned long rxRunt;
- unsigned long rxBadCRC;
- unsigned long rxOverrun;
- unsigned long rxCollision;
-
- unsigned long txInterrupts;
- unsigned long txDeferred;
- unsigned long txHeartbeat;
- unsigned long txLateCollision;
- unsigned long txRetryLimit;
- unsigned long txUnderrun;
- unsigned long txLostCarrier;
- unsigned long txRawWait;
- unsigned long txCoalesced;
- unsigned long txCoalesceFailed;
- unsigned long txRetry;
-};
-static struct scc_softc scc_softc[NSCCDRIVER];
-
-extern void *_RomBase; /* From linkcmds */
-
-/*
- * SCC1 interrupt handler
- */
-static rtems_isr
-m360Enet_interrupt_handler (rtems_vector_number v)
-{
- /*
- * Frame received?
- */
- if ((m360.scc1.sccm & 0x8) && (m360.scc1.scce & 0x8)) {
- m360.scc1.scce = 0x8;
- m360.scc1.sccm &= ~0x8;
- scc_softc[0].rxInterrupts++;
- rtems_bsdnet_event_send (scc_softc[0].rxDaemonTid, INTERRUPT_EVENT);
- }
-
- /*
- * Buffer transmitted or transmitter error?
- */
- if ((m360.scc1.sccm & 0x12) && (m360.scc1.scce & 0x12)) {
- m360.scc1.scce = 0x12;
- m360.scc1.sccm &= ~0x12;
- scc_softc[0].txInterrupts++;
- rtems_bsdnet_event_send (scc_softc[0].txDaemonTid, INTERRUPT_EVENT);
- }
- m360.cisr = 1UL << 30; /* Clear SCC1 interrupt-in-service bit */
-}
-
-/*
- * Initialize the ethernet hardware
- */
-static void
-m360Enet_initialize_hardware (struct scc_softc *sc)
-{
- int i;
- unsigned char *hwaddr;
- rtems_status_code status;
- rtems_isr_entry old_handler;
-
- /*
- * Configure port A CLK1, CLK2, TXD1 and RXD1 pins
- */
- m360.papar |= 0x303;
- m360.padir &= ~0x303;
- m360.paodr &= ~0x303;
-
- /*
- * Configure port C CTS1* and CD1* pins
- */
- m360.pcpar &= ~0x30;
- m360.pcdir &= ~0x30;
- m360.pcso |= 0x30;
-
- /*
- * Connect CLK1 and CLK2 to SCC1
- */
- m360.sicr &= ~0xFF;
- m360.sicr |= (5 << 3) | 4;
-
- /*
- * Allocate mbuf pointers
- */
- sc->rxMbuf = malloc (sc->rxBdCount * sizeof *sc->rxMbuf, M_MBUF, M_NOWAIT);
- sc->txMbuf = malloc (sc->txBdCount * sizeof *sc->txMbuf, M_MBUF, M_NOWAIT);
- if (!sc->rxMbuf || !sc->txMbuf)
- rtems_panic ("No memory for mbuf pointers");
-
- /*
- * Set receiver and transmitter buffer descriptor bases
- */
- sc->rxBdBase = M360AllocateBufferDescriptors(sc->rxBdCount);
- sc->txBdBase = M360AllocateBufferDescriptors(sc->txBdCount);
- m360.scc1p.rbase = (char *)sc->rxBdBase - (char *)&m360;
- m360.scc1p.tbase = (char *)sc->txBdBase - (char *)&m360;
-
- /*
- * Send "Init parameters" command
- */
- M360ExecuteRISC (M360_CR_OP_INIT_RX_TX | M360_CR_CHAN_SCC1);
-
- /*
- * Set receive and transmit function codes
- */
- m360.scc1p.rfcr = M360_RFCR_MOT | M360_RFCR_DMA_SPACE;
- m360.scc1p.tfcr = M360_TFCR_MOT | M360_TFCR_DMA_SPACE;
-
- /*
- * Set maximum receive buffer length
- */
- m360.scc1p.mrblr = RBUF_SIZE;
-
- /*
- * Set CRC parameters
- */
- m360.scc1p.un.ethernet.c_pres = 0xFFFFFFFF;
- m360.scc1p.un.ethernet.c_mask = 0xDEBB20E3;
-
- /*
- * Clear diagnostic counters
- */
- m360.scc1p.un.ethernet.crcec = 0;
- m360.scc1p.un.ethernet.alec = 0;
- m360.scc1p.un.ethernet.disfc = 0;
-
- /*
- * Set pad value
- */
- m360.scc1p.un.ethernet.pads = 0x8888;
-
- /*
- * Set retry limit
- */
- m360.scc1p.un.ethernet.ret_lim = 15;
-
- /*
- * Set maximum and minimum frame length
- */
- m360.scc1p.un.ethernet.mflr = 1518;
- m360.scc1p.un.ethernet.minflr = 64;
- m360.scc1p.un.ethernet.maxd1 = RBUF_SIZE;
- m360.scc1p.un.ethernet.maxd2 = RBUF_SIZE;
-
- /*
- * Clear group address hash table
- */
- m360.scc1p.un.ethernet.gaddr1 = 0;
- m360.scc1p.un.ethernet.gaddr2 = 0;
- m360.scc1p.un.ethernet.gaddr3 = 0;
- m360.scc1p.un.ethernet.gaddr4 = 0;
-
- /*
- * Set our physical address
- */
- hwaddr = sc->arpcom.ac_enaddr;
- m360.scc1p.un.ethernet.paddr_h = (hwaddr[5] << 8) | hwaddr[4];
- m360.scc1p.un.ethernet.paddr_m = (hwaddr[3] << 8) | hwaddr[2];
- m360.scc1p.un.ethernet.paddr_l = (hwaddr[1] << 8) | hwaddr[0];
-
- /*
- * Aggressive retry
- */
- m360.scc1p.un.ethernet.p_per = 0;
-
- /*
- * Clear individual address hash table
- */
- m360.scc1p.un.ethernet.iaddr1 = 0;
- m360.scc1p.un.ethernet.iaddr2 = 0;
- m360.scc1p.un.ethernet.iaddr3 = 0;
- m360.scc1p.un.ethernet.iaddr4 = 0;
-
- /*
- * Set up receive buffer descriptors
- */
- for (i = 0 ; i < sc->rxBdCount ; i++)
- (sc->rxBdBase + i)->status = 0;
-
- /*
- * Set up transmit buffer descriptors
- */
- for (i = 0 ; i < sc->txBdCount ; i++) {
- (sc->txBdBase + i)->status = 0;
- sc->txMbuf[i] = NULL;
- }
- sc->txBdHead = sc->txBdTail = 0;
- sc->txBdActiveCount = 0;
-
- /*
- * Clear any outstanding events
- */
- m360.scc1.scce = 0xFFFF;
-
- /*
- * Set up interrupts
- */
- status = rtems_interrupt_catch (m360Enet_interrupt_handler,
- (m360.cicr & 0xE0) | 0x1E,
- &old_handler);
- if (status != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't attach M360 SCC1 interrupt handler: %s\n",
- rtems_status_text (status));
- m360.scc1.sccm = 0; /* No interrupts unmasked till necessary */
- m360.cimr |= (1UL << 30); /* Enable SCC1 interrupt */
-
- /*
- * Set up General SCC Mode Register
- * Ethernet configuration
- */
- m360.scc1.gsmr_h = 0x0;
- m360.scc1.gsmr_l = 0x1088000c;
-
- /*
- * Set up data synchronization register
- * Ethernet synchronization pattern
- */
- m360.scc1.dsr = 0xd555;
-
- /*
- * Set up protocol-specific mode register
- * Heartbeat check
- * No force collision
- * Discard short frames
- * Individual address mode
- * Ethernet CRC
- * Not promisuous
- * Ignore/accept broadcast packets as specified
- * Normal backoff timer
- * No loopback
- * No input sample at end of frame
- * 64-byte limit for late collision
- * Wait 22 bits before looking for start of frame delimiter
- * Disable full-duplex operation
- */
- m360.scc1.psmr = 0x880A | (sc->acceptBroadcast ? 0 : 0x100);
-
- /*
- * Enable the TENA (RTS1*) pin
- */
-#if (defined (M68360_ATLAS_HSB))
- m360.pbpar |= 0x1000;
- m360.pbdir |= 0x1000;
-#else
- m360.pcpar |= 0x1;
- m360.pcdir &= ~0x1;
-#endif
-}
-
-/*
- * Soak up buffer descriptors that have been sent
- * Note that a buffer descriptor can't be retired as soon as it becomes
- * ready. The MC68360 Errata (May 96) says that, "If an Ethernet frame is
- * made up of multiple buffers, the user should not reuse the first buffer
- * descriptor until the last buffer descriptor of the frame has had its
- * ready bit cleared by the CPM".
- */
-static void
-m360Enet_retire_tx_bd (struct scc_softc *sc)
-{
- uint16_t status;
- int i;
- int nRetired;
- struct mbuf *m, *n;
- int retries = 0;
- int saveStatus = 0;
-
- i = sc->txBdTail;
- nRetired = 0;
- while ((sc->txBdActiveCount != 0)
- && (((status = (sc->txBdBase + i)->status) & M360_BD_READY) == 0)) {
- /*
- * Check for errors which stop the transmitter.
- */
- if (status & (M360_BD_LATE_COLLISION |
- M360_BD_RETRY_LIMIT |
- M360_BD_UNDERRUN)) {
- int j;
-
- if (status & M360_BD_LATE_COLLISION)
- sc->txLateCollision++;
- if (status & M360_BD_RETRY_LIMIT)
- sc->txRetryLimit++;
- if (status & M360_BD_UNDERRUN)
- sc->txUnderrun++;
-
- /*
- * Reenable buffer descriptors
- */
- j = sc->txBdTail;
- for (;;) {
- status = (sc->txBdBase + j)->status;
- if (status & M360_BD_READY)
- break;
- (sc->txBdBase + j)->status = M360_BD_READY |
- (status & (M360_BD_PAD |
- M360_BD_WRAP |
- M360_BD_INTERRUPT |
- M360_BD_LAST |
- M360_BD_TX_CRC));
- if (status & M360_BD_LAST)
- break;
- if (++j == sc->txBdCount)
- j = 0;
- }
-
- /*
- * Move transmitter back to the first
- * buffer descriptor in the frame.
- */
- m360.scc1p._tbptr = m360.scc1p.tbase +
- sc->txBdTail * sizeof (m360BufferDescriptor_t);
-
- /*
- * Restart the transmitter
- */
- M360ExecuteRISC (M360_CR_OP_RESTART_TX | M360_CR_CHAN_SCC1);
- continue;
- }
- saveStatus |= status;
- retries += (status >> 2) & 0xF;
- nRetired++;
- if (status & M360_BD_LAST) {
- /*
- * A full frame has been transmitted.
- * Free all the associated buffer descriptors.
- */
- if (saveStatus & M360_BD_DEFER)
- sc->txDeferred++;
- if (saveStatus & M360_BD_HEARTBEAT)
- sc->txHeartbeat++;
- if (saveStatus & M360_BD_CARRIER_LOST)
- sc->txLostCarrier++;
- saveStatus = 0;
- sc->txRetry += retries;
- retries = 0;
- sc->txBdActiveCount -= nRetired;
- while (nRetired) {
- nRetired--;
- m = sc->txMbuf[sc->txBdTail];
- MFREE (m, n);
- if (++sc->txBdTail == sc->txBdCount)
- sc->txBdTail = 0;
- }
- }
- if (++i == sc->txBdCount)
- i = 0;
- }
-}
-
-/*
- * SCC reader task
- */
-static void
-scc_rxDaemon (void *arg)
-{
- struct scc_softc *sc = (struct scc_softc *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mbuf *m;
- uint16_t status;
- volatile m360BufferDescriptor_t *rxBd;
- int rxBdIndex;
-
- /*
- * Allocate space for incoming packets and start reception
- */
- for (rxBdIndex = 0 ; ;) {
- rxBd = sc->rxBdBase + rxBdIndex;
- MGETHDR (m, M_WAIT, MT_DATA);
- MCLGET (m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod (m, void *);
- if (++rxBdIndex == sc->rxBdCount) {
- rxBd->status = M360_BD_EMPTY | M360_BD_INTERRUPT | M360_BD_WRAP;
- break;
- }
- rxBd->status = M360_BD_EMPTY | M360_BD_INTERRUPT;
- }
-
- /*
- * Input packet handling loop
- */
- rxBdIndex = 0;
- for (;;) {
- rxBd = sc->rxBdBase + rxBdIndex;
-
- /*
- * Wait for packet if there's not one ready
- */
- if ((status = rxBd->status) & M360_BD_EMPTY) {
- /*
- * Clear old events
- */
- m360.scc1.scce = 0x8;
-
- /*
- * Wait for packet
- * Note that the buffer descriptor is checked
- * *before* the event wait -- this catches the
- * possibility that a packet arrived between the
- * `if' above, and the clearing of the event register.
- */
- while ((status = rxBd->status) & M360_BD_EMPTY) {
- rtems_interrupt_level level;
- rtems_event_set events;
-
- /*
- * Unmask RXF (Full frame received) event
- */
- rtems_interrupt_disable (level);
- m360.scc1.sccm |= 0x8;
- rtems_interrupt_enable (level);
-
- rtems_bsdnet_event_receive (INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- }
- }
-
- /*
- * Check that packet is valid
- */
- if ((status & (M360_BD_LAST |
- M360_BD_FIRST_IN_FRAME |
- M360_BD_LONG |
- M360_BD_NONALIGNED |
- M360_BD_SHORT |
- M360_BD_CRC_ERROR |
- M360_BD_OVERRUN |
- M360_BD_COLLISION)) ==
- (M360_BD_LAST |
- M360_BD_FIRST_IN_FRAME)) {
- /*
- * Pass the packet up the chain.
- * FIXME: Packet filtering hook could be done here.
- */
- struct ether_header *eh;
-
- m = sc->rxMbuf[rxBdIndex];
- m->m_len = m->m_pkthdr.len = rxBd->length -
- sizeof(uint32_t) -
- sizeof(struct ether_header);
- eh = mtod (m, struct ether_header *);
- m->m_data += sizeof(struct ether_header);
- ether_input (ifp, eh, m);
-
- /*
- * Allocate a new mbuf
- */
- MGETHDR (m, M_WAIT, MT_DATA);
- MCLGET (m, M_WAIT);
- m->m_pkthdr.rcvif = ifp;
- sc->rxMbuf[rxBdIndex] = m;
- rxBd->buffer = mtod (m, void *);
- }
- else {
- /*
- * Something went wrong with the reception
- */
- if (!(status & M360_BD_LAST))
- sc->rxNotLast++;
- if (!(status & M360_BD_FIRST_IN_FRAME))
- sc->rxNotFirst++;
- if (status & M360_BD_LONG)
- sc->rxGiant++;
- if (status & M360_BD_NONALIGNED)
- sc->rxNonOctet++;
- if (status & M360_BD_SHORT)
- sc->rxRunt++;
- if (status & M360_BD_CRC_ERROR)
- sc->rxBadCRC++;
- if (status & M360_BD_OVERRUN)
- sc->rxOverrun++;
- if (status & M360_BD_COLLISION)
- sc->rxCollision++;
- }
-
- /*
- * Reenable the buffer descriptor
- */
- rxBd->status = (status & (M360_BD_WRAP | M360_BD_INTERRUPT)) | M360_BD_EMPTY;
-
- /*
- * Move to next buffer descriptor
- */
- if (++rxBdIndex == sc->rxBdCount)
- rxBdIndex = 0;
- }
-}
-
-static void
-sendpacket (struct ifnet *ifp, struct mbuf *m)
-{
- struct scc_softc *sc = ifp->if_softc;
- volatile m360BufferDescriptor_t *firstTxBd, *txBd;
- struct mbuf *l = NULL;
- uint16_t status;
- int nAdded;
-
- /*
- * Free up buffer descriptors
- */
- m360Enet_retire_tx_bd (sc);
-
- /*
- * Set up the transmit buffer descriptors.
- * No need to pad out short packets since the
- * hardware takes care of that automatically.
- * No need to copy the packet to a contiguous buffer
- * since the hardware is capable of scatter/gather DMA.
- */
- status = 0;
- nAdded = 0;
- txBd = firstTxBd = sc->txBdBase + sc->txBdHead;
- while (m) {
- /*
- * There are more mbufs in the packet than there
- * are transmit buffer descriptors.
- * Coalesce into a single buffer.
- */
- if (nAdded == sc->txBdCount) {
- struct mbuf *nm;
- int j;
- char *dest;
-
- /*
- * Get the pointer to the first mbuf of the packet
- */
- if (sc->txBdTail != sc->txBdHead)
- rtems_panic ("sendpacket coalesce");
- m = sc->txMbuf[sc->txBdTail];
-
- /*
- * Rescind the buffer descriptor READY bits
- */
- for (j = 0 ; j < sc->txBdCount ; j++)
- (sc->txBdBase + j)->status = 0;
-
- /*
- * Allocate an mbuf cluster
- * Toss the packet if allocation fails
- */
- MGETHDR (nm, M_DONTWAIT, MT_DATA);
- if (nm == NULL) {
- sc->txCoalesceFailed++;
- m_freem (m);
- return;
- }
- MCLGET (nm, M_DONTWAIT);
- if (nm->m_ext.ext_buf == NULL) {
- sc->txCoalesceFailed++;
- m_freem (m);
- m_free (nm);
- return;
- }
- nm->m_pkthdr = m->m_pkthdr;
- nm->m_len = nm->m_pkthdr.len;
-
- /*
- * Copy data from packet chain to mbuf cluster
- */
- sc->txCoalesced++;
- dest = nm->m_ext.ext_buf;
- while (m) {
- struct mbuf *n;
-
- if (m->m_len) {
- memcpy (dest, mtod(m, caddr_t), m->m_len);
- dest += m->m_len;
- }
- MFREE (m, n);
- m = n;
- }
-
- /*
- * Redo the send with the new mbuf cluster
- */
- m = nm;
- nAdded = 0;
- status = 0;
- continue;
- }
-
- /*
- * Wait for buffer descriptor to become available.
- */
- if ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- /*
- * Clear old events
- */
- m360.scc1.scce = 0x12;
-
- /*
- * Wait for buffer descriptor to become available.
- * Note that the buffer descriptors are checked
- * *before* entering the wait loop -- this catches
- * the possibility that a buffer descriptor became
- * available between the `if' above, and the clearing
- * of the event register.
- * This is to catch the case where the transmitter
- * stops in the middle of a frame -- and only the
- * last buffer descriptor in a frame can generate
- * an interrupt.
- */
- m360Enet_retire_tx_bd (sc);
- while ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
- rtems_interrupt_level level;
- rtems_event_set events;
-
- /*
- * Unmask TXB (buffer transmitted) and
- * TXE (transmitter error) events.
- */
- rtems_interrupt_disable (level);
- m360.scc1.sccm |= 0x12;
- rtems_interrupt_enable (level);
- rtems_bsdnet_event_receive (INTERRUPT_EVENT,
- RTEMS_WAIT|RTEMS_EVENT_ANY,
- RTEMS_NO_TIMEOUT,
- &events);
- m360Enet_retire_tx_bd (sc);
- }
- }
-
- /*
- * The IP fragmentation routine in ip_output
- * can produce packet fragments with zero length.
- */
- if (m->m_len) {
- /*
- * Fill in the buffer descriptor.
- * Don't set the READY flag in the first buffer
- * descriptor till the whole packet has been readied.
- */
- txBd = sc->txBdBase + sc->txBdHead;
- txBd->buffer = mtod (m, void *);
- txBd->length = m->m_len;
- sc->txMbuf[sc->txBdHead] = m;
- status = nAdded ? M360_BD_READY : 0;
- if (++sc->txBdHead == sc->txBdCount) {
- status |= M360_BD_WRAP;
- sc->txBdHead = 0;
- }
- txBd->status = status;
- l = m;
- m = m->m_next;
- nAdded++;
- }
- else {
- /*
- * Just toss empty mbufs
- */
- struct mbuf *n;
- MFREE (m, n);
- m = n;
- if (l != NULL)
- l->m_next = m;
- }
- }
- if (nAdded) {
- /*
- * Send the packet
- */
- txBd->status = status | M360_BD_PAD | M360_BD_LAST | M360_BD_TX_CRC | M360_BD_INTERRUPT;
- firstTxBd->status |= M360_BD_READY;
- sc->txBdActiveCount += nAdded;
- }
-}
-
-/*
- * Driver transmit daemon
- */
-void
-scc_txDaemon (void *arg)
-{
- struct scc_softc *sc = (struct scc_softc *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- struct mbuf *m;
- rtems_event_set events;
-
- for (;;) {
- /*
- * Wait for packet
- */
- rtems_bsdnet_event_receive (START_TRANSMIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &events);
-
- /*
- * Send packets till queue is empty
- */
- for (;;) {
- /*
- * Get the next mbuf chain to transmit.
- */
- IF_DEQUEUE(&ifp->if_snd, m);
- if (!m)
- break;
- sendpacket (ifp, m);
- }
- ifp->if_flags &= ~IFF_OACTIVE;
- }
-}
-
-/*
- * Send packet (caller provides header).
- */
-static void
-scc_start (struct ifnet *ifp)
-{
- struct scc_softc *sc = ifp->if_softc;
-
- rtems_bsdnet_event_send (sc->txDaemonTid, START_TRANSMIT_EVENT);
- ifp->if_flags |= IFF_OACTIVE;
-}
-
-/*
- * Initialize and start the device
- */
-static void
-scc_init (void *arg)
-{
- struct scc_softc *sc = arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- if (sc->txDaemonTid == 0) {
-
- /*
- * Set up SCC hardware
- */
- m360Enet_initialize_hardware (sc);
-
- /*
- * Start driver tasks
- */
- sc->txDaemonTid = rtems_bsdnet_newproc ("SCtx", 4096, scc_txDaemon, sc);
- sc->rxDaemonTid = rtems_bsdnet_newproc ("SCrx", 4096, scc_rxDaemon, sc);
-
- }
-
- /*
- * Set flags appropriately
- */
- if (ifp->if_flags & IFF_PROMISC)
- m360.scc1.psmr |= 0x200;
- else
- m360.scc1.psmr &= ~0x200;
-
- /*
- * Tell the world that we're running.
- */
- ifp->if_flags |= IFF_RUNNING;
-
- /*
- * Enable receiver and transmitter
- */
- m360.scc1.gsmr_l |= 0x30;
-}
-
-/*
- * Stop the device
- */
-static void
-scc_stop (struct scc_softc *sc)
-{
- struct ifnet *ifp = &sc->arpcom.ac_if;
-
- ifp->if_flags &= ~IFF_RUNNING;
-
- /*
- * Shut down receiver and transmitter
- */
- m360.scc1.gsmr_l &= ~0x30;
-}
-
-/*
- * Show interface statistics
- */
-static void
-scc_stats (struct scc_softc *sc)
-{
- printf (" Rx Interrupts:%-8lu", sc->rxInterrupts);
- printf (" Not First:%-8lu", sc->rxNotFirst);
- printf (" Not Last:%-8lu\n", sc->rxNotLast);
- printf (" Giant:%-8lu", sc->rxGiant);
- printf (" Runt:%-8lu", sc->rxRunt);
- printf (" Non-octet:%-8lu\n", sc->rxNonOctet);
- printf (" Bad CRC:%-8lu", sc->rxBadCRC);
- printf (" Overrun:%-8lu", sc->rxOverrun);
- printf (" Collision:%-8lu\n", sc->rxCollision);
- printf (" Discarded:%-8lu\n", (unsigned long)m360.scc1p.un.ethernet.disfc);
-
- printf (" Tx Interrupts:%-8lu", sc->txInterrupts);
- printf (" Deferred:%-8lu", sc->txDeferred);
- printf (" Missed Hearbeat:%-8lu\n", sc->txHeartbeat);
- printf (" No Carrier:%-8lu", sc->txLostCarrier);
- printf ("Retransmit Limit:%-8lu", sc->txRetryLimit);
- printf (" Late Collision:%-8lu\n", sc->txLateCollision);
- printf (" Underrun:%-8lu", sc->txUnderrun);
- printf (" Raw output wait:%-8lu", sc->txRawWait);
- printf (" Coalesced:%-8lu\n", sc->txCoalesced);
- printf (" Coalesce failed:%-8lu", sc->txCoalesceFailed);
- printf (" Retries:%-8lu\n", sc->txRetry);
-}
-
-/*
- * Driver ioctl handler
- */
-static int
-scc_ioctl (struct ifnet *ifp, ioctl_command_t command, caddr_t data)
-{
- struct scc_softc *sc = ifp->if_softc;
- int error = 0;
-
- switch (command) {
- case SIOCGIFADDR:
- case SIOCSIFADDR:
- ether_ioctl (ifp, command, data);
- break;
-
- case SIOCSIFFLAGS:
- switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
- case IFF_RUNNING:
- scc_stop (sc);
- break;
-
- case IFF_UP:
- scc_init (sc);
- break;
-
- case IFF_UP | IFF_RUNNING:
- scc_stop (sc);
- scc_init (sc);
- break;
-
- default:
- break;
- }
- break;
-
- case SIO_RTEMS_SHOW_STATS:
- scc_stats (sc);
- break;
-
- /*
- * FIXME: All sorts of multicast commands need to be added here!
- */
- default:
- error = EINVAL;
- break;
- }
- return error;
-}
-
-/*
- * Attach an SCC driver to the system
- */
-int
-rtems_scc1_driver_attach (struct rtems_bsdnet_ifconfig *config, int attaching)
-{
- struct scc_softc *sc;
- struct ifnet *ifp;
- int mtu;
- int unitNumber;
- char *unitName;
-
- /*
- * Make sure we're really being attached
- */
- if (!attaching) {
- printf ("SCC1 driver can not be detached.\n");
- return 0;
- }
-
- /*
- * Parse driver name
- */
- if ((unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName)) < 0)
- return 0;
-
- /*
- * Is driver free?
- */
- if ((unitNumber <= 0) || (unitNumber > NSCCDRIVER)) {
- printf ("Bad SCC unit number.\n");
- return 0;
- }
- sc = &scc_softc[unitNumber - 1];
- ifp = &sc->arpcom.ac_if;
- if (ifp->if_softc != NULL) {
- printf ("Driver already in use.\n");
- return 0;
- }
-
- /*
- * Process options
- */
- if (config->hardware_address) {
- memcpy (sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN);
- }
- else {
- /*
- * The first 4 bytes of the bootstrap prom
- * contain the value loaded into the stack
- * pointer as part of the CPU32's hardware
- * reset exception handler. The following
- * 4 bytes contain the value loaded into the
- * program counter. The boards' Ethernet
- * address is stored in the six bytes
- * immediately preceding this initial
- * program counter value.
- *
- * See start360/start360.s.
- */
- const unsigned long *ExceptionVectors;
- const unsigned char *entryPoint;
-
- /*
- * Sanity check -- assume entry point must be
- * within 1 MByte of beginning of boot ROM.
- */
- ExceptionVectors = (const unsigned long *)&_RomBase;
- entryPoint = (const unsigned char *)ExceptionVectors[1];
- if (((unsigned long)entryPoint - (unsigned long)ExceptionVectors)
- >= (1 * 1024 * 1024)) {
- printf ("Warning -- Ethernet address can not be found in bootstrap PROM.\n");
- sc->arpcom.ac_enaddr[0] = 0x08;
- sc->arpcom.ac_enaddr[1] = 0xF3;
- sc->arpcom.ac_enaddr[2] = 0x3E;
- sc->arpcom.ac_enaddr[3] = 0xC2;
- sc->arpcom.ac_enaddr[4] = 0x7E;
- sc->arpcom.ac_enaddr[5] = 0x38;
- }
- else {
- memcpy (sc->arpcom.ac_enaddr, entryPoint - ETHER_ADDR_LEN, ETHER_ADDR_LEN);
- }
- }
- if (config->mtu)
- mtu = config->mtu;
- else
- mtu = ETHERMTU;
- if (config->rbuf_count)
- sc->rxBdCount = config->rbuf_count;
- else
- sc->rxBdCount = RX_BUF_COUNT;
- if (config->xbuf_count)
- sc->txBdCount = config->xbuf_count;
- else
- sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;
- sc->acceptBroadcast = !config->ignore_broadcast;
-
- /*
- * Set up network interface values
- */
- ifp->if_softc = sc;
- ifp->if_unit = unitNumber;
- ifp->if_name = unitName;
- ifp->if_mtu = mtu;
- ifp->if_init = scc_init;
- ifp->if_ioctl = scc_ioctl;
- ifp->if_start = scc_start;
- ifp->if_output = ether_output;
- ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
- if (ifp->if_snd.ifq_maxlen == 0)
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
-
- /*
- * Attach the interface
- */
- if_attach (ifp);
- ether_ifattach (ifp);
- return 1;
-}
diff --git a/bsps/m68k/genmcf548x/net/network.c b/bsps/m68k/genmcf548x/net/network.c
deleted file mode 100644
index 646bd44870..0000000000
--- a/bsps/m68k/genmcf548x/net/network.c
+++ /dev/null
@@ -1,1696 +0,0 @@
-/*===============================================================*\
-| Project: RTEMS generic MCF548X BSP |
-+-----------------------------------------------------------------+
-| Partially based on the code references which are named below. |
-| Adaptions, modifications, enhancements and any recent parts of |
-| the code are: |
-| Copyright (c) 2009 |
-| Embedded Brains GmbH |
-| Obere Lagerstr. 30 |
-| D-82178 Puchheim |
-| Germany |
-| rtems@embedded-brains.de |
-+-----------------------------------------------------------------+
-| The license and distribution terms for this file may be |
-| found in the file LICENSE in this distribution or at |
-| |
-| http://www.rtems.org/license/LICENSE. |
-| |
-+-----------------------------------------------------------------+
-| this file contains the networking driver |
-\*===============================================================*/
-/*
- * RTEMS/TCPIP driver for MCF548X FEC Ethernet
- *
- * Modified for Motorola MPC5200 by Thomas Doerfler, <Thomas.Doerfler@imd-systems.de>
- * COPYRIGHT (c) 2003, IMD
- *
- * Modified for Motorola IceCube (mgt5100) by Peter Rasmussen <prasmus@ipr-engineering.de>
- * COPYRIGHT (c) 2003, IPR Engineering
- *
- * Parts of code are also under property of Driver Information Systems and based
- * on Motorola Proprietary Information.
- * COPYRIGHT (c) 2002 MOTOROLA INC.
- *
- * Modified for Motorola MCF548X by Thomas Doerfler, <Thomas.Doerfler@imd-systems.de>
- * COPYRIGHT (c) 2009, IMD
- *
- */
-
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <rtems.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-#include <stdio.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <net/if_var.h>
-
-#include <bsp.h>
-#include <bsp/irq-generic.h>
-#include <mcf548x/mcf548x.h>
-#include <rtems/rtems_mii_ioctl.h>
-#include <errno.h>
-
-/* freescale-api-specifics... */
-#include <mcf548x/MCD_dma.h>
-#include <mcf548x/mcdma_glue.h>
-
-/*
- * Number of interfaces supported by this driver
- */
-#define NIFACES 2
-
-#define FEC_WATCHDOG_TIMEOUT 5 /* check media every 5 seconds */
-
-#define DMA_BD_RX_NUM 32 /* Number of receive buffer descriptors */
-#define DMA_BD_TX_NUM 32 /* Number of transmit buffer descriptors */
-
-#define FEC_EVENT RTEMS_EVENT_0
-
-/*
- * internal SRAM
- * Layout:
- * - RxBD channel 0
- * - TxBD channel 0
- * - RxBD channel 1
- * - TxBD channel 1
- * - DMA task memory
- */
-extern char _SysSramBase[];
-#define SRAM_RXBD_BASE(base,chan) (((MCD_bufDescFec*)(base)) \
- +((chan) \
- *(DMA_BD_RX_NUM+DMA_BD_TX_NUM)))
-
-#define SRAM_TXBD_BASE(base,chan) (((MCD_bufDescFec*)(base)) \
- +((chan) \
- *(DMA_BD_RX_NUM+DMA_BD_TX_NUM) \
- +DMA_BD_RX_NUM))
-
-#define SRAM_DMA_BASE(base) ((void *)SRAM_RXBD_BASE(base,NIFACES+1))
-
-
-#undef ETH_DEBUG
-
-/*
- * Default number of buffer descriptors set aside for this driver.
- * The number of transmit buffer descriptors has to be quite large
- * since a single frame often uses four or more buffer descriptors.
- */
-#define RX_BUF_COUNT DMA_BD_RX_NUM
-#define TX_BUF_COUNT DMA_BD_TX_NUM
-#define TX_BD_PER_BUF 1
-
-#define INET_ADDR_MAX_BUF_SIZE (sizeof "255.255.255.255")
-
-#define MCF548X_FEC0_IRQ_VECTOR (39+64)
-#define MCF548X_FEC1_IRQ_VECTOR (38+64)
-
-#define MCF548X_FEC_IRQ_VECTOR(chan) (MCF548X_FEC0_IRQ_VECTOR \
- +(chan)*(MCF548X_FEC1_IRQ_VECTOR \
- -MCF548X_FEC0_IRQ_VECTOR))
-
-#define MCF548X_FEC_VECTOR2CHAN(vector) (((int)(vector)-MCF548X_FEC0_IRQ_VECTOR) \
- /(MCF548X_FEC1_IRQ_VECTOR \
- -MCF548X_FEC0_IRQ_VECTOR))
-
-#define MCDMA_FEC_RX_CHAN(chan) (0 + NIFACES*(chan))
-#define MCDMA_FEC_TX_CHAN(chan) (1 + NIFACES*(chan))
-
-#define MCF548X_FEC0_RX_INITIATOR (16)
-#define MCF548X_FEC1_RX_INITIATOR (30)
-#define MCF548X_FEC_RX_INITIATOR(chan) (MCF548X_FEC0_RX_INITIATOR \
- +(chan)*(MCF548X_FEC1_RX_INITIATOR \
- -MCF548X_FEC0_RX_INITIATOR))
-#define MCF548X_FEC0_TX_INITIATOR (17)
-#define MCF548X_FEC1_TX_INITIATOR (31)
-#define MCF548X_FEC_TX_INITIATOR(chan) (MCF548X_FEC0_TX_INITIATOR \
- +(chan)*(MCF548X_FEC1_TX_INITIATOR \
- -MCF548X_FEC0_TX_INITIATOR))
-
-/* BD and parameters are stored in SRAM(refer to sdma.h) */
-#define MCF548X_FEC_BD_BASE ETH_BD_BASE
-
-/* RBD bits definitions */
-#define MCF548X_FEC_RBD_EMPTY 0x8000 /* Buffer is empty */
-#define MCF548X_FEC_RBD_WRAP 0x2000 /* Last BD in ring */
-#define MCF548X_FEC_RBD_INT 0x1000 /* Interrupt */
-#define MCF548X_FEC_RBD_LAST 0x0800 /* Buffer is last in frame(useless) */
-#define MCF548X_FEC_RBD_MISS 0x0100 /* Miss bit for prom mode */
-#define MCF548X_FEC_RBD_BC 0x0080 /* The received frame is broadcast frame */
-#define MCF548X_FEC_RBD_MC 0x0040 /* The received frame is multicast frame */
-#define MCF548X_FEC_RBD_LG 0x0020 /* Frame length violation */
-#define MCF548X_FEC_RBD_NO 0x0010 /* Nonoctet align frame */
-#define MCF548X_FEC_RBD_SH 0x0008 /* Short frame, FEC does not support SH and this bit is always cleared */
-#define MCF548X_FEC_RBD_CR 0x0004 /* CRC error */
-#define MCF548X_FEC_RBD_OV 0x0002 /* Receive FIFO overrun */
-#define MCF548X_FEC_RBD_TR 0x0001 /* The receive frame is truncated */
-#define MCF548X_FEC_RBD_ERR (MCF548X_FEC_RBD_LG | \
- MCF548X_FEC_RBD_NO | \
- MCF548X_FEC_RBD_CR | \
- MCF548X_FEC_RBD_OV | \
- MCF548X_FEC_RBD_TR)
-
-/* TBD bits definitions */
-#define MCF548X_FEC_TBD_READY 0x8000 /* Buffer is ready */
-#define MCF548X_FEC_TBD_WRAP 0x2000 /* Last BD in ring */
-#define MCF548X_FEC_TBD_INT 0x1000 /* Interrupt */
-#define MCF548X_FEC_TBD_LAST 0x0800 /* Buffer is last in frame */
-#define MCF548X_FEC_TBD_TC 0x0400 /* Transmit the CRC */
-#define MCF548X_FEC_TBD_ABC 0x0200 /* Append bad CRC */
-
-#define FEC_INTR_MASK_USED \
-(MCF548X_FEC_EIMR_LC | MCF548X_FEC_EIMR_RL | \
- MCF548X_FEC_EIMR_XFUN | MCF548X_FEC_EIMR_XFERR | MCF548X_FEC_EIMR_RFERR)
-
-typedef enum {
- FEC_STATE_RESTART_0,
- FEC_STATE_RESTART_1,
- FEC_STATE_NORMAL,
-} fec_state;
-
-/*
- * Device data
- */
-struct mcf548x_enet_struct {
- struct arpcom arpcom;
- struct mbuf **rxMbuf;
- struct mbuf **txMbuf;
- int chan;
- fec_state state;
- int acceptBroadcast;
- int rxBdCount;
- int txBdCount;
- MCD_bufDescFec *rxBd;
- MCD_bufDescFec *txBd;
- int rxDmaChan; /* dma task */
- int txDmaChan; /* dma task */
- rtems_id rxDaemonTid;
- rtems_id txDaemonTid;
-
- /*
- * MDIO/Phy info
- */
- struct rtems_mdio_info mdio_info;
- int phy_default;
- int phy_chan; /* which fec channel services this phy access? */
- int media_state; /* (last detected) state of media */
-
- unsigned long rxInterrupts;
- unsigned long rxNotLast;
- unsigned long rxGiant;
- unsigned long rxNonOctet;
- unsigned long rxBadCRC;
- unsigned long rxFIFOError;
- unsigned long rxCollision;
-
- unsigned long txInterrupts;
- unsigned long txDeferred;
- unsigned long txLateCollision;
- unsigned long txUnderrun;
- unsigned long txFIFOError;
- unsigned long txMisaligned;
- unsigned long rxNotFirst;
- unsigned long txRetryLimit;
- };
-
-static struct mcf548x_enet_struct enet_driver[NIFACES];
-
-static void mcf548x_fec_restart(struct mcf548x_enet_struct *sc, rtems_id otherDaemon);
-
-static void fec_send_event(rtems_id task)
-{
- rtems_bsdnet_event_send(task, FEC_EVENT);
-}
-
-static void fec_wait_for_event(void)
-{
- rtems_event_set out;
- rtems_bsdnet_event_receive(
- FEC_EVENT,
- RTEMS_EVENT_ANY | RTEMS_WAIT,
- RTEMS_NO_TIMEOUT,
- &out
- );
-}
-
-static void mcf548x_fec_request_restart(struct mcf548x_enet_struct *sc)
-{
- sc->state = FEC_STATE_RESTART_0;
- fec_send_event(sc->txDaemonTid);
- fec_send_event(sc->rxDaemonTid);
-}
-
-/*
- * Function: MCF548X_eth_addr_filter_set
- *
- * Description: Set individual address filter for unicast address and
- * set physical address registers.
- *
- * Returns: void
- *
- * Notes:
- *
- */
-static void mcf548x_eth_addr_filter_set(struct mcf548x_enet_struct *sc) {
- unsigned char *mac;
- unsigned char currByte; /* byte for which to compute the CRC */
- int byte; /* loop - counter */
- int bit; /* loop - counter */
- unsigned long crc = 0xffffffff; /* initial value */
- int chan = sc->chan;
-
- /*
- * Get the mac address of ethernet controller
- */
- mac = (unsigned char *)(&sc->arpcom.ac_enaddr);
-
- /*
- * The algorithm used is the following:
- * we loop on each of the six bytes of the provided address,
- * and we compute the CRC by left-shifting the previous
- * value by one position, so that each bit in the current
- * byte of the address may contribute the calculation. If
- * the latter and the MSB in the CRC are different, then
- * the CRC value so computed is also ex-ored with the
- * "polynomium generator". The current byte of the address
- * is also shifted right by one bit at each iteration.
- * This is because the CRC generatore in hardware is implemented
- * as a shift-register with as many ex-ores as the radixes
- * in the polynomium. This suggests that we represent the
- * polynomiumm itsc as a 32-bit constant.
- */
- for(byte = 0; byte < 6; byte++)
- {
-
- currByte = mac[byte];
-
- for(bit = 0; bit < 8; bit++)
- {
-
- if((currByte & 0x01) ^ (crc & 0x01))
- {
-
- crc >>= 1;
- crc = crc ^ 0xedb88320;
-
- }
- else
- {
-
- crc >>= 1;
-
- }
-
- currByte >>= 1;
-
- }
-
- }
-
- crc = crc >> 26;
-
- /*
- * Set individual hash table register
- */
- if(crc >= 32)
- {
-
- MCF548X_FEC_IAUR(chan) = (1 << (crc - 32));
- MCF548X_FEC_IALR(chan) = 0;
-
- }
- else
- {
-
- MCF548X_FEC_IAUR(chan) = 0;
- MCF548X_FEC_IALR(chan) = (1 << crc);
-
- }
-
- /*
- * Set physical address
- */
- MCF548X_FEC_PALR(chan) = ((mac[0] << 24) +
- (mac[1] << 16) +
- (mac[2] << 8) +
- mac[3]);
- MCF548X_FEC_PAUR(chan) = ((mac[4] << 24)
- + (mac[5] << 16)) + 0x8808;
-
- }
-
-
-/*
- * Function: mcf548x_eth_mii_read
- *
- * Description: Read a media independent interface (MII) register on an
- * 18-wire ethernet tranceiver (PHY). Please see your PHY
- * documentation for the register map.
- *
- * Returns: 0 if ok
- *
- * Notes:
- *
- */
-int mcf548x_eth_mii_read(
- int phyAddr, /* PHY number to access or -1 */
- void *uarg, /* unit argument */
- unsigned regAddr, /* register address */
- uint32_t *retVal) /* ptr to read buffer */
-{
- struct mcf548x_enet_struct *sc = uarg;
- int timeout = 0xffff;
- int chan = sc->phy_chan;
-
- /*
- * reading from any PHY's register is done by properly
- * programming the FEC's MII data register.
- */
- MCF548X_FEC_MMFR(chan) = (MCF548X_FEC_MMFR_ST_01 |
- MCF548X_FEC_MMFR_OP_READ |
- MCF548X_FEC_MMFR_TA_10 |
- MCF548X_FEC_MMFR_PA(phyAddr) |
- MCF548X_FEC_MMFR_RA(regAddr));
-
- /*
- * wait for the related interrupt
- */
- while ((timeout--) && (!(MCF548X_FEC_EIR(chan) & MCF548X_FEC_EIR_MII)));
-
- if(timeout == 0) {
-
-#ifdef ETH_DEBUG
- iprintf ("Read MDIO failed..." "\r\n");
-#endif
-
- return 1;
-
- }
-
- /*
- * clear mii interrupt bit
- */
- MCF548X_FEC_EIR(chan) = MCF548X_FEC_EIR_MII;
-
- /*
- * it's now safe to read the PHY's register
- */
- *retVal = (unsigned short) MCF548X_FEC_MMFR(chan);
-
- return 0;
-
-}
-
-/*
- * Function: mcf548x_eth_mii_write
- *
- * Description: Write a media independent interface (MII) register on an
- * 18-wire ethernet tranceiver (PHY). Please see your PHY
- * documentation for the register map.
- *
- * Returns: Success (boolean)
- *
- * Notes:
- *
- */
-static int mcf548x_eth_mii_write(
- int phyAddr, /* PHY number to access or -1 */
- void *uarg, /* unit argument */
- unsigned regAddr, /* register address */
- uint32_t data) /* write data */
-{
- struct mcf548x_enet_struct *sc = uarg;
- int chan = sc->phy_chan;
- int timeout = 0xffff;
-
- MCF548X_FEC_MMFR(chan) = (MCF548X_FEC_MMFR_ST_01 |
- MCF548X_FEC_MMFR_OP_WRITE |
- MCF548X_FEC_MMFR_TA_10 |
- MCF548X_FEC_MMFR_PA(phyAddr) |
- MCF548X_FEC_MMFR_RA(regAddr) |
- MCF548X_FEC_MMFR_DATA(data));
-
- /*
- * wait for the MII interrupt
- */
- while ((timeout--) && (!(MCF548X_FEC_EIR(chan) & MCF548X_FEC_EIR_MII)));
-
- if(timeout == 0)
- {
-
-#ifdef ETH_DEBUG
- iprintf ("Write MDIO failed..." "\r\n");
-#endif
-
- return 1;
-
- }
-
- /*
- * clear MII interrupt bit
- */
- MCF548X_FEC_EIR(chan) = MCF548X_FEC_EIR_MII;
-
- return 0;
-
- }
-
-
-/*
- * Function: mcf548x_fec_reset
- *
- * Description: Reset a running ethernet driver including the hardware
- * FIFOs and the FEC.
- *
- * Returns: Success (boolean)
- *
- * Notes:
- *
- */
-static void mcf548x_fec_reset(struct mcf548x_enet_struct *sc) {
- volatile int delay;
- int chan = sc->chan;
- /*
- * Clear FIFO status registers
- */
- MCF548X_FEC_FECRFSR(chan) = ~0;
- MCF548X_FEC_FECTFSR(chan) = ~0;
-
- /*
- * reset the FIFOs
- */
- MCF548X_FEC_FRST(chan) = 0x03000000;
-
- for (delay = 0;delay < 16*4;delay++) {};
-
- MCF548X_FEC_FRST(chan) = 0x01000000;
-
- /*
- * Issue a reset command to the FEC chip
- */
- MCF548X_FEC_ECR(chan) |= MCF548X_FEC_ECR_RESET;
-
- /*
- * wait at least 16 clock cycles
- */
- for (delay = 0;delay < 16*4;delay++) {};
-}
-
-
-/*
- * Function: mcf548x_fec_off
- *
- * Description: Stop the FEC and disable the ethernet SmartComm tasks.
- * This function "turns off" the driver.
- *
- * Returns: void
- *
- * Notes:
- *
- */
-void mcf548x_fec_off(struct mcf548x_enet_struct *sc)
- {
- int counter = 0xffff;
- int chan = sc->chan;
-
-
-#if defined(ETH_DEBUG)
- uint32_t phyStatus;
- int i;
-
- for(i = 0; i < 9; i++)
- {
-
- mcf548x_eth_mii_read(sc->phy_default, sc, i, &phyStatus);
- iprintf ("Mii reg %d: 0x%04lx" "\r\n", i, phyStatus);
-
- }
-
- for(i = 16; i < 21; i++)
- {
-
- mcf548x_eth_mii_read(sc->phy_default, sc, i, &phyStatus);
- iprintf ("Mii reg %d: 0x%04lx" "\r\n", i, phyStatus);
-
- }
- for(i = 0; i < 32; i++)
- {
-
- mcf548x_eth_mii_read(i, sc, 0, &phyStatus);
- iprintf ("Mii Phy=%d, reg 0: 0x%04lx" "\r\n", i, phyStatus);
-
- }
-#endif /* ETH_DEBUG */
-
- /*
- * block FEC chip interrupts
- */
- MCF548X_FEC_EIMR(chan) = 0;
-
- /*
- * issue graceful stop command to the FEC transmitter if necessary
- */
- MCF548X_FEC_TCR(chan) |= MCF548X_FEC_TCR_GTS;
-
- /*
- * wait for graceful stop to register
- * FIXME: add rtems_task_wake_after here, if it takes to long
- */
- while((counter--) && (!( MCF548X_FEC_EIR(chan) & MCF548X_FEC_EIR_GRA)));
-
- /*
- * Disable the SmartDMA transmit and receive tasks.
- */
- MCD_killDma( sc->rxDmaChan );
- MCD_killDma( sc->txDmaChan );
- /*
- * Disable transmit / receive interrupts
- */
- mcdma_glue_irq_disable(sc->txDmaChan);
- mcdma_glue_irq_disable(sc->rxDmaChan);
-
- /*
- * Disable the Ethernet Controller
- */
- MCF548X_FEC_ECR(chan) &= ~(MCF548X_FEC_ECR_ETHER_EN);
-}
-
-/*
- * MCF548X FEC interrupt handler
- */
-void mcf548x_fec_irq_handler(rtems_vector_number vector)
-{
- struct mcf548x_enet_struct *sc;
- volatile uint32_t ievent;
- int chan;
-
- sc = &(enet_driver[MCF548X_FEC_VECTOR2CHAN(vector)]);
- chan = sc->chan;
- ievent = MCF548X_FEC_EIR(chan);
-
- MCF548X_FEC_EIR(chan) = ievent;
- /*
- * check errors, update statistics
- */
- if (ievent & MCF548X_FEC_EIR_LC) {
- sc->txLateCollision++;
- }
- if (ievent & MCF548X_FEC_EIR_RL) {
- sc->txRetryLimit++;
- }
- if (ievent & MCF548X_FEC_EIR_XFUN) {
- sc->txUnderrun++;
- }
- if (ievent & MCF548X_FEC_EIR_XFERR) {
- sc->txFIFOError++;
- }
- if (ievent & MCF548X_FEC_EIR_RFERR) {
- sc->rxFIFOError++;
- }
- /*
- * fatal error occurred?
- */
- if (ievent & (MCF548X_FEC_EIR_RFERR | MCF548X_FEC_EIR_XFERR)) {
- MCF548X_FEC_EIMR(chan) &=~(MCF548X_FEC_EIMR_RFERR | MCF548X_FEC_EIMR_XFERR);
- printk("fifo\n");
- mcf548x_fec_request_restart(sc);
- }
-}
-
-/*
- * MCF548X DMA ethernet interrupt handler
- */
-void mcf548x_mcdma_rx_irq_handler(void * param)
-{
- struct mcf548x_enet_struct *sc = (struct mcf548x_enet_struct *)param;
- /* Frame received? */
- if(MCDMA_GET_PENDING(sc->rxDmaChan)) {
- MCDMA_CLR_PENDING(sc->rxDmaChan);
-
- mcdma_glue_irq_disable(sc->rxDmaChan);/*Disable receive ints*/
- sc->rxInterrupts++; /* Rx int has occurred */
- fec_send_event(sc->rxDaemonTid);
- }
-}
-
-/*
- * MCF548X DMA ethernet interrupt handler
- */
-void mcf548x_mcdma_tx_irq_handler(void * param)
-{
- struct mcf548x_enet_struct *sc = (struct mcf548x_enet_struct *)param;
-
- /* Buffer transmitted or transmitter error? */
- if(MCDMA_GET_PENDING(sc->txDmaChan)) {
-
- MCDMA_CLR_PENDING(sc->txDmaChan);
-
- mcdma_glue_irq_disable(sc->txDmaChan);/*Disable tx ints*/
-
- sc->txInterrupts++; /* Tx int has occurred */
-
- fec_send_event(sc->txDaemonTid);
- }
-}
-
-/*
- * Function: mcf548x_fec_initialize_hardware
- *
- * Description: Configure the MCF548X FEC registers and enable the
- * SmartComm tasks. This function "turns on" the driver.
- *
- * Returns: void
- *
- * Notes:
- *
- */
-static void mcf548x_fec_initialize_hardware(struct mcf548x_enet_struct *sc)
- {
- int chan = sc->chan;
-
- /*
- * Reset mcf548x FEC
- */
- mcf548x_fec_reset(sc);
-
- /*
- * Clear FEC-Lite interrupt event register (IEVENT)
- */
- MCF548X_FEC_EIR(chan) = MCF548X_FEC_EIR_CLEAR_ALL;
-
- /*
- * Set interrupt mask register
- */
- MCF548X_FEC_EIMR(chan) = FEC_INTR_MASK_USED;
- /*
- * Set FEC-Lite receive control register (R_CNTRL)
- * frame length=1518, MII mode for 18-wire-transceiver
- */
- MCF548X_FEC_RCR(chan) = (MCF548X_FEC_RCR_MAX_FL(ETHER_MAX_LEN)
- | MCF548X_FEC_RCR_FCE
- | MCF548X_FEC_RCR_MII_MODE);
-
- /*
- * Set FEC-Lite transmit control register (X_CNTRL)
- * full-duplex, heartbeat disabled
- */
- MCF548X_FEC_TCR(chan) = MCF548X_FEC_TCR_FDEN;
-
-
-
- /*
- * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock(33Mhz)
- * and do not drop the Preamble.
- */
- MCF548X_FEC_MSCR(chan) = MCF548X_FEC_MSCR_MII_SPEED(7); /* ipb_clk = 33 MHz */
-
- /*
- * Set Opcode/Pause Duration Register
- */
- MCF548X_FEC_PAUR(chan) = 0x00010020;
-
- /*
- * Set Rx FIFO alarm and granularity value
- */
- MCF548X_FEC_FECRFCR(chan) = (MCF548X_FEC_FECRFCR_FRM
- | MCF548X_FEC_FECRFCR_GR(0x7));
- MCF548X_FEC_FECRFAR(chan) = MCF548X_FEC_FECRFAR_ALARM(256);
-
- /*
- * Set Tx FIFO granularity value
- */
- MCF548X_FEC_FECTFCR(chan) = (MCF548X_FEC_FECTFCR_FRM
- | MCF548X_FEC_FECTFCR_GR(7));
-
- /*
- * Set transmit fifo watermark register (X_WMRK), default = 64
- */
- MCF548X_FEC_FECTFAR(chan) = MCF548X_FEC_FECTFAR_ALARM(512);
- MCF548X_FEC_FECTFWR(chan) = MCF548X_FEC_FECTFWR_X_WMRK_256;
-
- /*
- * Set individual address filter for unicast address
- * and set physical address registers.
- */
- mcf548x_eth_addr_filter_set(sc);
-
- /*
- * Set multicast address filter
- */
- MCF548X_FEC_GAUR(chan) = 0x00000000;
- MCF548X_FEC_GALR(chan) = 0x00000000;
-
- /*
- * enable CRC in finite state machine register
- */
- MCF548X_FEC_CTCWR(chan) = MCF548X_FEC_CTCWR_TFCW | MCF548X_FEC_CTCWR_CRC;
- }
-
-
-/*
- * Send packet (caller provides header).
- */
-static void mcf548x_fec_tx_start(struct ifnet *ifp)
- {
-
- struct mcf548x_enet_struct *sc = ifp->if_softc;
-
- ifp->if_flags |= IFF_OACTIVE;
-
- fec_send_event(sc->txDaemonTid);
-
- }
-
-static void fec_start_dma_and_controller(struct mcf548x_enet_struct *sc)
-{
- int chan = sc->chan;
- int mcdma_rc;
- /*
- * Enable the SmartDMA receive task.
- */
- mcdma_rc = MCD_startDma
- (sc->rxDmaChan, /* the channel on which to run the DMA */
- (void *)sc->rxBd, /* the address to move data from, or buffer-descriptor addr */
- 0, /* the amount to increment the source address per transfer */
- (void *)&MCF548X_FEC_FECRFDR(chan), /* the address to move data to */
- 0, /* the amount to increment the destination address per transfer */
- ETHER_MAX_LEN, /* the number of bytes to transfer independent of the transfer size */
- 0, /* the number bytes in of each data movement (1, 2, or 4) */
- MCF548X_FEC_RX_INITIATOR(chan), /* what device initiates the DMA */
- 2, /* priority of the DMA */
- 0 /* flags describing the DMA */
- | MCD_FECRX_DMA
- | MCD_INTERRUPT
- | MCD_TT_FLAGS_CW
- | MCD_TT_FLAGS_RL
- | MCD_TT_FLAGS_SP
- ,
- 0 /* a description of byte swapping, bit swapping, and CRC actions */
- | MCD_NO_CSUM
- | MCD_NO_BYTE_SWAP
- );
- if (mcdma_rc != MCD_OK) {
- rtems_panic("FEC: cannot start rx DMA");
- }
- mcdma_rc = MCD_startDma
- (sc->txDmaChan, /* the channel on which to run the DMA */
- (void *)sc->txBd, /* the address to move data from, or buffer-descriptor addr */
- 0, /* the amount to increment the source address per transfer */
- (void *)&MCF548X_FEC_FECTFDR(chan), /* the address to move data to */
- 0, /* the amount to increment the destination address per transfer */
- ETHER_MAX_LEN, /* the number of bytes to transfer independent of the transfer size */
- 0, /* the number bytes in of each data movement (1, 2, or 4) */
- MCF548X_FEC_TX_INITIATOR(chan), /* what device initiates the DMA */
- 1, /* priority of the DMA */
- 0 /* flags describing the DMA */
- | MCD_FECTX_DMA
- | MCD_INTERRUPT
- | MCD_TT_FLAGS_CW
- | MCD_TT_FLAGS_RL
- | MCD_TT_FLAGS_SP
- ,
- 0 /* a description of byte swapping, bit swapping, and CRC actions */
- | MCD_NO_CSUM
- | MCD_NO_BYTE_SWAP
- );
- if (mcdma_rc != MCD_OK) {
- rtems_panic("FEC: cannot start tx DMA");
- }
-
- /*
- * Enable FEC-Lite controller
- */
- MCF548X_FEC_ECR(chan) |= MCF548X_FEC_ECR_ETHER_EN;
-}
-
-static void mcf548x_fec_restart(struct mcf548x_enet_struct *sc, rtems_id otherDaemon)
-{
- if (sc->state == FEC_STATE_RESTART_1) {
- mcf548x_fec_initialize_hardware(sc);
- fec_start_dma_and_controller(sc);
- sc->state = FEC_STATE_NORMAL;
- } else {
- sc->state = FEC_STATE_RESTART_1;
- }
-
- fec_send_event(otherDaemon);
- while (sc->state != FEC_STATE_NORMAL) {
- fec_wait_for_event();
- }
-}
-
-static void fec_reset_bd_and_discard_tx_frames(
- int bdCount,
- MCD_bufDescFec *bdRing,
- struct mbuf **mbufs
-)
-{
- int bdIndex = 0;
-
- for (bdIndex = 0; bdIndex < bdCount; ++bdIndex) {
- bool bdIsLast = bdIndex == bdCount - 1;
- struct mbuf *m = mbufs[bdIndex];
-
- bdRing[bdIndex].statCtrl = bdIsLast ? MCF548X_FEC_TBD_WRAP : 0;
-
- if (m != NULL) {
- mbufs[bdIndex] = NULL;
- m_free(m);
- }
- }
-}
-
-static void fec_reset_tx_dma(
- int dmaChan,
- int bdCount,
- MCD_bufDescFec *bdRing,
- struct mbuf **mbufs,
- struct mbuf *m
-)
-{
- if (m != NULL) {
- m_freem(m);
- }
-
- MCD_killDma(dmaChan);
-
- fec_reset_bd_and_discard_tx_frames(bdCount, bdRing, mbufs);
-}
-
-static struct mbuf *fec_next_fragment(
- struct ifnet *ifp,
- struct mbuf *m,
- bool *isFirst
-)
-{
- struct mbuf *n = NULL;
-
- *isFirst = false;
-
- while (true) {
- if (m == NULL) {
- IF_DEQUEUE(&ifp->if_snd, m);
-
- if (m != NULL) {
- *isFirst = true;
- } else {
- ifp->if_flags &= ~IFF_OACTIVE;
-
- return NULL;
- }
- }
-
- if (m->m_len > 0) {
- break;
- } else {
- m = m_free(m);
- }
- }
-
- n = m->m_next;
- while (n != NULL && n->m_len <= 0) {
- n = m_free(n);
- }
- m->m_next = n;
-
- return m;
-}
-
-static bool fec_transmit(
- struct ifnet *ifp,
- int dmaChan,
- int bdCount,
- MCD_bufDescFec *bdRing,
- struct mbuf **mbufs,
- int *bdIndexPtr,
- struct mbuf **mPtr,
- MCD_bufDescFec **firstPtr
-)
-{
- bool bdShortage = false;
- int bdIndex = *bdIndexPtr;
- struct mbuf *m = *mPtr;
- MCD_bufDescFec *first = *firstPtr;
-
- while (true) {
- MCD_bufDescFec *bd = &bdRing[bdIndex];
-
- MCDMA_CLR_PENDING(dmaChan);
- if ((bd->statCtrl & MCF548X_FEC_TBD_READY) == 0) {
- struct mbuf *done = mbufs[bdIndex];
- bool isFirst = false;
-
- if (done != NULL) {
- m_free(done);
- mbufs[bdIndex] = NULL;
- }
-
- m = fec_next_fragment(ifp, m, &isFirst);
- if (m != NULL) {
- bool bdIsLast = bdIndex == bdCount - 1;
- u16 status = bdIsLast ? MCF548X_FEC_TBD_WRAP : 0;
-
- bd->length = (u16) m->m_len;
- bd->dataPointer = mtod(m, u32);
-
- mbufs[bdIndex] = m;
-
- rtems_cache_flush_multiple_data_lines(mtod(m, void *), m->m_len);
-
- if (isFirst) {
- first = bd;
- } else {
- status |= MCF548X_FEC_TBD_READY;
- }
-
- if (m->m_next != NULL) {
- bd->statCtrl = status;
- } else {
- bd->statCtrl = status | MCF548X_FEC_TBD_INT | MCF548X_FEC_TBD_LAST;
- first->statCtrl |= MCF548X_FEC_TBD_READY;
- MCD_continDma(dmaChan);
- }
-
- m = m->m_next;
- } else {
- break;
- }
- } else {
- bdShortage = true;
- break;
- }
-
- if (bdIndex < bdCount - 1) {
- ++bdIndex;
- } else {
- bdIndex = 0;
- }
- }
-
- *bdIndexPtr = bdIndex;
- *mPtr = m;
- *firstPtr = first;
-
- return bdShortage;
-}
-
-static MCD_bufDescFec *fec_init_tx_dma(
- MCD_bufDescFec *bdRing,
- int bdCount
-)
-{
- int bdIndex;
-
- for (bdIndex = 0; bdIndex < bdCount; ++bdIndex) {
- bool bdIsLast = bdIndex == bdCount - 1;
-
- bdRing[bdIndex].dataPointer = 0;
- bdRing[bdIndex].length = 0;
- bdRing[bdIndex].statCtrl = bdIsLast ? MCF548X_FEC_RBD_WRAP : 0;
- }
-
- return bdRing;
-}
-
-static void mcf548x_fec_txDaemon(void *arg)
-{
- struct mcf548x_enet_struct *sc = arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- int dmaChan = sc->txDmaChan;
- int bdIndex = 0;
- int bdCount = sc->txBdCount;
- struct mbuf **mbufs = &sc->txMbuf[0];
- struct mbuf *m = NULL;
- MCD_bufDescFec *bdRing = fec_init_tx_dma(sc->txBd, bdCount);
- MCD_bufDescFec *first = NULL;
- bool bdShortage = false;
-
- memset(mbufs, 0, bdCount * sizeof(*mbufs));
-
- while (true) {
- if (bdShortage) {
- mcdma_glue_irq_enable(dmaChan);
- }
- fec_wait_for_event();
-
- if (sc->state != FEC_STATE_NORMAL) {
- fec_reset_tx_dma(dmaChan, bdCount, bdRing, mbufs, m);
- mcf548x_fec_restart(sc, sc->rxDaemonTid);
- bdIndex = 0;
- m = NULL;
- first = NULL;
- }
-
- bdShortage = fec_transmit(
- ifp,
- dmaChan,
- bdCount,
- bdRing,
- mbufs,
- &bdIndex,
- &m,
- &first
- );
- }
-}
-
-static struct mbuf *fec_add_mbuf(
- int how,
- struct ifnet *ifp,
- MCD_bufDescFec *bd,
- bool bdIsLast
-)
-{
- struct mbuf *m;
-
- MGETHDR(m, how, MT_DATA);
- if (m != NULL) {
- MCLGET(m, how);
- if ((m->m_flags & M_EXT) != 0) {
- m->m_pkthdr.rcvif = ifp;
-
- rtems_cache_invalidate_multiple_data_lines(mtod(m, void *), ETHER_MAX_LEN);
-
- bd->dataPointer = mtod(m, u32);
- bd->length = ETHER_MAX_LEN;
- bd->statCtrl = MCF548X_FEC_RBD_EMPTY
- | MCF548X_FEC_RBD_INT
- | (bdIsLast ? MCF548X_FEC_RBD_WRAP : 0);
- } else {
- m_free(m);
- }
- }
-
- return m;
-}
-
-static MCD_bufDescFec *fec_init_rx_dma(
- MCD_bufDescFec *bdRing,
- struct ifnet *ifp,
- int bdCount,
- struct mbuf **mbufs
-)
-{
- int bdIndex;
-
- for (bdIndex = 0; bdIndex < bdCount; ++bdIndex) {
- bool bdIsLast = bdIndex == bdCount - 1;
-
- mbufs[bdIndex] = fec_add_mbuf(M_WAIT, ifp, &bdRing[bdIndex], bdIsLast);
- }
-
- return bdRing;
-}
-
-static void fec_reset_rx_dma(
- int dmaChan,
- int bdCount,
- MCD_bufDescFec *bdRing
-)
-{
- int bdIndex;
-
- MCD_killDma(dmaChan);
-
- for (bdIndex = 0; bdIndex < bdCount - 1; ++bdIndex) {
- bdRing[bdIndex].length = ETHER_MAX_LEN;
- bdRing[bdIndex].statCtrl = MCF548X_FEC_RBD_EMPTY | MCF548X_FEC_RBD_INT;
- }
-
- bdRing[bdIndex].length = ETHER_MAX_LEN;
- bdRing[bdIndex].statCtrl = MCF548X_FEC_RBD_EMPTY | MCF548X_FEC_RBD_INT | MCF548X_FEC_RBD_WRAP;
-}
-
-static int fec_ether_input(
- struct ifnet *ifp,
- int dmaChan,
- int bdIndex,
- int bdCount,
- MCD_bufDescFec *bdRing,
- struct mbuf **mbufs
-)
-{
- while (true) {
- bool bdIsLast = bdIndex == bdCount - 1;
- MCD_bufDescFec *bd = &bdRing[bdIndex];
- struct mbuf *m = mbufs[bdIndex];
- struct mbuf *n;
- u16 status;
-
- MCDMA_CLR_PENDING(dmaChan);
- status = bd->statCtrl;
-
- if ((status & MCF548X_FEC_RBD_EMPTY) != 0) {
- break;
- }
-
- n = fec_add_mbuf(0, ifp, bd, bdIsLast);
- if (n != NULL) {
- int len = bd->length - ETHER_HDR_LEN - ETHER_CRC_LEN;
- struct ether_header *eh = mtod(m, struct ether_header *);
-
- m->m_len = len;
- m->m_pkthdr.len = len;
- m->m_data = mtod(m, char *) + ETHER_HDR_LEN;
-
- ether_input(ifp, eh, m);
- } else {
- n = m;
- }
-
- mbufs[bdIndex] = n;
-
- if (bdIndex < bdCount - 1) {
- ++bdIndex;
- } else {
- bdIndex = 0;
- }
- }
-
- return bdIndex;
-}
-
-static void mcf548x_fec_rxDaemon(void *arg)
-{
- struct mcf548x_enet_struct *sc = arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- int dmaChan = sc->rxDmaChan;
- int bdIndex = 0;
- int bdCount = sc->rxBdCount;
- struct mbuf **mbufs = &sc->rxMbuf[0];
- MCD_bufDescFec *bdRing = fec_init_rx_dma(sc->rxBd, ifp, bdCount, mbufs);
-
- while (true) {
- mcdma_glue_irq_enable(dmaChan);
- fec_wait_for_event();
-
- bdIndex = fec_ether_input(ifp, dmaChan, bdIndex, bdCount, bdRing, mbufs);
-
- if (sc->state != FEC_STATE_NORMAL) {
- fec_reset_rx_dma(dmaChan, bdCount, bdRing);
- mcf548x_fec_restart(sc, sc->txDaemonTid);
- bdIndex = 0;
- }
- }
-}
-
-/*
- * Initialize and start the device
- */
-static void mcf548x_fec_init(void *arg)
-{
- struct mcf548x_enet_struct *sc = (struct mcf548x_enet_struct *)arg;
- struct ifnet *ifp = &sc->arpcom.ac_if;
- int chan = sc->chan;
- rtems_isr_entry old_handler;
- char *txTaskName = "FTx0";
- char *rxTaskName = "FRx0";
- if(sc->txDaemonTid == 0)
- {
- /*
- * Allocate a set of BDs
- */
- sc->rxBd = SRAM_RXBD_BASE(_SysSramBase,chan);
- sc->txBd = SRAM_TXBD_BASE(_SysSramBase,chan);
-
- if(!sc->rxBd || !sc->txBd)
- rtems_panic ("No memory for BDs");
- /*
- * clear the BDs
- */
- memset((void *)sc->rxBd,0,sc->rxBdCount * sizeof *(sc->rxBd));
- memset((void *)sc->txBd,0,sc->txBdCount * sizeof *(sc->txBd));
- /*
- * Allocate a set of mbuf pointers
- */
- sc->rxMbuf =
- malloc(sc->rxBdCount * sizeof *sc->rxMbuf, M_MBUF, M_NOWAIT);
- sc->txMbuf =
- malloc(sc->txBdCount * sizeof *sc->txMbuf, M_MBUF, M_NOWAIT);
-
- if(!sc->rxMbuf || !sc->txMbuf)
- rtems_panic ("No memory for mbuf pointers");
-
- sc->txDmaChan = MCDMA_FEC_TX_CHAN(chan);
- sc->rxDmaChan = MCDMA_FEC_RX_CHAN(chan);
-
- mcdma_glue_init(SRAM_DMA_BASE(_SysSramBase));
-
- /*
- * Set up interrupts
- */
- mcdma_glue_irq_install(sc->rxDmaChan,
- mcf548x_mcdma_rx_irq_handler,
- sc);
- mcdma_glue_irq_install(sc->txDmaChan,
- mcf548x_mcdma_tx_irq_handler,
- sc);
- if(rtems_interrupt_catch(mcf548x_fec_irq_handler,
- MCF548X_FEC_IRQ_VECTOR(chan),
- &old_handler)) {
- rtems_panic ("Can't attach MFC54xx FEX interrupt handler\n");
- }
-
- bsp_interrupt_vector_enable(MCF548X_IRQ_FEC(chan));
-
- MCF548X_FEC_EIMR(chan) = FEC_INTR_MASK_USED;
-
- /*
- * Start driver tasks
- */
- txTaskName[3] = '0'+chan;
- rxTaskName[3] = '0'+chan;
- sc->txDaemonTid = rtems_bsdnet_newproc(txTaskName, 4096,
- mcf548x_fec_txDaemon, sc);
- sc->rxDaemonTid = rtems_bsdnet_newproc(rxTaskName, 4096,
- mcf548x_fec_rxDaemon, sc);
- }
-
- mcf548x_fec_request_restart(sc);
-
- /*
- * Set flags appropriately
- */
- if(ifp->if_flags & IFF_PROMISC)
- MCF548X_FEC_RCR(chan) |= MCF548X_FEC_RCR_PROM;
- else
- MCF548X_FEC_RCR(chan) &= ~MCF548X_FEC_RCR_PROM;
-
- /*
- * init timer so the "watchdog function gets called periodically
- */
- ifp->if_timer = 1;
- /*
- * Tell the world that we're running.
- */
- ifp->if_flags |= IFF_RUNNING;
-}
-
-
-static void enet_stats (struct mcf548x_enet_struct *sc)
-{
- printf (" Rx Interrupts:%-8lu", sc->rxInterrupts);
- printf (" Rx Not First:%-8lu", sc->rxNotFirst);
- printf (" Rx Not Last:%-8lu\n", sc->rxNotLast);
- printf (" Rx Giant:%-8lu", sc->rxGiant);
- printf (" Rx Non-octet:%-8lu", sc->rxNonOctet);
- printf (" Rx Bad CRC:%-8lu\n", sc->rxBadCRC);
- printf (" Rx FIFO Error:%-8lu", sc->rxFIFOError);
- printf (" Rx Collision:%-8lu", sc->rxCollision);
-
- printf (" Tx Interrupts:%-8lu\n", sc->txInterrupts);
- printf (" Tx Deferred:%-8lu", sc->txDeferred);
- printf (" Tx Late Collision:%-8lu", sc->txLateCollision);
- printf (" Tx Retransmit Limit:%-8lu\n", sc->txRetryLimit);
- printf (" Tx Underrun:%-8lu", sc->txUnderrun);
- printf (" Tx FIFO Error:%-8lu", sc->txFIFOError);
- printf (" Tx Misaligned:%-8lu\n", sc->txMisaligned);
-
-}
-
-int32_t mcf548x_fec_setMultiFilter(struct ifnet *ifp)
-{
- /*struct mcf548x_enet_struct *sc = ifp->if_softc; */
- /* XXX anything to do? */
- return 0;
-}
-
-
-/*
- * Driver ioctl handler
- */
-static int mcf548x_fec_ioctl (struct ifnet *ifp, ioctl_command_t command, caddr_t data)
- {
- struct mcf548x_enet_struct *sc = ifp->if_softc;
- int error = 0;
-
- switch(command)
- {
-
- case SIOCGIFMEDIA:
- case SIOCSIFMEDIA:
- rtems_mii_ioctl (&(sc->mdio_info),sc,command,(void *)data);
- break;
-
- case SIOCGIFADDR:
- case SIOCSIFADDR:
-
- ether_ioctl(ifp, command, data);
-
- break;
-
- case SIOCADDMULTI:
- case SIOCDELMULTI: {
- struct ifreq* ifr = (struct ifreq*) data;
- error = (command == SIOCADDMULTI)
- ? ether_addmulti(ifr, &sc->arpcom)
- : ether_delmulti(ifr, &sc->arpcom);
-
- if (error == ENETRESET) {
- if (ifp->if_flags & IFF_RUNNING)
- error = mcf548x_fec_setMultiFilter(ifp);
- else
- error = 0;
- }
- break;
- }
-
- case SIOCSIFFLAGS:
-
- switch(ifp->if_flags & (IFF_UP | IFF_RUNNING))
- {
-
- case IFF_RUNNING:
-
- mcf548x_fec_off(sc);
-
- break;
-
- case IFF_UP:
-
- mcf548x_fec_init(sc);
-
- break;
-
- case IFF_UP | IFF_RUNNING:
-
- mcf548x_fec_off(sc);
- mcf548x_fec_init(sc);
-
- break;
-
- default:
- break;
-
- }
-
- break;
-
- case SIO_RTEMS_SHOW_STATS:
-
- enet_stats(sc);
-
- break;
-
- /*
- * FIXME: All sorts of multicast commands need to be added here!
- */
- default:
-
- error = EINVAL;
-
- break;
-
- }
-
- return error;
-
- }
-
-
-/*
- * init the PHY and adapt FEC settings
- */
-int mcf548x_fec_mode_adapt(struct ifnet *ifp)
-{
- int result = 0;
- struct mcf548x_enet_struct *sc = ifp->if_softc;
- int media = IFM_MAKEWORD( 0, 0, 0, sc->phy_default);
- int chan = sc->chan;
-
- /*
- * fetch media status
- */
- result = mcf548x_fec_ioctl(ifp,SIOCGIFMEDIA,(caddr_t)&media);
- if (result != 0) {
- return result;
- }
- /*
- * status is unchanged? then do nothing
- */
- if (media == sc->media_state) {
- return 0;
- }
- /*
- * otherwise: for the first call, try to negotiate mode
- */
- if (sc->media_state == 0) {
- /*
- * set media status: set auto negotiation -> start auto-negotiation
- */
- media = IFM_MAKEWORD(0,IFM_AUTO,0,sc->phy_default);
- result = mcf548x_fec_ioctl(ifp,SIOCSIFMEDIA,(caddr_t)&media);
- if (result != 0) {
- return result;
- }
- /*
- * wait for auto-negotiation to terminate
- */
- do {
- media = IFM_MAKEWORD(0,0,0,sc->phy_default);
- result = mcf548x_fec_ioctl(ifp,SIOCGIFMEDIA,(caddr_t)&media);
- if (result != 0) {
- return result;
- }
- } while (IFM_NONE == IFM_SUBTYPE(media));
- }
-
- /*
- * now set HW according to media results:
- */
-
- /*
- * if we are half duplex then switch to half duplex
- */
- if (0 == (IFM_FDX & IFM_OPTIONS(media))) {
- MCF548X_FEC_TCR(chan) &= ~MCF548X_FEC_TCR_FDEN;
- }
- else {
- MCF548X_FEC_TCR(chan) |= MCF548X_FEC_TCR_FDEN;
- }
- /*
- * store current media state for future compares
- */
- sc->media_state = media;
-
- return 0;
-}
-
-/*
- * periodically poll the PHY. if mode has changed,
- * then adjust the FEC settings
- */
-static void mcf548x_fec_watchdog( struct ifnet *ifp)
-{
- mcf548x_fec_mode_adapt(ifp);
- ifp->if_timer = FEC_WATCHDOG_TIMEOUT;
-}
-
-/*
- * Attach the MCF548X fec driver to the system
- */
-int rtems_mcf548x_fec_driver_attach(struct rtems_bsdnet_ifconfig *config)
- {
- struct mcf548x_enet_struct *sc;
- struct ifnet *ifp;
- int mtu;
- int unitNumber;
- char *unitName;
-
- /*
- * Parse driver name
- */
- if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0)
- return 0;
-
- /*
- * Is driver free?
- */
- if ((unitNumber <= 0) || (unitNumber > NIFACES))
- {
-
- printf ("Bad FEC unit number.\n");
- return 0;
-
- }
-
- sc = &enet_driver[unitNumber - 1];
- sc->chan = unitNumber-1;
- ifp = &sc->arpcom.ac_if;
-
- if(ifp->if_softc != NULL)
- {
-
- printf ("Driver already in use.\n");
- return 0;
-
- }
-
- /*
- * Process options
- */
-#if NVRAM_CONFIGURE == 1
-
- /* Configure from NVRAM */
- if(addr = nvram->ipaddr)
- {
-
- /* We have a non-zero entry, copy the value */
- if(pAddr = malloc(INET_ADDR_MAX_BUF_SIZE, 0, M_NOWAIT))
- config->ip_address = (char *)inet_ntop(AF_INET, &addr, pAddr, INET_ADDR_MAX_BUF_SIZE -1);
- else
- rtems_panic("Can't allocate ip_address buffer!\n");
-
- }
-
- if(addr = nvram->netmask)
- {
-
- /* We have a non-zero entry, copy the value */
- if (pAddr = malloc (INET_ADDR_MAX_BUF_SIZE, 0, M_NOWAIT))
- config->ip_netmask = (char *)inet_ntop(AF_INET, &addr, pAddr, INET_ADDR_MAX_BUF_SIZE -1);
- else
- rtems_panic("Can't allocate ip_netmask buffer!\n");
-
- }
-
- /* Ethernet address requires special handling -- it must be copied into
- * the arpcom struct. The following if construct serves only to give the
- * User Area NVRAM parameter the highest priority.
- *
- * If the ethernet address is specified in NVRAM, go ahead and copy it.
- * (ETHER_ADDR_LEN = 6 bytes).
- */
- if(nvram->enaddr[0] || nvram->enaddr[1] || nvram->enaddr[2])
- {
-
- /* Anything in the first three bytes indicates a non-zero entry, copy value */
- memcpy((void *)sc->arpcom.ac_enaddr, &nvram->enaddr, ETHER_ADDR_LEN);
-
- }
- else
- if(config->hardware_address)
- {
-
- /* There is no entry in NVRAM, but there is in the ifconfig struct, so use it. */
- memcpy((void *)sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN);
- }
-
-#else /* NVRAM_CONFIGURE != 1 */
-
- if(config->hardware_address)
- {
-
- memcpy(sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN);
-
- }
-
-#endif /* NVRAM_CONFIGURE != 1 */
-#ifdef HAS_UBOOT
- if ((sc->arpcom.ac_enaddr[0] == 0) &&
- (sc->arpcom.ac_enaddr[1] == 0) &&
- (sc->arpcom.ac_enaddr[2] == 0)) {
- memcpy(
- (void *)sc->arpcom.ac_enaddr,
- bsp_uboot_board_info.bi_enetaddr,
- ETHER_ADDR_LEN
- );
- }
-#endif
-#ifdef HAS_DBUG
- if ((sc->arpcom.ac_enaddr[0] == 0) &&
- (sc->arpcom.ac_enaddr[1] == 0) &&
- (sc->arpcom.ac_enaddr[2] == 0)) {
- memcpy(
- (void *)sc->arpcom.ac_enaddr,
- DBUG_SETTINGS.macaddr,
- ETHER_ADDR_LEN
- );
- }
-#endif
- if ((sc->arpcom.ac_enaddr[0] == 0) &&
- (sc->arpcom.ac_enaddr[1] == 0) &&
- (sc->arpcom.ac_enaddr[2] == 0)) {
- /* There is no ethernet address provided, so it could be read
- * from the Ethernet protocol block of SCC1 in DPRAM.
- */
- rtems_panic("No Ethernet address specified!\n");
- }
- if(config->mtu)
- mtu = config->mtu;
- else
- mtu = ETHERMTU;
-
- if(config->rbuf_count)
- sc->rxBdCount = config->rbuf_count;
- else
- sc->rxBdCount = RX_BUF_COUNT;
-
- if(config->xbuf_count)
- sc->txBdCount = config->xbuf_count;
- else
- sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;
-
- sc->acceptBroadcast = !config->ignore_broadcast;
-
- /*
- * setup info about mdio interface
- */
- sc->mdio_info.mdio_r = mcf548x_eth_mii_read;
- sc->mdio_info.mdio_w = mcf548x_eth_mii_write;
- sc->mdio_info.has_gmii = 0; /* we do not support gigabit IF */
-
- /*
- * XXX: Although most hardware builders will assign the PHY addresses
- * like this, this should be more configurable
- */
- sc->phy_default = unitNumber-1;
- sc->phy_chan = 0; /* assume all MII accesses are via FEC0 */
-
- /*
- * Set up network interface values
- */
- ifp->if_softc = sc;
- ifp->if_unit = unitNumber;
- ifp->if_name = unitName;
- ifp->if_mtu = mtu;
- ifp->if_init = mcf548x_fec_init;
- ifp->if_ioctl = mcf548x_fec_ioctl;
- ifp->if_start = mcf548x_fec_tx_start;
- ifp->if_output = ether_output;
- ifp->if_watchdog = mcf548x_fec_watchdog; /* XXX: timer is set in "init" */
- ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST;
- /*ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;*/
-
- if(ifp->if_snd.ifq_maxlen == 0)
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
-
- /*
- * Attach the interface
- */
- if_attach(ifp);
-
- ether_ifattach(ifp);
-
- return 1;
- }
-
-
-int rtems_mcf548x_fec_driver_attach_detach(struct rtems_bsdnet_ifconfig *config, int attaching)
-{
- if (attaching) {
- return rtems_mcf548x_fec_driver_attach(config);
- }
- else {
- return 0;
- }
-}
-
-
diff --git a/bsps/m68k/mcf5235/net/network.c b/bsps/m68k/mcf5235/net/network.c
deleted file mode 100644
index f352b664db..0000000000
--- a/bsps/m68k/mcf5235/net/network.c
+++ /dev/null
@@ -1,879 +0,0 @@
-/*
- * RTEMS/TCPIP driver for MCF5235 Fast Ethernet Controller
- *
- * TO DO: Check network stack code -- force longword alignment of all tx mbufs?
- */
-
-#include <machine/rtems-bsd-kernel-space.h>
-
-#include <bsp.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <string.h>
-#include <rtems.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-
-#include <net/ethernet.h>
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-
-
-/*
- * Number of interfaces supported by this driver
- */
-#define NIFACES 1
-
-#define FEC_INTC0_TX_VECTOR (64+23)
-#define FEC_INTC0_RX_VECTOR (64+27)
-
-/*
- * Default number of buffer descriptors set aside for this driver.
- * The number of transmit buffer descriptors has to be quite large
- * since a single frame often uses three or more buffer descriptors.
- */
-#define RX_BUF_COUNT 32
-#define TX_BUF_COUNT 20
-#define TX_BD_PER_BUF 3
-
-#define INET_ADDR_MAX_BUF_SIZE (sizeof "255.255.255.255")
-
-/*
- * RTEMS event used by interrupt handler to signal daemons.
- * This must *not* be the same event used by the TCP/IP task synchronization.
- */
-#define TX_INTERRUPT_EVENT RTEMS_EVENT_1
-#define RX_INTERRUPT_EVENT RTEMS_EVENT_1
-
-/*
- * RTEMS event used to start transmit daemon.
- * This must not be the same as INTERRUPT_EVENT.
- */
-#define START_TRANSMIT_EVENT RTEMS_EVENT_2
-
-/*
- * Receive buffer size -- Allow for a full ethernet packet plus CRC (1518).
- * Round off to nearest multiple of RBUF_ALIGN.
- */
-#define MAX_MTU_SIZE 1518
-#define RBUF_ALIGN 4
-#define RBUF_SIZE ((MAX_MTU_SIZE + RBUF_ALIGN) & ~RBUF_ALIGN)
-
-#if (MCLBYTES < RBUF_SIZE)
- #error "Driver must have MCLBYTES > RBUF_SIZE"
-#endif
-
-typedef struct mcf5235BufferDescriptor_ {
- volatile uint16_t status;