source: rtems/c/src/lib/libbsp/m68k/mcf5329/network/network.c @ d8d6a08

5
Last change on this file since d8d6a08 was d8d6a08, checked in by Sebastian Huber <sebastian.huber@…>, on 01/27/18 at 10:12:44

bsps: Move network define to source files

Define INSIDE_RTEMS_BSD_TCPIP_STACK in the network interface driver
source files to avoid some build system magic.

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