source: rtems/c/src/lib/libbsp/m68k/uC5282/network/network.c @ 572484f

4.104.114.84.95
Last change on this file since 572484f was 572484f, checked in by Eric Norum <WENorum@…>, on 01/28/05 at 19:35:23

New BSP for Arcturus uCDIMM ColdFire? 5282.

  • Property mode set to 100644
File size: 25.1 KB
Line 
1/*
2 * RTEMS/TCPIP driver for MCF5282 Fast Ethernet Controller
3 *
4 * TO DO: MII communications to set speed, full/half duplex, etc.
5 * TO DO: Check network stack code -- force longword alignment of all tx mbufs?
6 */
7
8#include <bsp.h>
9#include <stdio.h>
10#include <errno.h>
11#include <stdarg.h>
12#include <string.h>
13#include <rtems/error.h>
14#include <rtems/rtems_bsdnet.h>
15
16#include <sys/param.h>
17#include <sys/mbuf.h>
18#include <sys/socket.h>
19#include <sys/sockio.h>
20
21#include <net/ethernet.h>
22#include <net/if.h>
23
24#include <netinet/in.h>
25#include <netinet/if_ether.h>
26
27
28/*
29 * Number of interfaces supported by this driver
30 */
31#define NIFACES 1
32
33#define FEC_INTC0_TX_VECTOR (64+23)
34#define FEC_INTC0_RX_VECTOR (64+27)
35
36/*
37 * Default number of buffer descriptors set aside for this driver.
38 * The number of transmit buffer descriptors has to be quite large
39 * since a single frame often uses three or more buffer descriptors.
40 */
41#define RX_BUF_COUNT     32
42#define TX_BUF_COUNT     20
43#define TX_BD_PER_BUF    3
44
45#define INET_ADDR_MAX_BUF_SIZE (sizeof "255.255.255.255")
46
47/*
48 * RTEMS event used by interrupt handler to signal daemons.
49 * This must *not* be the same event used by the TCP/IP task synchronization.
50 */
51#define TX_INTERRUPT_EVENT RTEMS_EVENT_1
52#define RX_INTERRUPT_EVENT RTEMS_EVENT_1
53
54/*
55 * RTEMS event used to start transmit daemon.
56 * This must not be the same as INTERRUPT_EVENT.
57 */
58#define START_TRANSMIT_EVENT RTEMS_EVENT_2
59
60/*
61 * Receive buffer size -- Allow for a full ethernet packet plus CRC (1518).
62 * Round off to nearest multiple of RBUF_ALIGN.
63 */
64#define MAX_MTU_SIZE    1518
65#define RBUF_ALIGN      4
66#define RBUF_SIZE       ((MAX_MTU_SIZE + RBUF_ALIGN) & ~RBUF_ALIGN)
67
68#if (MCLBYTES < RBUF_SIZE)
69    #error "Driver must have MCLBYTES > RBUF_SIZE"
70#endif
71
72typedef struct mcf5282BufferDescriptor_ {
73    volatile rtems_unsigned16   status;
74    rtems_unsigned16            length;
75    volatile void               *buffer;
76} mcf5282BufferDescriptor_t;
77
78/*
79 * Per-device data
80 */
81struct mcf5282_enet_struct {
82    struct arpcom               arpcom;
83    struct mbuf                 **rxMbuf;
84    struct mbuf                 **txMbuf;
85    int                         acceptBroadcast;
86    int                         rxBdCount;
87    int                         txBdCount;
88    int                         txBdHead;
89    int                         txBdTail;
90    int                         txBdActiveCount;
91    mcf5282BufferDescriptor_t  *rxBdBase;
92    mcf5282BufferDescriptor_t  *txBdBase;
93    rtems_id                    rxDaemonTid;
94    rtems_id                    txDaemonTid;
95
96    /*
97     * Statistics
98     */
99    unsigned long   rxInterrupts;
100    unsigned long   txInterrupts;
101    unsigned long   txRawWait;
102    unsigned long   txRealign;
103};
104static struct mcf5282_enet_struct enet_driver[NIFACES];
105
106static rtems_isr
107mcf5282_fec_rx_interrupt_handler( rtems_vector_number v )
108{
109    MCF5282_FEC_EIR = MCF5282_FEC_EIR_RXF;
110    MCF5282_FEC_EIMR &= ~MCF5282_FEC_EIMR_RXF;   
111    enet_driver[0].rxInterrupts++;
112    rtems_event_send(enet_driver[0].rxDaemonTid, RX_INTERRUPT_EVENT);
113}
114
115static rtems_isr
116mcf5282_fec_tx_interrupt_handler( rtems_vector_number v )
117{
118    MCF5282_FEC_EIR = MCF5282_FEC_EIR_TXF;
119    MCF5282_FEC_EIMR &= ~MCF5282_FEC_EIMR_TXF;   
120    enet_driver[0].txInterrupts++;
121    rtems_event_send(enet_driver[0].txDaemonTid, TX_INTERRUPT_EVENT);
122}
123
124/*
125 * Allocate buffer descriptors from SRAM
126 * Ensure 128-bit (16-byte)alignment
127 */
128static void *
129mcf5282_bd_allocate(unsigned int count)
130{
131    char *p;
132   
133    p = malloc((count * sizeof(mcf5282BufferDescriptor_t)) + 15, 0, M_NOWAIT);
134    if (!p)
135        rtems_panic("FEC BD");
136    if ((int)p & 0xF)
137        p += 16 - ((int)p & 0xF);
138printf("Allocate %d at %p\n", count, p);
139    return p;
140}
141
142/*
143 * Retrieve MAC address from bootloader environment variable area.
144 * Parameter is interface number (0 or 1).
145 */
146static unsigned char *
147gethwaddr(int a)
148{
149   register long __res __asm__ ("%d2") = 12;
150   register long __a __asm__ ("%d1") = (long)a;
151   __asm__ __volatile__ ("trap #2" \
152                         : "=g" (__res) \
153                         : "0" (__res), "d" (__a) \
154                         : "%d0");
155   return (unsigned char *)(__res);
156}
157
158static void
159mcf5282_fec_initialize_hardware(struct mcf5282_enet_struct *sc)
160{
161    int i;
162    unsigned char *hwaddr;
163    rtems_status_code status;
164    rtems_isr_entry old_handler;
165        unsigned32 clock_speed = get_CPU_clock_speed();
166
167/*  extern struct rtems_bsdnet_ifconfig netdriver_config; */
168
169
170    /*
171     * Issue reset to FEC
172     */
173    MCF5282_FEC_ECR = MCF5282_FEC_ECR_RESET;
174    rtems_task_wake_after( 1 );
175    /*
176     * Configuration of I/O ports is done outside of this function
177     */
178#if 0
179    imm->gpio.pbcnt |= MCF5282_GPIO_PBCNT_SET_FEC;        /* Set up port b FEC pins */
180#endif
181
182    /*
183     * Set our physical address
184     */
185    hwaddr = sc->arpcom.ac_enaddr;
186    MCF5282_FEC_PALR = (hwaddr[0] << 24) | (hwaddr[1] << 16) |
187                       (hwaddr[2] << 8)  | (hwaddr[3] << 0);
188    MCF5282_FEC_PAUR = (hwaddr[4] << 24) | (hwaddr[5] << 16);
189
190
191    /*
192     * Clear the hash table
193     */
194    MCF5282_FEC_GAUR = 0;
195    MCF5282_FEC_GALR = 0;
196
197    /*
198     * Set up receive buffer size
199     */
200    MCF5282_FEC_EMRBR = 1520; /* Standard Ethernet */
201
202    /*
203     * Allocate mbuf pointers
204     */
205    sc->rxMbuf = malloc(sc->rxBdCount * sizeof *sc->rxMbuf, M_MBUF, M_NOWAIT);
206    sc->txMbuf = malloc(sc->txBdCount * sizeof *sc->txMbuf, M_MBUF, M_NOWAIT);
207    if (!sc->rxMbuf || !sc->txMbuf)
208        rtems_panic("No memory for mbuf pointers");
209
210    /*
211     * Set receiver and transmitter buffer descriptor bases
212     */
213    sc->rxBdBase = mcf5282_bd_allocate(sc->rxBdCount);
214    sc->txBdBase = mcf5282_bd_allocate(sc->txBdCount);
215    MCF5282_FEC_ERDSR = (int)sc->rxBdBase;
216    MCF5282_FEC_ETDSR = (int)sc->txBdBase;
217
218    /*
219     * Set up Receive Control Register:
220     *   Not promiscuous
221     *   MII mode
222     *   Half duplex
223     *   No loopback
224     */
225    MCF5282_FEC_RCR = MCF5282_FEC_RCR_MAX_FL(MAX_MTU_SIZE) |
226                      MCF5282_FEC_RCR_MII_MODE             |
227                      MCF5282_FEC_RCR_DRT;
228
229    /*
230     * Set up Transmit Control Register:
231     *   Half duplex
232     *   No heartbeat
233     */
234    MCF5282_FEC_TCR = 0;
235
236    /*
237     * Initialize statistic counters
238     */
239    MCF5282_FEC_MIBC = MCF5282_FEC_MIBC_MIB_DISABLE;
240    {
241    vuint32 *vuip = &MCF5282_FEC_RMON_T_DROP;
242    while (vuip <= &MCF5282_FEC_IEEE_R_OCTETS_OK)
243        *vuip++ = 0;
244    }
245    MCF5282_FEC_MIBC = 0;
246
247    /*
248     * Set MII speed to <2.5 MHz
249     */
250    if (clock_speed <= 25000000)
251        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0x5);
252    else if (clock_speed <= 33000000)
253        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0x7);
254    else if (clock_speed <= 40000000)
255        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0x8);
256    else if (clock_speed <= 50000000)
257        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0xA);
258    else if (clock_speed <= 66000000)
259        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0xD);
260    else
261        MCF5282_FEC_MSCR = MCF5282_FEC_MSCR_MII_SPEED(0xF);
262
263    /*
264     * Set up receive buffer descriptors
265     */
266    for (i = 0 ; i < sc->rxBdCount ; i++)
267        (sc->rxBdBase + i)->status = 0;
268
269    /*
270     * Set up transmit buffer descriptors
271     */
272    for (i = 0 ; i < sc->txBdCount ; i++) {
273        sc->txBdBase[i].status = 0;
274        sc->txMbuf[i] = NULL;
275    }
276    sc->txBdHead = sc->txBdTail = 0;
277    sc->txBdActiveCount = 0;
278
279    /*
280     * Set up interrupts
281     */
282    status = rtems_interrupt_catch( mcf5282_fec_tx_interrupt_handler, FEC_INTC0_TX_VECTOR, &old_handler );
283    if (status != RTEMS_SUCCESSFUL)
284        rtems_panic ("Can't attach MCF5282 FEC TX interrupt handler: %s\n",
285                     rtems_status_text(status));
286    status = rtems_interrupt_catch(mcf5282_fec_rx_interrupt_handler, FEC_INTC0_RX_VECTOR, &old_handler);
287    if (status != RTEMS_SUCCESSFUL)
288        rtems_panic ("Can't attach MCF5282 FEC RX interrupt handler: %s\n",
289                     rtems_status_text(status));
290    MCF5282_INTC0_ICR23 = MCF5282_INTC_ICR_IL(FEC_IRQ_LEVEL) |
291                          MCF5282_INTC_ICR_IP(FEC_IRQ_TX_PRIORITY);
292    MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT23 | MCF5282_INTC_IMRL_MASKALL);
293    MCF5282_INTC0_ICR27 = MCF5282_INTC_ICR_IL(FEC_IRQ_LEVEL) |
294                          MCF5282_INTC_ICR_IP(FEC_IRQ_RX_PRIORITY);
295    MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT27 | MCF5282_INTC_IMRL_MASKALL);
296}
297
298/*
299 * Soak up buffer descriptors that have been sent.
300 */
301static void
302fec_retire_tx_bd(volatile struct mcf5282_enet_struct *sc )
303{
304    struct mbuf *m, *n;
305
306    while ((sc->txBdActiveCount != 0)
307        && ((sc->txBdBase[sc->txBdTail].status & MCF5282_FEC_TxBD_R) == 0)) {
308        m = sc->txMbuf[sc->txBdTail];
309        MFREE(m, n);
310        if (++sc->txBdTail == sc->txBdCount)
311            sc->txBdTail = 0;
312        sc->txBdActiveCount--;
313    }
314}
315
316static void
317fec_rxDaemon (void *arg)
318{
319    volatile struct mcf5282_enet_struct *sc = (volatile struct mcf5282_enet_struct *)arg;
320    struct ifnet *ifp = (struct ifnet* )&sc->arpcom.ac_if;
321    struct mbuf *m;
322    volatile rtems_unsigned16 status;
323    volatile mcf5282BufferDescriptor_t *rxBd;
324    int rxBdIndex;
325
326    /*
327     * Allocate space for incoming packets and start reception
328     */
329    for (rxBdIndex = 0 ; ;) {
330        rxBd = sc->rxBdBase + rxBdIndex;
331        MGETHDR(m, M_WAIT, MT_DATA);
332        MCLGET(m, M_WAIT);
333        m->m_pkthdr.rcvif = ifp;
334        sc->rxMbuf[rxBdIndex] = m;
335        rxBd->buffer = mtod(m, void *);
336        rxBd->status = MCF5282_FEC_RxBD_E;
337        if (++rxBdIndex == sc->rxBdCount) {
338            rxBd->status |= MCF5282_FEC_RxBD_W;
339            break;
340        }
341    }
342
343    /*
344     * Input packet handling loop
345     */
346    /* Indicate we have some ready buffers available */
347    MCF5282_FEC_RDAR = MCF5282_FEC_RDAR_R_DES_ACTIVE;
348
349    rxBdIndex = 0;
350    for (;;) {
351        rxBd = sc->rxBdBase + rxBdIndex;
352
353        /*
354         * Wait for packet if there's not one ready
355         */
356        if ((status = rxBd->status) & MCF5282_FEC_RxBD_E) {
357            /*
358             * Clear old events.
359             */
360            MCF5282_FEC_EIR = MCF5282_FEC_EIR_RXF;
361
362            /*
363             * Wait for packet to arrive.
364             * Check the buffer descriptor before waiting for the event.
365             * This catches the case when a packet arrives between the
366             * `if' above, and the clearing of the RXF bit in the EIR.
367             */
368            while ((status = rxBd->status) & MCF5282_FEC_RxBD_E) {
369                rtems_event_set events;
370                int level;
371
372                rtems_interrupt_disable(level);
373                MCF5282_FEC_EIMR |= MCF5282_FEC_EIMR_RXF;
374                rtems_interrupt_enable(level);
375                rtems_bsdnet_event_receive (RX_INTERRUPT_EVENT,
376                                            RTEMS_WAIT|RTEMS_EVENT_ANY,
377                                            RTEMS_NO_TIMEOUT,
378                                            &events);
379            }
380        }
381
382        /*
383         * Check that packet is valid
384         */
385        if (status & MCF5282_FEC_RxBD_L) {
386            /*
387             * Pass the packet up the chain.
388             * FIXME: Packet filtering hook could be done here.
389             */
390            struct ether_header *eh;
391
392            /*
393             * Invalidate the buffer for this descriptor
394             */
395            m = sc->rxMbuf[rxBdIndex];
396            m->m_len = m->m_pkthdr.len = rxBd->length -
397                       sizeof(rtems_unsigned32) -
398                       sizeof(struct ether_header);
399            eh = mtod(m, struct ether_header *);
400            m->m_data += sizeof(struct ether_header);
401            ether_input(ifp, eh, m);
402
403            /*
404             * Allocate a new mbuf
405             */
406            MGETHDR(m, M_WAIT, MT_DATA);
407            MCLGET(m, M_WAIT);
408            m->m_pkthdr.rcvif = ifp;
409            sc->rxMbuf[rxBdIndex] = m;
410            rxBd->buffer = mtod(m, void *);
411        }
412
413        /*
414         * Reenable the buffer descriptor
415         */
416        rxBd->status = (status & MCF5282_FEC_RxBD_W) | MCF5282_FEC_RxBD_E;
417        MCF5282_FEC_RDAR = MCF5282_FEC_RDAR_R_DES_ACTIVE;
418
419        /*
420         * Move to next buffer descriptor
421         */
422        if (++rxBdIndex == sc->rxBdCount)
423            rxBdIndex = 0;
424    }
425}
426
427static void
428fec_sendpacket(struct ifnet *ifp, struct mbuf *m)
429{
430    struct mcf5282_enet_struct *sc = ifp->if_softc;
431    volatile mcf5282BufferDescriptor_t *firstTxBd, *txBd;
432    rtems_unsigned16 status;
433    int nAdded;
434
435   /*
436     * Free up buffer descriptors
437     */
438    fec_retire_tx_bd(sc);
439
440    /*
441     * Set up the transmit buffer descriptors.
442     * No need to pad out short packets since the
443     * hardware takes care of that automatically.
444     * No need to copy the packet to a contiguous buffer
445     * since the hardware is capable of scatter/gather DMA.
446     */
447    nAdded = 0;
448    firstTxBd = sc->txBdBase + sc->txBdHead;
449   
450    for (;;) {
451        /*
452         * Wait for buffer descriptor to become available
453         */
454        if ((sc->txBdActiveCount + nAdded)  == sc->txBdCount) {
455            /*
456             * Clear old events.
457             */
458            MCF5282_FEC_EIR = MCF5282_FEC_EIR_TXF;
459
460            /*
461             * Wait for buffer descriptor to become available.
462             * Check for buffer descriptors before waiting for the event.
463             * This catches the case when a buffer became available between
464             * the `if' above, and the clearing of the TXF bit in the EIR.
465             */
466            fec_retire_tx_bd(sc);
467            while ((sc->txBdActiveCount + nAdded) == sc->txBdCount) {
468                rtems_event_set events;
469                int level;
470
471                rtems_interrupt_disable(level);
472                MCF5282_FEC_EIMR |= MCF5282_FEC_EIMR_TXF;   
473                rtems_interrupt_enable(level);
474                sc->txRawWait++;
475                rtems_bsdnet_event_receive(TX_INTERRUPT_EVENT,
476                                           RTEMS_WAIT|RTEMS_EVENT_ANY,
477                                           RTEMS_NO_TIMEOUT,
478                                           &events);
479                fec_retire_tx_bd(sc);
480            }
481        }
482   
483        /*
484         * Don't set the READY flag on the first fragment
485         * until the whole packet has been readied.
486         */
487        status = nAdded ? MCF5282_FEC_TxBD_R : 0;
488   
489        /*
490         * The IP fragmentation routine in ip_output
491         * can produce fragments with zero length.
492         */
493        txBd = sc->txBdBase + sc->txBdHead;
494        if (m->m_len) {
495            char *p = mtod(m, char *);
496            /*
497             * Stupid FEC can't handle misaligned data!
498             * Given the way that mbuf's are layed out it should be
499             * safe to shuffle the data down like this.....
500             * Perhaps this code could be improved with a "Duff's Device".
501             */
502            if ((int)p & 0x3) {
503                int l = m->m_len;
504                char *dest = p - ((int)p & 0x3);
505                unsigned16 *o = (unsigned16 *)dest, *i = (unsigned16 *)p;
506                while (l > 0) {
507                    *o++ = *i++;
508                    l -= sizeof(unsigned16);
509                }
510                p = dest;
511                sc->txRealign++;
512            }
513            txBd->buffer = p;
514            txBd->length = m->m_len;
515            sc->txMbuf[sc->txBdHead] = m;
516            nAdded++;
517            if (++sc->txBdHead == sc->txBdCount) {
518                status |= MCF5282_FEC_TxBD_W;
519                sc->txBdHead = 0;
520            }
521            m = m->m_next;
522        }
523        else {
524            /*
525             * Just toss empty mbufs
526             */
527            struct mbuf *n;
528            MFREE(m, n);
529            m = n;
530        }
531        if (m == NULL) {
532          if (nAdded) {
533            txBd->status = status | MCF5282_FEC_TxBD_R
534                                  | MCF5282_FEC_TxBD_L
535                                  | MCF5282_FEC_TxBD_TC;
536            if (nAdded > 1)
537                firstTxBd->status |= MCF5282_FEC_TxBD_R;
538            MCF5282_FEC_TDAR = MCF5282_FEC_TDAR_X_DES_ACTIVE;
539            sc->txBdActiveCount += nAdded;
540          }
541          break;
542        }
543        txBd->status = status;
544    }
545}
546
547void
548fec_txDaemon(void *arg)
549{
550    struct mcf5282_enet_struct *sc = (struct mcf5282_enet_struct *)arg;
551    struct ifnet *ifp = &sc->arpcom.ac_if;
552    struct mbuf *m;
553    rtems_event_set events;
554
555    for (;;) {
556        /*
557         * Wait for packet
558         */
559        rtems_bsdnet_event_receive(START_TRANSMIT_EVENT,
560                                    RTEMS_EVENT_ANY | RTEMS_WAIT,
561                                    RTEMS_NO_TIMEOUT,
562                                    &events);
563
564        /*
565         * Send packets till queue is empty
566         */
567        for (;;) {
568            /*
569             * Get the next mbuf chain to transmit.
570             */
571            IF_DEQUEUE(&ifp->if_snd, m);
572            if (!m)
573                break;
574            fec_sendpacket(ifp, m);
575        }
576        ifp->if_flags &= ~IFF_OACTIVE;
577    }
578}
579
580
581/*
582 * Send packet (caller provides header).
583 */
584static void
585mcf5282_enet_start(struct ifnet *ifp)
586{
587    struct mcf5282_enet_struct *sc = ifp->if_softc;
588
589    rtems_event_send(sc->txDaemonTid, START_TRANSMIT_EVENT);
590    ifp->if_flags |= IFF_OACTIVE;
591}
592
593static void
594fec_init(void *arg)
595{
596    struct mcf5282_enet_struct *sc = arg;
597    struct ifnet *ifp = &sc->arpcom.ac_if;
598
599    if (sc->txDaemonTid == 0) {
600        /*
601         * Set up hardware
602         */
603        mcf5282_fec_initialize_hardware(sc);
604
605        /*
606         * Start driver tasks
607         */
608        sc->txDaemonTid = rtems_bsdnet_newproc("FECtx", 4096, fec_txDaemon, sc);
609        sc->rxDaemonTid = rtems_bsdnet_newproc("FECrx", 4096, fec_rxDaemon, sc);
610    }
611
612    /*
613     * Set flags appropriately
614     */
615    if (ifp->if_flags & IFF_PROMISC)
616        MCF5282_FEC_RCR |= MCF5282_FEC_RCR_PROM;
617    else
618        MCF5282_FEC_RCR &= ~MCF5282_FEC_RCR_PROM;
619
620    /*
621     * Tell the world that we're running.
622     */
623    ifp->if_flags |= IFF_RUNNING;
624
625    /*
626     * Enable receiver and transmitter
627     */
628    MCF5282_FEC_ECR = MCF5282_FEC_ECR_ETHER_EN;
629}
630
631
632static void
633fec_stop(struct mcf5282_enet_struct *sc)
634{
635    struct ifnet *ifp = &sc->arpcom.ac_if;
636
637    ifp->if_flags &= ~IFF_RUNNING;
638
639    /*
640     * Shut down receiver and transmitter
641     */
642    MCF5282_FEC_ECR = 0x0;
643}
644
645/*
646 * Show interface statistics
647 */
648static void
649enet_stats(struct mcf5282_enet_struct *sc)
650{
651    printf("  Rx Interrupts:%-10lu",   sc->rxInterrupts);
652    printf("Rx Packet Count:%-10lu",   MCF5282_FEC_RMON_R_PACKETS);
653    printf("   Rx Broadcast:%-10lu\n", MCF5282_FEC_RMON_R_BC_PKT);
654    printf("   Rx Multicast:%-10lu",   MCF5282_FEC_RMON_R_MC_PKT);
655    printf("CRC/Align error:%-10lu",   MCF5282_FEC_RMON_R_CRC_ALIGN);
656    printf("   Rx Undersize:%-10lu\n", MCF5282_FEC_RMON_R_UNDERSIZE);
657    printf("    Rx Oversize:%-10lu",   MCF5282_FEC_RMON_R_OVERSIZE);
658    printf("    Rx Fragment:%-10lu",   MCF5282_FEC_RMON_R_FRAG);
659    printf("      Rx Jabber:%-10lu\n", MCF5282_FEC_RMON_R_JAB);
660    printf("          Rx 64:%-10lu",   MCF5282_FEC_RMON_R_P64);
661    printf("      Rx 65-127:%-10lu",   MCF5282_FEC_RMON_R_P65T0127);
662    printf("     Rx 128-255:%-10lu\n", MCF5282_FEC_RMON_R_P128TO255);
663    printf("     Rx 256-511:%-10lu",   MCF5282_FEC_RMON_R_P256TO511);
664    printf("    Rx 511-1023:%-10lu",   MCF5282_FEC_RMON_R_P512TO1023);
665    printf("   Rx 1024-2047:%-10lu\n", MCF5282_FEC_RMON_R_P1024TO2047);
666    printf("      Rx >=2048:%-10lu",   MCF5282_FEC_RMON_R_GTE2048);
667    printf("      Rx Octets:%-10lu",   MCF5282_FEC_RMON_R_OCTETS);
668    printf("     Rx Dropped:%-10lu\n", MCF5282_FEC_IEEE_R_DROP);
669    printf("    Rx frame OK:%-10lu",   MCF5282_FEC_IEEE_R_FRAME_OK);
670    printf("   Rx CRC error:%-10lu",   MCF5282_FEC_IEEE_R_CRC);
671    printf(" Rx Align error:%-10lu\n", MCF5282_FEC_IEEE_R_ALIGN);
672    printf("  FIFO Overflow:%-10lu",   MCF5282_FEC_IEEE_R_MACERR);
673    printf("Rx Pause Frames:%-10lu",   MCF5282_FEC_IEEE_R_FDXFC);
674    printf("   Rx Octets OK:%-10lu\n", MCF5282_FEC_IEEE_R_OCTETS_OK);
675    printf("  Tx Interrupts:%-10lu",   sc->txInterrupts);
676    printf("Tx Output Waits:%-10lu",   sc->txRawWait);
677    printf("Tx Realignments:%-10lu\n",   sc->txRealign);
678    printf(" Tx Unaccounted:%-10lu", MCF5282_FEC_RMON_T_DROP);
679    printf("Tx Packet Count:%-10lu",   MCF5282_FEC_RMON_T_PACKETS);
680    printf("   Tx Broadcast:%-10lu\n",   MCF5282_FEC_RMON_T_BC_PKT);
681    printf("   Tx Multicast:%-10lu", MCF5282_FEC_RMON_T_MC_PKT);
682    printf("CRC/Align error:%-10lu",   MCF5282_FEC_RMON_T_CRC_ALIGN);
683    printf("   Tx Undersize:%-10lu\n",   MCF5282_FEC_RMON_T_UNDERSIZE);
684    printf("    Tx Oversize:%-10lu", MCF5282_FEC_RMON_T_OVERSIZE);
685    printf("    Tx Fragment:%-10lu",   MCF5282_FEC_RMON_T_FRAG);
686    printf("      Tx Jabber:%-10lu\n",   MCF5282_FEC_RMON_T_JAB);
687    printf("  Tx Collisions:%-10lu", MCF5282_FEC_RMON_T_COL);
688    printf("          Tx 64:%-10lu",   MCF5282_FEC_RMON_T_P64);
689    printf("      Tx 65-127:%-10lu\n",   MCF5282_FEC_RMON_T_P65TO127);
690    printf("     Tx 128-255:%-10lu", MCF5282_FEC_RMON_T_P128TO255);
691    printf("     Tx 256-511:%-10lu",   MCF5282_FEC_RMON_T_P256TO511);
692    printf("    Tx 511-1023:%-10lu\n",   MCF5282_FEC_RMON_T_P512TO1023);
693    printf("   Tx 1024-2047:%-10lu", MCF5282_FEC_RMON_T_P1024TO2047);
694    printf("      Tx >=2048:%-10lu",   MCF5282_FEC_RMON_T_P_GTE2048);
695    printf("      Tx Octets:%-10lu\n",   MCF5282_FEC_RMON_T_OCTETS);
696    printf("     Tx Dropped:%-10lu", MCF5282_FEC_IEEE_T_DROP);
697    printf("    Tx Frame OK:%-10lu",   MCF5282_FEC_IEEE_T_FRAME_OK);
698    printf(" Tx 1 Collision:%-10lu\n",   MCF5282_FEC_IEEE_T_1COL);
699    printf("Tx >1 Collision:%-10lu", MCF5282_FEC_IEEE_T_MCOL);
700    printf("    Tx Deferred:%-10lu",   MCF5282_FEC_IEEE_T_DEF);
701    printf(" Late Collision:%-10lu\n",   MCF5282_FEC_IEEE_T_LCOL);
702    printf(" Excessive Coll:%-10lu", MCF5282_FEC_IEEE_T_EXCOL);
703    printf("  FIFO Underrun:%-10lu",   MCF5282_FEC_IEEE_T_MACERR);
704    printf("  Carrier Error:%-10lu\n",   MCF5282_FEC_IEEE_T_CSERR);
705    printf("   Tx SQE Error:%-10lu", MCF5282_FEC_IEEE_T_SQE);
706    printf("Tx Pause Frames:%-10lu",   MCF5282_FEC_IEEE_T_FDXFC);
707    printf("   Tx Octets OK:%-10lu\n", MCF5282_FEC_IEEE_T_OCTETS_OK);
708}
709
710static int
711fec_ioctl(struct ifnet *ifp, int command, caddr_t data)
712{
713    struct mcf5282_enet_struct *sc = ifp->if_softc;
714    int error = 0;
715
716    switch (command) {
717        case SIOCGIFADDR:
718        case SIOCSIFADDR:
719            ether_ioctl(ifp, command, data);
720            break;
721
722        case SIOCSIFFLAGS:
723            switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
724                case IFF_RUNNING:
725                    fec_stop(sc);
726                    break;
727
728                case IFF_UP:
729                    fec_init(sc);
730                    break;
731
732                case IFF_UP | IFF_RUNNING:
733                    fec_stop(sc);
734                    fec_init(sc);
735                    break;
736
737                default:
738                    break;
739            }
740            break;
741
742        case SIO_RTEMS_SHOW_STATS:
743            enet_stats(sc);
744            break;
745
746            /*
747             * FIXME: All sorts of multicast commands need to be added here!
748             */
749        default:
750            error = EINVAL;
751            break;
752    }
753    return error;
754}
755
756int
757rtems_fec_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching )
758{
759    struct mcf5282_enet_struct *sc;
760    struct ifnet *ifp;
761    int mtu;
762    int unitNumber;
763    char *unitName;
764    unsigned char *hwaddr;
765
766printf("attaching\n"); rtems_task_wake_after(10);
767    /*
768     * Parse driver name
769     */
770    if ((unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName)) < 0)
771        return 0;
772
773    /*
774     * Is driver free?
775     */
776    if ((unitNumber <= 0) || (unitNumber > NIFACES)) {
777        printf("Bad FECC unit number.\n");
778        return 0;
779    }
780    sc = &enet_driver[unitNumber - 1];
781    ifp = &sc->arpcom.ac_if;
782    if (ifp->if_softc != NULL) {
783        printf("Driver already in use.\n");
784        return 0;
785    }
786
787    /*
788     * Process options
789     */
790    if (config->hardware_address)
791        hwaddr = config->hardware_address;
792    else
793        hwaddr = gethwaddr(unitNumber - 1);
794    printf("%s%d: Ethernet address: %02x:%02x:%02x:%02x:%02x:%02x\n",
795                                            unitName, unitNumber,
796                                            hwaddr[0], hwaddr[1], hwaddr[2],
797                                            hwaddr[3], hwaddr[4], hwaddr[5]);
798    memcpy(sc->arpcom.ac_enaddr, hwaddr, ETHER_ADDR_LEN);
799
800    if (config->mtu)
801        mtu = config->mtu;
802    else
803        mtu = ETHERMTU;
804    if (config->rbuf_count)
805        sc->rxBdCount = config->rbuf_count;
806    else
807        sc->rxBdCount = RX_BUF_COUNT;
808    if (config->xbuf_count)
809        sc->txBdCount = config->xbuf_count;
810    else
811        sc->txBdCount = TX_BUF_COUNT * TX_BD_PER_BUF;
812
813    sc->acceptBroadcast = !config->ignore_broadcast;
814
815    /*
816     * Set up network interface values
817     */
818    ifp->if_softc = sc;
819    ifp->if_unit = unitNumber;
820    ifp->if_name = unitName;
821    ifp->if_mtu = mtu;
822    ifp->if_init = fec_init;
823    ifp->if_ioctl = fec_ioctl;
824    ifp->if_start = mcf5282_enet_start;
825    ifp->if_output = ether_output;
826    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
827    if (ifp->if_snd.ifq_maxlen == 0)
828        ifp->if_snd.ifq_maxlen = ifqmaxlen;
829
830    /*
831     * Attach the interface
832     */
833    if_attach(ifp);
834    ether_ifattach(ifp);
835    return 1;
836};
837
Note: See TracBrowser for help on using the repository browser.