linux-bk/drivers/net/68360enet.c
<<
>>
Prefs
   1/*
   2 * Ethernet driver for Motorola MPC8xx.
   3 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com>
   4 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
   5 *
   6 * I copied the basic skeleton from the lance driver, because I did not
   7 * know how to write the Linux driver, but I did know how the LANCE worked.
   8 *
   9 * This version of the driver is somewhat selectable for the different
  10 * processor/board combinations.  It works for the boards I know about
  11 * now, and should be easily modified to include others.  Some of the
  12 * configuration information is contained in "commproc.h" and the
  13 * remainder is here.
  14 *
  15 * Buffer descriptors are kept in the CPM dual port RAM, and the frame
  16 * buffers are in the host memory.
  17 *
  18 * Right now, I am very watseful with the buffers.  I allocate memory
  19 * pages and then divide them into 2K frame buffers.  This way I know I
  20 * have buffers large enough to hold one frame within one buffer descriptor.
  21 * Once I get this working, I will use 64 or 128 byte CPM buffers, which
  22 * will be much more memory efficient and will easily handle lots of
  23 * small packets.
  24 *
  25 */
  26#include <linux/config.h>
  27#include <linux/kernel.h>
  28#include <linux/string.h>
  29#include <linux/ptrace.h>
  30#include <linux/errno.h>
  31#include <linux/ioport.h>
  32#include <linux/interrupt.h>
  33#include <linux/pci.h>
  34#include <linux/init.h>
  35#include <linux/delay.h>
  36#include <linux/netdevice.h>
  37#include <linux/etherdevice.h>
  38#include <linux/skbuff.h>
  39#include <linux/spinlock.h> 
  40
  41#include <asm/irq.h>
  42#include <asm/m68360.h>
  43/* #include <asm/8xx_immap.h> */
  44/* #include <asm/pgtable.h> */
  45/* #include <asm/mpc8xx.h> */
  46#include <asm/bitops.h>
  47/* #include <asm/uaccess.h> */
  48#include <asm/commproc.h>
  49
  50
  51/*
  52 *                              Theory of Operation
  53 *
  54 * The MPC8xx CPM performs the Ethernet processing on SCC1.  It can use
  55 * an aribtrary number of buffers on byte boundaries, but must have at
  56 * least two receive buffers to prevent constant overrun conditions.
  57 *
  58 * The buffer descriptors are allocated from the CPM dual port memory
  59 * with the data buffers allocated from host memory, just like all other
  60 * serial communication protocols.  The host memory buffers are allocated
  61 * from the free page pool, and then divided into smaller receive and
  62 * transmit buffers.  The size of the buffers should be a power of two,
  63 * since that nicely divides the page.  This creates a ring buffer
  64 * structure similar to the LANCE and other controllers.
  65 *
  66 * Like the LANCE driver:
  67 * The driver runs as two independent, single-threaded flows of control.  One
  68 * is the send-packet routine, which enforces single-threaded use by the
  69 * cep->tx_busy flag.  The other thread is the interrupt handler, which is
  70 * single threaded by the hardware and other software.
  71 *
  72 * The send packet thread has partial control over the Tx ring and the
  73 * 'cep->tx_busy' flag.  It sets the tx_busy flag whenever it's queuing a Tx
  74 * packet. If the next queue slot is empty, it clears the tx_busy flag when
  75 * finished otherwise it sets the 'lp->tx_full' flag.
  76 *
  77 * The MBX has a control register external to the MPC8xx that has some
  78 * control of the Ethernet interface.  Information is in the manual for
  79 * your board.
  80 *
  81 * The RPX boards have an external control/status register.  Consult the
  82 * programming documents for details unique to your board.
  83 *
  84 * For the TQM8xx(L) modules, there is no control register interface.
  85 * All functions are directly controlled using I/O pins.  See commproc.h.
  86 */
  87
  88
  89/* The transmitter timeout
  90 */
  91#define TX_TIMEOUT      (2*HZ)
  92
  93/* The number of Tx and Rx buffers.  These are allocated statically here.
  94 * We don't need to allocate pages for the transmitter.  We just use
  95 * the skbuffer directly.
  96 */
  97#ifdef CONFIG_ENET_BIG_BUFFERS
  98#define RX_RING_SIZE            64
  99#define TX_RING_SIZE            64      /* Must be power of two */
 100#define TX_RING_MOD_MASK        63      /*   for this to work */
 101#else
 102#define RX_RING_SIZE            8
 103#define TX_RING_SIZE            8       /* Must be power of two */
 104#define TX_RING_MOD_MASK        7       /*   for this to work */
 105#endif
 106
 107#define CPM_ENET_RX_FRSIZE  2048 /* overkill left over from ppc page-based allocation */
 108static char rx_buf_pool[RX_RING_SIZE * CPM_ENET_RX_FRSIZE];
 109
 110
 111/* The CPM stores dest/src/type, data, and checksum for receive packets.
 112 */
 113#define PKT_MAXBUF_SIZE         1518
 114#define PKT_MINBUF_SIZE         64
 115#define PKT_MAXBLR_SIZE         1520
 116
 117/* The CPM buffer descriptors track the ring buffers.  The rx_bd_base and
 118 * tx_bd_base always point to the base of the buffer descriptors.  The
 119 * cur_rx and cur_tx point to the currently available buffer.
 120 * The dirty_tx tracks the current buffer that is being sent by the
 121 * controller.  The cur_tx and dirty_tx are equal under both completely
 122 * empty and completely full conditions.  The empty/ready indicator in
 123 * the buffer descriptor determines the actual condition.
 124 */
 125struct scc_enet_private {
 126        /* The saved address of a sent-in-place packet/buffer, for skfree(). */
 127        struct  sk_buff* tx_skbuff[TX_RING_SIZE];
 128        ushort  skb_cur;
 129        ushort  skb_dirty;
 130
 131        /* CPM dual port RAM relative addresses.
 132        */
 133        QUICC_BD        *rx_bd_base;            /* Address of Rx and Tx buffers. */
 134        QUICC_BD        *tx_bd_base;
 135        QUICC_BD        *cur_rx, *cur_tx;               /* The next free ring entry */
 136        QUICC_BD        *dirty_tx;      /* The ring entries to be free()ed. */
 137        volatile struct scc_regs        *sccp;
 138        /* struct       net_device_stats stats; */
 139        struct  net_device_stats stats;
 140        uint    tx_full;
 141        /* spinlock_t lock; */
 142        volatile unsigned int lock;
 143};
 144
 145
 146
 147static int scc_enet_open(struct net_device *dev);
 148static int scc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
 149static int scc_enet_rx(struct net_device *dev);
 150static irqreturn_t scc_enet_interrupt(int vec, void *dev_id, struct pt_regs *fp);
 151static int scc_enet_close(struct net_device *dev);
 152/* static struct net_device_stats *scc_enet_get_stats(struct net_device *dev); */
 153static struct net_device_stats *scc_enet_get_stats(struct net_device *dev);
 154static void set_multicast_list(struct net_device *dev);
 155
 156/* Get this from various configuration locations (depends on board).
 157*/
 158/*static        ushort  my_enet_addr[] = { 0x0800, 0x3e26, 0x1559 };*/
 159
 160/* Typically, 860(T) boards use SCC1 for Ethernet, and other 8xx boards
 161 * use SCC2.  This is easily extended if necessary.
 162 */
 163
 164#define CONFIG_SCC1_ENET /* by default */
 165
 166#ifdef CONFIG_SCC1_ENET
 167#define CPM_CR_ENET CPM_CR_CH_SCC1
 168#define PROFF_ENET      PROFF_SCC1
 169#define SCC_ENET        0
 170#define CPMVEC_ENET     CPMVEC_SCC1
 171#endif
 172
 173#ifdef CONFIG_SCC2_ENET
 174#define CPM_CR_ENET     CPM_CR_CH_SCC2
 175#define PROFF_ENET      PROFF_SCC2
 176#define SCC_ENET        1               /* Index, not number! */
 177#define CPMVEC_ENET     CPMVEC_SCC2
 178#endif
 179
 180static int
 181scc_enet_open(struct net_device *dev)
 182{
 183
 184        /* I should reset the ring buffers here, but I don't yet know
 185         * a simple way to do that.
 186         * mleslie: That's no biggie. Worth doing, too.
 187         */
 188
 189        /* netif_start_queue(dev); */
 190        return 0;                                       /* Always succeed */
 191}
 192
 193
 194static int
 195scc_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 196{
 197        struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
 198        volatile QUICC_BD       *bdp;
 199
 200        /* Fill in a Tx ring entry */
 201        bdp = cep->cur_tx;
 202
 203#ifndef final_version
 204        if (bdp->status & BD_ENET_TX_READY) {
 205                /* Ooops.  All transmit buffers are full.  Bail out.
 206                 * This should not happen, since cep->tx_busy should be set.
 207                 */
 208                printk("%s: tx queue full!.\n", dev->name);
 209                return 1;
 210        }
 211#endif
 212
 213        /* Clear all of the status flags.
 214         */
 215        bdp->status &= ~BD_ENET_TX_STATS;
 216
 217        /* If the frame is short, tell CPM to pad it.
 218        */
 219        if (skb->len <= ETH_ZLEN)
 220                bdp->status |= BD_ENET_TX_PAD;
 221        else
 222                bdp->status &= ~BD_ENET_TX_PAD;
 223
 224        /* Set buffer length and buffer pointer.
 225        */
 226        bdp->length = skb->len;
 227        /* bdp->buf = __pa(skb->data); */
 228        bdp->buf = skb->data;
 229
 230        /* Save skb pointer.
 231        */
 232        cep->tx_skbuff[cep->skb_cur] = skb;
 233
 234        /* cep->stats.tx_bytes += skb->len; */ /* TODO: It would really be nice... */
 235
 236        cep->skb_cur = (cep->skb_cur+1) & TX_RING_MOD_MASK;
 237        
 238
 239        /* Push the data cache so the CPM does not get stale memory
 240         * data.
 241         */
 242/*      flush_dcache_range((unsigned long)(skb->data), */
 243/*                                      (unsigned long)(skb->data + skb->len)); */
 244
 245        /* spin_lock_irq(&cep->lock); */ /* TODO: SPINLOCK */
 246        local_irq_disable();
 247        if (cep->lock > 0) {
 248                printk ("scc_enet_start_xmit() lock == %d\n", cep->lock);
 249        } else {
 250                cep->lock++;
 251        }
 252
 253        /* Send it on its way.  Tell CPM its ready, interrupt when done,
 254         * its the last BD of the frame, and to put the CRC on the end.
 255         */
 256        bdp->status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR | BD_ENET_TX_LAST | BD_ENET_TX_TC);
 257
 258        dev->trans_start = jiffies;
 259
 260        /* If this was the last BD in the ring, start at the beginning again.
 261        */
 262        if (bdp->status & BD_ENET_TX_WRAP)
 263                bdp = cep->tx_bd_base;
 264        else
 265                bdp++;
 266
 267        if (bdp->status & BD_ENET_TX_READY) {
 268                /* netif_stop_queue(dev); */
 269                cep->tx_full = 1;
 270        }
 271
 272        cep->cur_tx = (QUICC_BD *)bdp;
 273
 274        /* spin_unlock_irq(&cep->lock); */ /* TODO: SPINLOCK */
 275        cep->lock--;
 276        sti();
 277
 278        return 0;
 279}
 280
 281#if 0
 282static void
 283scc_enet_timeout(struct net_device *dev)
 284{
 285        struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
 286
 287        printk("%s: transmit timed out.\n", dev->name);
 288        cep->stats.tx_errors++;
 289#ifndef final_version
 290        {
 291                int     i;
 292                QUICC_BD        *bdp;
 293                printk(" Ring data dump: cur_tx %p%s cur_rx %p.\n",
 294                       cep->cur_tx, cep->tx_full ? " (full)" : "",
 295                       cep->cur_rx);
 296                bdp = cep->tx_bd_base;
 297                for (i = 0 ; i < TX_RING_SIZE; i++, bdp++)
 298                        printk("%04x %04x %08x\n",
 299                               bdp->status,
 300                               bdp->length,
 301                               (int)(bdp->buf));
 302                bdp = cep->rx_bd_base;
 303                for (i = 0 ; i < RX_RING_SIZE; i++, bdp++)
 304                        printk("%04x %04x %08x\n",
 305                               bdp->status,
 306                               bdp->length,
 307                               (int)(bdp->buf));
 308        }
 309#endif
 310/*      if (!cep->tx_full) */
 311/*              netif_wake_queue(dev); */
 312}
 313#endif
 314
 315/* The interrupt handler.
 316 * This is called from the CPM handler, not the MPC core interrupt.
 317 */
 318static irqreturn_t scc_enet_interrupt(int vec, void *dev_id, struct pt_regs *fp)
 319{
 320        struct  net_device *dev = (struct net_device *)dev_id;
 321        volatile struct scc_enet_private *cep;
 322        volatile QUICC_BD       *bdp;
 323        ushort  int_events;
 324        int     must_restart;
 325
 326        cep = (struct scc_enet_private *)dev->priv;
 327
 328        /* Get the interrupt events that caused us to be here.
 329        */
 330        int_events = cep->sccp->scc_scce;
 331        cep->sccp->scc_scce = int_events;
 332        must_restart = 0;
 333
 334        /* Handle receive event in its own function.
 335        */
 336        if (int_events & SCCE_ENET_RXF)
 337                scc_enet_rx(dev_id);
 338
 339        /* Check for a transmit error.  The manual is a little unclear
 340         * about this, so the debug code until I get it figured out.  It
 341         * appears that if TXE is set, then TXB is not set.  However,
 342         * if carrier sense is lost during frame transmission, the TXE
 343         * bit is set, "and continues the buffer transmission normally."
 344         * I don't know if "normally" implies TXB is set when the buffer
 345         * descriptor is closed.....trial and error :-).
 346         */
 347
 348        /* Transmit OK, or non-fatal error.  Update the buffer descriptors.
 349        */
 350        if (int_events & (SCCE_ENET_TXE | SCCE_ENET_TXB)) {
 351            /* spin_lock(&cep->lock); */ /* TODO: SPINLOCK */
 352                /* local_irq_disable(); */
 353                if (cep->lock > 0) {
 354                        printk ("scc_enet_interrupt() lock == %d\n", cep->lock);
 355                } else {
 356                        cep->lock++;
 357                }
 358
 359            bdp = cep->dirty_tx;
 360            while ((bdp->status&BD_ENET_TX_READY)==0) {
 361                if ((bdp==cep->cur_tx) && (cep->tx_full == 0))
 362                    break;
 363
 364                if (bdp->status & BD_ENET_TX_HB)        /* No heartbeat */
 365                        cep->stats.tx_heartbeat_errors++;
 366                if (bdp->status & BD_ENET_TX_LC)        /* Late collision */
 367                        cep->stats.tx_window_errors++;
 368                if (bdp->status & BD_ENET_TX_RL)        /* Retrans limit */
 369                        cep->stats.tx_aborted_errors++;
 370                if (bdp->status & BD_ENET_TX_UN)        /* Underrun */
 371                        cep->stats.tx_fifo_errors++;
 372                if (bdp->status & BD_ENET_TX_CSL)       /* Carrier lost */
 373                        cep->stats.tx_carrier_errors++;
 374
 375
 376                /* No heartbeat or Lost carrier are not really bad errors.
 377                 * The others require a restart transmit command.
 378                 */
 379                if (bdp->status &
 380                    (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
 381                        must_restart = 1;
 382                        cep->stats.tx_errors++;
 383                }
 384
 385                cep->stats.tx_packets++;
 386
 387                /* Deferred means some collisions occurred during transmit,
 388                 * but we eventually sent the packet OK.
 389                 */
 390                if (bdp->status & BD_ENET_TX_DEF)
 391                        cep->stats.collisions++;
 392
 393                /* Free the sk buffer associated with this last transmit.
 394                */
 395                /* dev_kfree_skb_irq(cep->tx_skbuff[cep->skb_dirty]); */
 396                dev_kfree_skb (cep->tx_skbuff[cep->skb_dirty]);
 397                cep->skb_dirty = (cep->skb_dirty + 1) & TX_RING_MOD_MASK;
 398
 399                /* Update pointer to next buffer descriptor to be transmitted.
 400                */
 401                if (bdp->status & BD_ENET_TX_WRAP)
 402                        bdp = cep->tx_bd_base;
 403                else
 404                        bdp++;
 405
 406                /* I don't know if we can be held off from processing these
 407                 * interrupts for more than one frame time.  I really hope
 408                 * not.  In such a case, we would now want to check the
 409                 * currently available BD (cur_tx) and determine if any
 410                 * buffers between the dirty_tx and cur_tx have also been
 411                 * sent.  We would want to process anything in between that
 412                 * does not have BD_ENET_TX_READY set.
 413                 */
 414
 415                /* Since we have freed up a buffer, the ring is no longer
 416                 * full.
 417                 */
 418                if (cep->tx_full) {
 419                        cep->tx_full = 0;
 420/*                      if (netif_queue_stopped(dev)) */
 421/*                              netif_wake_queue(dev); */
 422                }
 423
 424                cep->dirty_tx = (QUICC_BD *)bdp;
 425            }
 426
 427            if (must_restart) {
 428                        volatile QUICC *cp;
 429
 430                /* Some transmit errors cause the transmitter to shut
 431                 * down.  We now issue a restart transmit.  Since the
 432                 * errors close the BD and update the pointers, the restart
 433                 * _should_ pick up without having to reset any of our
 434                 * pointers either.
 435                 */
 436                cp = pquicc;
 437                cp->cp_cr =
 438                    mk_cr_cmd(CPM_CR_ENET, CPM_CR_RESTART_TX) | CPM_CR_FLG;
 439                while (cp->cp_cr & CPM_CR_FLG);
 440            }
 441            /* spin_unlock(&cep->lock); */ /* TODO: SPINLOCK */
 442                /* sti(); */
 443                cep->lock--;
 444        }
 445
 446        /* Check for receive busy, i.e. packets coming but no place to
 447         * put them.  This "can't happen" because the receive interrupt
 448         * is tossing previous frames.
 449         */
 450        if (int_events & SCCE_ENET_BSY) {
 451                cep->stats.rx_dropped++;
 452                printk("CPM ENET: BSY can't happen.\n");
 453        }
 454
 455        return IRQ_HANDLED;
 456}
 457
 458/* During a receive, the cur_rx points to the current incoming buffer.
 459 * When we update through the ring, if the next incoming buffer has
 460 * not been given to the system, we just set the empty indicator,
 461 * effectively tossing the packet.
 462 */
 463static int
 464scc_enet_rx(struct net_device *dev)
 465{
 466        struct  scc_enet_private *cep;
 467        volatile QUICC_BD       *bdp;
 468        struct  sk_buff *skb;
 469        ushort  pkt_len;
 470
 471        cep = (struct scc_enet_private *)dev->priv;
 472
 473        /* First, grab all of the stats for the incoming packet.
 474         * These get messed up if we get called due to a busy condition.
 475         */
 476        bdp = cep->cur_rx;
 477
 478        for (;;) {
 479                if (bdp->status & BD_ENET_RX_EMPTY)
 480                        break;
 481                
 482#ifndef final_version
 483                /* Since we have allocated space to hold a complete frame, both
 484                 * the first and last indicators should be set.
 485                 */
 486                if ((bdp->status & (BD_ENET_RX_FIRST | BD_ENET_RX_LAST)) !=
 487                        (BD_ENET_RX_FIRST | BD_ENET_RX_LAST))
 488                        printk("CPM ENET: rcv is not first+last\n");
 489#endif
 490
 491                /* Frame too long or too short.
 492                 */
 493                if (bdp->status & (BD_ENET_RX_LG | BD_ENET_RX_SH))
 494                        cep->stats.rx_length_errors++;
 495                if (bdp->status & BD_ENET_RX_NO)        /* Frame alignment */
 496                        cep->stats.rx_frame_errors++;
 497                if (bdp->status & BD_ENET_RX_CR)        /* CRC Error */
 498                        cep->stats.rx_crc_errors++;
 499                if (bdp->status & BD_ENET_RX_OV)        /* FIFO overrun */
 500                        cep->stats.rx_crc_errors++;
 501
 502                /* Report late collisions as a frame error.
 503                 * On this error, the BD is closed, but we don't know what we
 504                 * have in the buffer.  So, just drop this frame on the floor.
 505                 */
 506                if (bdp->status & BD_ENET_RX_CL) {
 507                        cep->stats.rx_frame_errors++;
 508                }
 509                else {
 510                        
 511                        /* Process the incoming frame.
 512                         */
 513                        cep->stats.rx_packets++;
 514                        pkt_len = bdp->length;
 515                        /* cep->stats.rx_bytes += pkt_len; */  /* TODO: It would really be nice... */
 516
 517                        /* This does 16 byte alignment, much more than we need.
 518                         * The packet length includes FCS, but we don't want to
 519                         * include that when passing upstream as it messes up
 520                         * bridging applications.
 521                         */
 522                        skb = dev_alloc_skb(pkt_len-4);
 523
 524                        if (skb == NULL) {
 525                                printk("%s: Memory squeeze, dropping packet.\n", dev->name);
 526                                cep->stats.rx_dropped++;
 527                        }
 528                        else {
 529                                skb->dev = dev;
 530                                skb_put(skb,pkt_len-4); /* Make room */
 531                                eth_copy_and_sum(skb, (unsigned char *)bdp->buf, pkt_len-4, 0);
 532                                skb->protocol=eth_type_trans(skb,dev);
 533                                netif_rx(skb);
 534                        }
 535                }
 536
 537                /* Clear the status flags for this buffer.
 538                 */
 539                bdp->status &= ~BD_ENET_RX_STATS;
 540
 541                /* Mark the buffer empty.
 542                 */
 543                bdp->status |= BD_ENET_RX_EMPTY;
 544
 545                /* Update BD pointer to next entry.
 546                 */
 547                if (bdp->status & BD_ENET_RX_WRAP)
 548                        bdp = cep->rx_bd_base;
 549                else
 550                        bdp++;
 551
 552        }
 553        cep->cur_rx = (QUICC_BD *)bdp;
 554
 555        return 0;
 556}
 557
 558static int
 559scc_enet_close(struct net_device *dev)
 560{
 561        /* Don't know what to do yet.
 562        */
 563        /* netif_stop_queue(dev); */
 564
 565        return 0;
 566}
 567
 568/* static struct net_device_stats *scc_enet_get_stats(struct net_device *dev) */
 569static struct net_device_stats *scc_enet_get_stats(struct net_device *dev)
 570{
 571        struct scc_enet_private *cep = (struct scc_enet_private *)dev->priv;
 572
 573        return &cep->stats;
 574}
 575
 576/* Set or clear the multicast filter for this adaptor.
 577 * Skeleton taken from sunlance driver.
 578 * The CPM Ethernet implementation allows Multicast as well as individual
 579 * MAC address filtering.  Some of the drivers check to make sure it is
 580 * a group multicast address, and discard those that are not.  I guess I
 581 * will do the same for now, but just remove the test if you want
 582 * individual filtering as well (do the upper net layers want or support
 583 * this kind of feature?).
 584 */
 585
 586static void set_multicast_list(struct net_device *dev)
 587{
 588        struct  scc_enet_private *cep;
 589        struct  dev_mc_list *dmi;
 590        u_char  *mcptr, *tdptr;
 591        volatile scc_enet_t *ep;
 592        int     i, j;
 593        volatile QUICC *cp = pquicc;
 594
 595        cep = (struct scc_enet_private *)dev->priv;
 596
 597        /* Get pointer to SCC area in parameter RAM.
 598        */
 599        ep = (scc_enet_t *)dev->base_addr;
 600
 601        if (dev->flags&IFF_PROMISC) {
 602          
 603                /* Log any net taps. */
 604                printk("%s: Promiscuous mode enabled.\n", dev->name);
 605                cep->sccp->scc_psmr |= ETHER_PRO; 
 606        } else {
 607
 608                cep->sccp->scc_psmr &= ~ETHER_PRO;
 609
 610                if (dev->flags & IFF_ALLMULTI) {
 611                        /* Catch all multicast addresses, so set the
 612                         * filter to all 1's.
 613                         */
 614                        ep->sen_gaddr1 = 0xffff;
 615                        ep->sen_gaddr2 = 0xffff;
 616                        ep->sen_gaddr3 = 0xffff;
 617                        ep->sen_gaddr4 = 0xffff;
 618                }
 619                else {
 620                        /* Clear filter and add the addresses in the list.
 621                        */
 622                        ep->sen_gaddr1 = 0;
 623                        ep->sen_gaddr2 = 0;
 624                        ep->sen_gaddr3 = 0;
 625                        ep->sen_gaddr4 = 0;
 626
 627                        dmi = dev->mc_list;
 628
 629                        for (i=0; i<dev->mc_count; i++) {
 630                                
 631                                /* Only support group multicast for now.
 632                                */
 633                                if (!(dmi->dmi_addr[0] & 1))
 634                                        continue;
 635
 636                                /* The address in dmi_addr is LSB first,
 637                                 * and taddr is MSB first.  We have to
 638                                 * copy bytes MSB first from dmi_addr.
 639                                 */
 640                                mcptr = (u_char *)dmi->dmi_addr + 5;
 641                                tdptr = (u_char *)&ep->sen_taddrh;
 642                                for (j=0; j<6; j++)
 643                                        *tdptr++ = *mcptr--;
 644
 645                                /* Ask CPM to run CRC and set bit in
 646                                 * filter mask.
 647                                 */
 648                                cp->cp_cr = mk_cr_cmd(CPM_CR_ENET, CPM_CR_SET_GADDR) | CPM_CR_FLG;
 649                                /* this delay is necessary here -- Cort */
 650                                udelay(10);
 651                                while (cp->cp_cr & CPM_CR_FLG);
 652                        }
 653                }
 654        }
 655}
 656
 657
 658/* Initialize the CPM Ethernet on SCC.
 659 */
 660int scc_enet_init(void)
 661{
 662        struct net_device *dev;
 663        struct scc_enet_private *cep;
 664        int i, j;
 665        unsigned char   *eap;
 666        /* unsigned long        mem_addr; */
 667        /* pte_t                *pte; */
 668        /* bd_t         *bd; */ /* `board tag' used by ppc - TODO: integrate uC bootloader vars */
 669        volatile        QUICC_BD        *bdp;
 670        volatile        QUICC   *cp;
 671        volatile struct scc_regs        *sccp;
 672        volatile struct ethernet_pram   *ep;
 673        /* volatile     immap_t         *immap; */
 674
 675        cp = pquicc;    /* Get pointer to Communication Processor */
 676
 677        /* immap = (immap_t *)IMAP_ADDR; */     /* and to internal registers */
 678
 679        /* bd = (bd_t *)__res; */
 680
 681        /* Allocate some private information.
 682        */
 683        cep = (struct scc_enet_private *)kmalloc(sizeof(*cep), GFP_KERNEL);
 684        memset(cep, 0, sizeof(*cep));
 685        /* __clear_user(cep,sizeof(*cep)); */
 686        /* spin_lock_init(&cep->lock); */ /* TODO: SPINLOCK */
 687
 688        /* Create an Ethernet device instance.
 689         */
 690        dev = init_etherdev(0, 0);
 691
 692        /* Get pointer to SCC area in parameter RAM.
 693        */
 694        /* ep = (ethernet_pram *)(&cp->cp_dparam[PROFF_ENET]); */
 695        ep = &pquicc->pram[SCC_ENET].enet_scc;
 696
 697        /* And another to the SCC register area.
 698        */
 699        sccp = &pquicc->scc_regs[SCC_ENET];
 700        cep->sccp = sccp;               /* Keep the pointer handy */
 701
 702        /* Disable receive and transmit in case EPPC-Bug started it.
 703        */
 704        sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
 705
 706        /* Set up 360 pins for SCC interface to ethernet transceiver.
 707         * Pin mappings (PA_xx and PC_xx) are defined in commproc.h
 708         */
 709
 710        /* Configure port A pins for Txd and Rxd.
 711         */
 712        pquicc->pio_papar |= (PA_ENET_RXD | PA_ENET_TXD);
 713        pquicc->pio_padir &= ~(PA_ENET_RXD | PA_ENET_TXD);
 714        pquicc->pio_paodr &= ~PA_ENET_TXD;
 715
 716        /* Configure port C pins to enable CLSN and RENA.
 717         */
 718        pquicc->pio_pcpar &= ~(PC_ENET_CLSN | PC_ENET_RENA);
 719        pquicc->pio_pcdir &= ~(PC_ENET_CLSN | PC_ENET_RENA);
 720        pquicc->pio_pcso |= (PC_ENET_CLSN | PC_ENET_RENA);
 721
 722        /* Configure port A for TCLK and RCLK.
 723        */
 724        pquicc->pio_papar |= (PA_ENET_TCLK | PA_ENET_RCLK);
 725        pquicc->pio_padir &= ~(PA_ENET_TCLK | PA_ENET_RCLK);
 726
 727        /* Configure Serial Interface clock routing.
 728         * First, clear all SCC bits to zero, then set the ones we want.
 729         */
 730        pquicc->si_sicr &= ~SICR_ENET_MASK;
 731        pquicc->si_sicr |= SICR_ENET_CLKRT;
 732
 733
 734        /* Allocate space for the buffer descriptors in the DP ram.
 735         * These are relative offsets in the DP ram address space.
 736         * Initialize base addresses for the buffer descriptors.
 737         */
 738        i = m360_cpm_dpalloc(sizeof(QUICC_BD) * RX_RING_SIZE);
 739        ep->rbase = i;
 740        cep->rx_bd_base = (QUICC_BD *)((uint)pquicc + i);
 741
 742        i = m360_cpm_dpalloc(sizeof(QUICC_BD) * TX_RING_SIZE);
 743        ep->tbase = i;
 744        cep->tx_bd_base = (QUICC_BD *)((uint)pquicc + i);
 745
 746        cep->dirty_tx = cep->cur_tx = cep->tx_bd_base;
 747        cep->cur_rx = cep->rx_bd_base;
 748
 749        /* Issue init Rx BD command for SCC.
 750         * Manual says to perform an Init Rx parameters here.  We have
 751         * to perform both Rx and Tx because the SCC may have been
 752         * already running. [In uCquicc's case, I don't think that is so - mles]
 753         * In addition, we have to do it later because we don't yet have
 754         * all of the BD control/status set properly.
 755        cp->cp_cpcr = mk_cr_cmd(CPM_CR_ENET, CPM_CR_INIT_RX) | CPM_CR_FLG;
 756        while (cp->cp_cpcr & CPM_CR_FLG);
 757         */
 758
 759        /* Initialize function code registers for big-endian.
 760        */
 761        ep->rfcr = (SCC_EB | SCC_FC_DMA);
 762        ep->tfcr = (SCC_EB | SCC_FC_DMA);
 763
 764        /* Set maximum bytes per receive buffer.
 765         * This appears to be an Ethernet frame size, not the buffer
 766         * fragment size.  It must be a multiple of four.
 767         */
 768        ep->mrblr  = PKT_MAXBLR_SIZE;
 769
 770        /* Set CRC preset and mask.
 771         */
 772        ep->c_pres = 0xffffffff;
 773        ep->c_mask = 0xdebb20e3; /* see 360UM p. 7-247 */
 774
 775        ep->crcec  = 0; /* CRC Error counter */
 776        ep->alec   = 0; /* alignment error counter */
 777        ep->disfc  = 0; /* discard frame counter */
 778
 779        ep->pads   = 0x8888;    /* Tx short frame pad character */
 780        ep->ret_lim = 0x000f;   /* Retry limit threshold */
 781
 782        ep->mflr   = PKT_MAXBUF_SIZE;   /* maximum frame length register */
 783        ep->minflr = PKT_MINBUF_SIZE;   /* minimum frame length register */
 784
 785        ep->maxd1 = PKT_MAXBLR_SIZE;    /* maximum DMA1 length */
 786        ep->maxd2 = PKT_MAXBLR_SIZE;    /* maximum DMA2 length */
 787
 788        /* Clear hash tables, group and individual.
 789         */
 790        ep->gaddr1 = ep->gaddr2 = ep->gaddr3 = ep->gaddr4 = 0;
 791        ep->iaddr1 = ep->iaddr2 = ep->iaddr3 = ep->iaddr4 = 0;
 792
 793        /* Set Ethernet station address.
 794         *
 795         * The uCbootloader provides a hook to the kernel to retrieve
 796         * stuff like the MAC address. This is retrieved in config_BSP()
 797         */
 798#if defined (CONFIG_UCQUICC)
 799        {
 800                extern unsigned char *scc1_hwaddr;
 801
 802                eap = (char *)ep->paddr.b;
 803                for (i=5; i>=0; i--)
 804                        *eap++ = dev->dev_addr[i] = scc1_hwaddr[i];
 805        }
 806#endif
 807
 808
 809/* #ifndef CONFIG_MBX */
 810/*      eap = (unsigned char *)&(ep->paddrh); */
 811
 812/*      for (i=5; i>=0; i--) */
 813/*              *eap++ = dev->dev_addr[i] = bd->bi_enetaddr[i]; */
 814/* #else */
 815/*      for (i=5; i>=0; i--) */
 816/*              dev->dev_addr[i] = *eap++; */
 817/* #endif */
 818
 819        ep->p_per   = 0;        /* 'cause the book says so */
 820        ep->taddr_l = 0;        /* temp address (LSB) */
 821        ep->taddr_m = 0;
 822        ep->taddr_h = 0;        /* temp address (MSB) */
 823
 824        /* Now allocate the host memory pages and initialize the
 825         * buffer descriptors.
 826         */
 827        /* initialize rx buffer descriptors */
 828        bdp = cep->tx_bd_base;
 829        for (j=0; j<(TX_RING_SIZE-1); j++) {
 830                bdp->buf = 0;
 831                bdp->status = 0;
 832                bdp++;
 833        }
 834        bdp->buf = 0;
 835        bdp->status = BD_SC_WRAP;
 836
 837
 838        /* initialize rx buffer descriptors */
 839        bdp = cep->rx_bd_base;
 840        for (j=0; j<(RX_RING_SIZE-1); j++) {
 841                bdp->buf = &rx_buf_pool[j * CPM_ENET_RX_FRSIZE];
 842                bdp->status = BD_SC_EMPTY | BD_SC_INTRPT;
 843                bdp++;
 844        }
 845        bdp->buf = &rx_buf_pool[j * CPM_ENET_RX_FRSIZE];
 846        bdp->status = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
 847
 848
 849
 850        /* Let's re-initialize the channel now.  We have to do it later
 851         * than the manual describes because we have just now finished
 852         * the BD initialization.
 853         */
 854        cp->cp_cr = mk_cr_cmd(CPM_CR_ENET, CPM_CR_INIT_TRX) | CPM_CR_FLG;
 855        while (cp->cp_cr & CPM_CR_FLG);
 856
 857        cep->skb_cur = cep->skb_dirty = 0;
 858
 859        sccp->scc_scce = 0xffff;        /* Clear any pending events */
 860
 861        /* Enable interrupts for transmit error, complete frame
 862         * received, and any transmit buffer we have also set the
 863         * interrupt flag.
 864         */
 865        sccp->scc_sccm = (SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);
 866
 867        /* Install our interrupt handler.
 868         */
 869        /* cpm_install_handler(CPMVEC_ENET, scc_enet_interrupt, dev); */
 870        request_irq(CPMVEC_ENET, scc_enet_interrupt,
 871                IRQ_FLG_LOCK, dev->name, (void *)dev);
 872
 873        /* Set GSMR_H to enable all normal operating modes.
 874         * Set GSMR_L to enable Ethernet to MC68160.
 875         */
 876        sccp->scc_gsmr.w.high = 0;
 877        sccp->scc_gsmr.w.low  = (SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 |
 878                                                         SCC_GSMRL_TPP_10 | SCC_GSMRL_MODE_ENET);
 879
 880        /* Set sync/delimiters.
 881         */
 882        sccp->scc_dsr = 0xd555;
 883
 884        /* Set processing mode.  Use Ethernet CRC, catch broadcast, and
 885         * start frame search 22 bit times after RENA.
 886         */
 887        sccp->scc_psmr = (SCC_PMSR_ENCRC       /* Ethernet CRC mode */
 888                          /* | SCC_PSMR_HBC */ /* Enable heartbeat */
 889                          /* | SCC_PMSR_PRO */ /* Promiscuous mode */
 890                          /* | SCC_PMSR_FDE */ /* Full duplex enable */
 891                          | ETHER_NIB_22);
 892        /* sccp->scc_psmr = (SCC_PMSR_PRO | ETHER_CRC_32 | ETHER_NIB_22); */
 893
 894
 895        /* It is now OK to enable the Ethernet transmitter.
 896         * Unfortunately, there are board implementation differences here.
 897         */
 898#if defined(CONFIG_UCQUICC)
 899/*       immap->im_ioport.iop_pcpar |= PC_ENET_TENA; */
 900/*       immap->im_ioport.iop_pcdir &= ~PC_ENET_TENA; */
 901         cp->pio_pcpar |=  PC_ENET_TENA; /* t_en */
 902         cp->pio_pcdir &= ~PC_ENET_TENA;
 903
 904         cp->pip_pbpar &= ~(0x00000200); /* power up ethernet transceiver */
 905         cp->pip_pbdir |=  (0x00000200);
 906         cp->pip_pbdat |=  (0x00000200);
 907#endif
 908
 909
 910        dev->base_addr = (unsigned long)ep;
 911        dev->priv = cep;
 912#if 0
 913        dev->name = "CPM_ENET";
 914#endif
 915
 916        /* The CPM Ethernet specific entries in the device structure. */
 917        dev->open = scc_enet_open;
 918        dev->hard_start_xmit = scc_enet_start_xmit;
 919        /* dev->tx_timeout = scc_enet_timeout; */
 920        /* dev->watchdog_timeo = TX_TIMEOUT; */
 921        dev->stop = scc_enet_close;
 922        dev->get_stats = scc_enet_get_stats;
 923        dev->set_multicast_list = set_multicast_list;
 924
 925        /* And last, enable the transmit and receive processing.
 926        */
 927        sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
 928
 929        printk("%s: CPM ENET Version 0.3, ", dev->name);
 930        for (i=0; i<5; i++)
 931                printk("%02x:", dev->dev_addr[i]);
 932        printk("%02x\n", dev->dev_addr[5]);
 933
 934        return 0;
 935}
 936
 937
 938
 939int m68360_enet_probe(struct device *dev)
 940{
 941        return(scc_enet_init ());
 942}
 943
 944
 945/*
 946 * Local variables:
 947 *  c-indent-level: 4
 948 *  c-basic-offset: 4
 949 *  tab-width: 4
 950 * End:
 951 */
 952
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.