root/drivers/net/sunlance.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. load_csrs
  2. lance_init_ring
  3. init_restart_lance
  4. lance_rx
  5. lance_tx
  6. lance_interrupt
  7. lance_open
  8. lance_close
  9. lance_reset
  10. lance_start_xmit
  11. lance_get_stats
  12. lance_set_multicast
  13. sparc_lance_probe

   1 /* lance.c: Linux/Sparc/Lance driver */
   2 /*
   3         Written 1995 by Miguel de Icaza
   4   Sources:
   5         The Linux  depca driver
   6         The Linux  lance driver.
   7         The Linux  skeleton driver.
   8         The NetBSD Sparc/Lance driver.
   9         Theo Deraadt (deraadt@theos.com)
  10         NCR92C990 Lan Controller manual
  11 */
  12 
  13 static char *version =
  14         "lance.c:v1.2 29/Oct/95 Miguel de Icaza (miguel@nuclecu.unam.mx)\n";
  15 
  16 #include <linux/kernel.h>
  17 #include <linux/sched.h>
  18 #include <linux/types.h>
  19 #include <linux/fcntl.h>
  20 #include <linux/interrupt.h>
  21 #include <linux/ptrace.h>
  22 #include <linux/ioport.h>
  23 #include <linux/in.h>
  24 #include <linux/malloc.h>
  25 #include <linux/string.h>
  26 #include <asm/system.h>
  27 #include <asm/bitops.h>
  28 #include <asm/io.h>
  29 #include <asm/dma.h>
  30 #include <linux/errno.h>
  31 #include <asm/byteorder.h>      /* Used by the checksum routines */
  32 
  33 /* Used for the temporal inet entries and routing */
  34 #include <linux/socket.h>
  35 #include <linux/route.h>
  36 
  37 #include <asm/idprom.h>
  38 #include <asm/sbus.h>
  39 #include <asm/openprom.h>
  40 #include <asm/oplib.h>
  41 
  42 #include <linux/netdevice.h>
  43 #include <linux/etherdevice.h>
  44 #include <linux/skbuff.h>
  45 
  46 #define MASK_INTERRUPTS   1
  47 #define UNMASK_INTERRUPTS 0
  48 
  49 /* Define: 2^2 Tx buffers and 2^4 Rx buffers */
  50 #ifndef LANCE_LOG_TX_BUFFERS
  51 #define LANCE_LOG_TX_BUFFERS 2
  52 #define LANCE_LOG_RX_BUFFERS 4
  53 #endif
  54 
  55 #define LE_CSR0 0
  56 #define LE_CSR1 1
  57 #define LE_CSR2 2
  58 #define LE_CSR3 3
  59 
  60 #define LE_MO_PROM      0x8000  /* Enable promiscuous mode */
  61 
  62 #define LE_C0_ERR       0x8000  /* Error: set if BAB, SQE, MISS or ME is set */
  63 #define LE_C0_BABL      0x4000  /* BAB:  Babble: tx timeout. */
  64 #define LE_C0_CERR      0x2000  /* SQE:  Signal quality error */
  65 #define LE_C0_MISS      0x1000  /* MISS: Missed a packaed */
  66 #define LE_C0_MERR      0x0800  /* ME:   Memory error */
  67 #define LE_C0_RINT      0x0400  /* Received interrupt */
  68 #define LE_C0_TINT      0x0200  /* Transmitter Interrupt */
  69 #define LE_C0_IDON      0x0100  /* IFIN: Init finished. */
  70 #define LE_C0_INTR      0x0080  /* Interrupt or error */
  71 #define LE_C0_INEA      0x0040  /* Interrupt enable */
  72 #define LE_C0_RXON      0x0020  /* Receiver on */
  73 #define LE_C0_TXON      0x0010  /* Transmitter on */
  74 #define LE_C0_TDMD      0x0008  /* Transmiter demand */
  75 #define LE_C0_STOP      0x0004  /* Stop the card */
  76 #define LE_C0_STRT      0x0002  /* Start the card */
  77 #define LE_C0_INIT      0x0001  /* Init the card */
  78 
  79 #define LE_C3_BSWP      0x4     /* SWAP */
  80 #define LE_C3_ACON      0x2     /* ALE Control */
  81 #define LE_C3_BCON      0x1     /* Byte control */
  82 
  83 /* Receive message descriptor 1 */
  84 #define LE_R1_OWN       0x80    /* Who owns the entry */
  85 #define LE_R1_ERR       0x40    /* Error: if FRA, OFL, CRC or BUF is set */
  86 #define LE_R1_FRA       0x20    /* FRA: Frame error */
  87 #define LE_R1_OFL       0x10    /* OFL: Frame overflow */
  88 #define LE_R1_CRC       0x08    /* CRC error */
  89 #define LE_R1_BUF       0x04    /* BUF: Buffer error */
  90 #define LE_R1_SOP       0x02    /* Start of packet */
  91 #define LE_R1_EOP       0x01    /* End of packet */
  92 #define LE_R1_POK       0x03    /* Packet is complete: SOP + EOP */
  93 
  94 #define LE_T1_OWN       0x80    /* Lance owns the packet */
  95 #define LE_T1_ERR       0x40    /* Error summary */
  96 #define LE_T1_EONE      0x08    /* Error: one retry needed */
  97 #define LE_T1_EDEF      0x04    /* Error: defered */
  98 #define LE_T1_SOP       0x02    /* Start of packet */
  99 #define LE_T1_EOP       0x01    /* End of packet */
 100 
 101 #define LE_T3_BUF       0x8000  /* Buffer error */
 102 #define LE_T3_UFL       0x4000  /* Error undeflow */
 103 #define LE_T3_LCOL      0x1000  /* Error late collision */
 104 #define LE_T3_CLOS      0x0800  /* Error carrier loss */
 105 #define LE_T3_RTY       0x0400  /* Error retry */
 106 #define LE_T3_TDR       0x03ff  /* Time Domain Reflectometry counter */
 107 
 108 #define TX_RING_SIZE                    (1 << (LANCE_LOG_TX_BUFFERS))
 109 #define TX_RING_MOD_MASK                (TX_RING_SIZE - 1)
 110 #define TX_RING_LEN_BITS                ((LANCE_LOG_TX_BUFFERS) << 29)
 111 
 112 #define RX_RING_SIZE                    (1 << (LANCE_LOG_RX_BUFFERS))
 113 #define RX_RING_MOD_MASK                (RX_RING_SIZE - 1)
 114 #define RX_RING_LEN_BITS                ((LANCE_LOG_RX_BUFFERS) << 29)
 115 
 116 #define PKT_BUF_SZ              1544
 117 #define RX_BUFF_SIZE            1536
 118 #define TX_BUFF_SIZE            1536
 119 
 120 struct lance_rx_desc {
 121     unsigned short rmd0;        /* low address of packet */
 122     unsigned char  rmd1_bits;   /* descriptor bits */
 123     unsigned char  rmd1_hadr;   /* high address of packet */
 124     short    length;            /* This length is 2s complement (negative)! Buffer length */
 125     unsigned short mblength;            /* This is the actual number of bytes received */
 126 };
 127 
 128 struct lance_tx_desc {
 129     unsigned short tmd0;        /* low address of packet */
 130     unsigned char  tmd1_bits;   /* descriptor bits */
 131     unsigned char  tmd1_hadr;   /* high address of packet */
 132     short length;               /* Length is 2s complement (negative)! */
 133     unsigned short misc;
 134 };
 135                 
 136 /* The LANCE initialization block, described in databook. */
 137 /* On the Sparc, this block should be on a DMA region     */
 138 struct lance_init_block {
 139     unsigned short mode;                /* Pre-set mode (reg. 15) */
 140     unsigned char phys_addr[6];         /* Physical ethernet address */
 141     unsigned filter[2];                 /* Multicast filter. */
 142     
 143     /* Receive and transmit ring base, along with extra bits. */
 144     unsigned short rx_ptr;              /* receive descriptor addr */
 145     unsigned short rx_len;              /* receive len and high addr */
 146     unsigned short tx_ptr;              /* transmit descriptor addr */
 147     unsigned short tx_len;              /* transmit len and high addr */
 148     
 149     /* The Tx and Rx ring entries must aligned on 8-byte boundaries. */
 150     struct lance_rx_desc brx_ring[RX_RING_SIZE];
 151     struct lance_tx_desc btx_ring[TX_RING_SIZE];
 152     
 153     char   rx_buf [RX_RING_SIZE][RX_BUFF_SIZE];
 154     char   tx_buf [TX_RING_SIZE][TX_BUFF_SIZE];
 155 };
 156 
 157 struct lance_private {
 158         char *name;
 159         volatile struct lance_regs *ll;
 160         volatile struct lance_init_block *init_block;
 161         
 162         int rx_new, tx_new;
 163         int rx_old, tx_old;
 164 
 165         struct enet_statistics stats;
 166 };
 167 
 168 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
 169                         lp->tx_old+TX_RING_MOD_MASK-lp->tx_new:\
 170                         lp->tx_old - lp->tx_new-1)
 171 
 172 /* On the sparc, the lance control ports are memory mapped */
 173 struct lance_regs {
 174     unsigned short rdp;                 /* register data port */
 175     unsigned short rap;                 /* register address port */
 176 };
 177 
 178 int sparc_lance_debug = 2;
 179 
 180 /* The Lance uses 24 bit addresses */
 181 /* The DVMA will provide the remaining bytes for us */
 182 #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
 183 
 184 /* Load the CSR registers */
 185 static void load_csrs (struct lance_private *lp)
     /* [previous][next][first][last][top][bottom][index][help] */
 186 {
 187     volatile struct lance_regs *ll = lp->ll;
 188     volatile struct lance_init_block *ib = lp->init_block;
 189     int leptr;
 190 
 191     leptr = LANCE_ADDR (ib);
 192     ll->rap = LE_CSR1;
 193     ll->rdp = (leptr & 0xFFFF);
 194     ll->rap = LE_CSR2;
 195     ll->rdp = leptr >> 16;
 196     ll->rap = LE_CSR3;
 197     ll->rdp = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
 198 
 199     /* Point back to csr0 */
 200     ll->rap = LE_CSR0;
 201 }
 202 
 203 #define ZERO 0
 204 
 205 /* Setup the Lance Rx and Tx rings */
 206 /* Sets dev->tbusy */
 207 static void
 208 lance_init_ring (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 209 {
 210     struct lance_private *lp = (struct lance_private *) dev->priv;
 211     volatile struct lance_init_block *ib = lp->init_block;
 212     int leptr;
 213     int i;
 214     
 215     /* Lock out other processes while setting up harware */
 216     dev->tbusy = 1;
 217     lp->rx_new = lp->tx_new = 0;
 218     lp->rx_old = lp->tx_old = 0;
 219 
 220     ib->mode = 0;
 221 
 222     /* Copy the ethernet address to the lance init block
 223      * Note that on the sparc you need to swap the ethernet address.
 224      */
 225     ib->phys_addr [0] = dev->dev_addr [1];
 226     ib->phys_addr [1] = dev->dev_addr [0];
 227     ib->phys_addr [2] = dev->dev_addr [3];
 228     ib->phys_addr [3] = dev->dev_addr [2];
 229     ib->phys_addr [4] = dev->dev_addr [5];
 230     ib->phys_addr [5] = dev->dev_addr [4];
 231 
 232     if (ZERO)
 233         printk ("TX rings:\n");
 234     
 235     /* Setup the Tx ring entries */
 236     for (i = 0; i <= TX_RING_SIZE; i++){
 237         leptr = LANCE_ADDR(&ib->tx_buf[i][0]);
 238         ib->btx_ring [i].tmd0      = leptr;
 239         ib->btx_ring [i].tmd1_hadr = leptr >> 16;
 240         ib->btx_ring [i].tmd1_bits = 0;
 241         ib->btx_ring [i].length    = 0xf000; /* The ones required by tmd2 */
 242         ib->btx_ring [i].misc      = 0;
 243         if (i < 3)
 244             if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
 245     }
 246 
 247     /* Setup the Rx ring entries */
 248     if (ZERO) printk ("RX rings:\n");
 249     for (i = 0; i < RX_RING_SIZE; i++){
 250         leptr = LANCE_ADDR(&ib->rx_buf[i][0]);
 251 
 252         ib->brx_ring [i].rmd0      = leptr;
 253         ib->brx_ring [i].rmd1_hadr = leptr >> 16;
 254         ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
 255         ib->brx_ring [i].length    = -RX_BUFF_SIZE | 0xf000;
 256         ib->brx_ring [i].mblength  = 0;
 257         if (i < 3)
 258             if (ZERO) printk ("%d: 0x%8.8x\n", i, leptr);
 259     }
 260 
 261     /* Setup the initialization block */
 262     
 263     /* Setup rx descriptor pointer */
 264     leptr = LANCE_ADDR(&ib->brx_ring);
 265     ib->rx_len = (LANCE_LOG_RX_BUFFERS << 13) | (leptr >> 16);
 266     ib->rx_ptr = leptr;
 267     if (ZERO) printk ("RX ptr: %8.8x\n", leptr);
 268     
 269     /* Setup tx descriptor pointer */
 270     leptr = LANCE_ADDR(&ib->btx_ring);
 271     ib->tx_len = (LANCE_LOG_TX_BUFFERS << 13) | (leptr >> 16);
 272     ib->tx_ptr = leptr;
 273     if (ZERO) printk ("TX ptr: %8.8x\n", leptr);
 274 
 275     /* Clear the multicast filter */
 276     ib->filter [0] = 0;
 277     ib->filter [1] = 0;
 278 }
 279 
 280 static int init_restart_lance (struct lance_private *lp)
     /* [previous][next][first][last][top][bottom][index][help] */
 281 {
 282     volatile struct lance_regs *ll = lp->ll;
 283     int i;
 284 
 285     ll->rap = LE_CSR0;
 286     ll->rdp = LE_C0_INIT;
 287 
 288     /* Wait for the lance to complete initialization */
 289     for (i = 0; (i < 100) && !(ll->rdp & (LE_C0_ERR | LE_C0_IDON)); i++)
 290         ;
 291     if ((i == 100) || (ll->rdp & LE_C0_ERR)){
 292         printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, ll->rdp);
 293         return -1;
 294     }
 295 
 296     /* Clear IDON by writing a "1", enable interrupts and start lance */
 297     ll->rdp = LE_C0_IDON;
 298     ll->rdp = LE_C0_INEA | LE_C0_STRT;
 299     printk ("LANCE opened after %d ticks, csr0=%4.4x\n", i, ll->rdp);
 300     return 0;
 301 }
 302 
 303 static int
 304 lance_rx (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 305 {
 306     struct lance_private *lp = (struct lance_private *) dev->priv;
 307     volatile struct lance_init_block *ib = lp->init_block;
 308     volatile struct lance_regs *ll = lp->ll;
 309     volatile struct lance_rx_desc *rd;
 310     int i;
 311     int entry;
 312     unsigned char bits;
 313 
 314 #ifdef TEST_HITS
 315     printk ("[");
 316     for (i = 0; i < RX_RING_SIZE; i++){
 317             if (i == lp->rx_new)
 318                     printk ("%s", ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
 319             else
 320                     printk ("%s", ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
 321     }
 322     printk ("]");
 323 #endif
 324     
 325 #ifdef OLD_METHOD
 326     ll->rdp = LE_C0_RINT|LE_C0_INEA;
 327     /* FIXME: Add slot prediction */
 328     for (rd = &ib->brx_ring [i = 0]; i < RX_RING_SIZE; i++, rd++){
 329         int bits;
 330         
 331         bits = rd->rmd1_bits;
 332 
 333         /* Check if we own the packet */
 334         if (bits & LE_R1_OWN)
 335             continue;
 336 
 337         /* We got an incomplete frame? */
 338         if ((bits & LE_R1_POK) != LE_R1_POK){
 339             /* Count only the end frame as a tx error, not the beginning */
 340             if (bits & LE_R1_EOP) lp->stats.rx_errors++;
 341             if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
 342             if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
 343             if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
 344             if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
 345         } else {
 346             int pkt_len = rd->mblength;
 347             struct sk_buff *skb;
 348             char *buf;
 349             
 350             skb = dev_alloc_skb (pkt_len+2);
 351             if (skb == NULL){
 352                 printk ("%s: Memory squeeze, deferring packet.\n", dev->name);
 353                 lp->stats.rx_dropped++;
 354                 rd->rmd1_bits = LE_R1_OWN;
 355                 return 0;
 356             }
 357             
 358             skb->dev = dev;
 359             skb_reserve (skb, 2);               /* 16 byte align */
 360             buf = skb_put (skb, pkt_len);       /* make room */
 361             memcpy (buf, &(ib->rx_buf [i][0]), pkt_len);
 362             skb->protocol = eth_type_trans (skb,dev);
 363             netif_rx (skb);
 364             lp->stats.rx_packets++;
 365         }
 366 
 367         /* Return the packet to the pool */
 368         rd->rmd1_bits = LE_R1_OWN;
 369     }
 370 #else
 371     ll->rdp = LE_C0_RINT|LE_C0_INEA;
 372     for (rd = &ib->brx_ring [lp->rx_new];
 373          !((bits = rd->rmd1_bits) & LE_R1_OWN);
 374          rd = &ib->brx_ring [lp->rx_new]){
 375 
 376         /* We got an incomplete frame? */
 377         if ((bits & LE_R1_POK) != LE_R1_POK){
 378             printk ("Incomplete frame\n");
 379             /* Count only the end frame as a tx error, not the beginning */
 380             if (bits & LE_R1_EOP) lp->stats.rx_errors++;
 381             if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
 382             if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
 383             if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
 384             if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
 385         } else {
 386             int pkt_len = rd->mblength;
 387             struct sk_buff *skb;
 388             char *buf;
 389 
 390             skb = dev_alloc_skb (pkt_len+2);
 391             if (skb == NULL){
 392                 printk ("%s: Memory squeeze, deferring packet.\n", dev->name);
 393                 lp->stats.rx_dropped++;
 394                 rd->rmd1_bits = LE_R1_OWN;
 395                 lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
 396                 return 0;
 397             }
 398             
 399             skb->dev = dev;
 400             skb_reserve (skb, 2);               /* 16 byte align */
 401             buf = skb_put (skb, pkt_len);       /* make room */
 402             memcpy (buf, (char *) &(ib->rx_buf [lp->rx_new][0]), pkt_len);
 403             skb->protocol = eth_type_trans (skb,dev);
 404             netif_rx (skb);
 405             lp->stats.rx_packets++;
 406         }
 407 
 408         /* Return the packet to the pool */
 409         rd->rmd1_bits = LE_R1_OWN;
 410         lp->rx_new = (lp->rx_new + 1) & RX_RING_MOD_MASK;
 411     }
 412 #endif
 413     return 0;
 414 }
 415 
 416 static int
 417 lance_tx (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 418 {
 419     struct lance_private *lp = (struct lance_private *) dev->priv;
 420     volatile struct lance_init_block *ib = lp->init_block;
 421     volatile struct lance_regs *ll = lp->ll;
 422     volatile struct lance_tx_desc *td;
 423     int i, j;
 424     int status;
 425 
 426     /* csr0 is 2f3 */
 427     ll->rdp = LE_C0_TINT | LE_C0_INEA;
 428     /* csr0 is 73 */
 429     j = lp->tx_old;
 430     for (i = 0; i < TX_RING_SIZE; i++){
 431         td = &ib->btx_ring [j];
 432 
 433         if (td->tmd1_bits & LE_T1_ERR){
 434             status = td->misc;
 435             
 436             if (status & LE_T3_RTY)  lp->stats.tx_aborted_errors++;
 437             if (status & LE_T3_CLOS) lp->stats.tx_carrier_errors++;
 438             if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
 439 
 440             /* buffer errors and underflows turn off the transmiter */
 441             /* Restart the adapter */
 442             if (status & (LE_T3_BUF|LE_T3_UFL)){
 443                 lp->stats.tx_fifo_errors++;
 444 
 445                 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n", dev->name);
 446                 /* Stop the lance */
 447                 ll->rdp = LE_CSR0;
 448                 ll->rap = LE_C0_STOP;
 449                 init_restart_lance (lp);
 450             }
 451         }
 452         
 453         j = (j + 1) & TX_RING_MOD_MASK;
 454     }
 455     lp->tx_old = (lp->tx_old+1) & TX_RING_MOD_MASK;
 456 
 457     ll->rdp = LE_C0_TINT | LE_C0_INEA;
 458     return 0;
 459 }
 460 
 461 static void
 462 lance_interrupt (int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 463 {
 464     struct device *dev = (struct device *) (irq2dev_map [irq]);
 465     struct lance_private *lp;
 466     volatile struct lance_regs *ll;
 467     int csr0;
 468     
 469     lp = (struct lance_private *) dev->priv;
 470     ll = lp->ll;
 471 
 472     if (dev->interrupt)
 473         printk ("%s: again", dev->name);
 474     
 475     dev->interrupt = 1;
 476 
 477     csr0 = ll->rdp;
 478     
 479     /* Acknowledge all the interrupt sources ASAP */
 480     ll->rdp = csr0 & 0x004f;
 481     
 482     if ((csr0 & LE_C0_ERR)){
 483         /* Clear the error condition */
 484         ll->rdp = LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA;
 485     }
 486     
 487     if (csr0 & LE_C0_RINT){
 488         lance_rx (dev);
 489     }
 490     
 491     if (csr0 & LE_C0_TINT){
 492         lance_tx (dev);
 493     }
 494     
 495     if ((TX_BUFFS_AVAIL >= 0) && dev->tbusy){
 496         dev->tbusy = 0;
 497         mark_bh (NET_BH);
 498     }
 499     ll->rap = 0;
 500     ll->rdp = 0x7940;
 501 
 502     dev->interrupt = 0;
 503 }
 504 
 505 struct device *last_dev = 0;
 506 
 507 static int
 508 lance_open (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 509 {
 510     struct lance_private *lp = (struct lance_private *)dev->priv;
 511     volatile struct lance_regs *ll = lp->ll;
 512     int status = 0;
 513 
 514     last_dev = dev;
 515     
 516     /* Stop the Lance */
 517     ll->rap = LE_CSR0;
 518     ll->rdp = LE_C0_STOP;
 519 
 520     if (request_irq (dev->irq, &lance_interrupt, 0, "LANCE")){
 521         printk ("Lance: Can't get irq %d\n", dev->irq);
 522         return -EAGAIN;
 523     }
 524     irq2dev_map [dev->irq] = dev;
 525 
 526     lance_init_ring (dev);
 527     load_csrs (lp);
 528 
 529     dev->tbusy = 0;
 530     dev->interrupt = 0;
 531     dev->start = 1;
 532 
 533     status = init_restart_lance (lp);
 534 
 535     /* To make life easier to us while Sparc Linux becomes self hosting: */
 536     {
 537             struct rtentry server_route;
 538             struct sockaddr_in *sin;
 539             
 540             sin=(struct sockaddr_in *)&server_route.rt_dst;
 541             *sin=server;
 542             sin=(struct sockaddr_in *)&server_route.rt_genmask;
 543             sin->sin_family=AF_INET;
 544             sin->sin_addr.s_addr= ip_get_mask (dev->pa_addr);
 545             server_route.rt_dev[0]=dev;
 546             server_route.
 547             server_route.rt_flags=RTF_HOST|RTF_UP;
 548 
 549             if(ip_rt_new(&server_route)==-1)
 550                     printk("Unable to add NFS server route.\n");
 551     }
 552     ip_rt_add (RTF_UP,
 553                dev->pa_addr & ip_get_mask (dev->pa_addr),
 554                ip_get_mask (dev->pa_addr),
 555                0, dev, dev->mtu, 0, 0);
 556     return status;
 557 }
 558 
 559 static int
 560 lance_close (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 561 {
 562     struct lance_private *lp = (struct lance_private *) dev->priv;
 563     volatile struct lance_regs *ll = lp->ll;
 564 
 565     dev->start = 0;
 566     dev->tbusy = 1;
 567 
 568     /* Stop the card */
 569     ll->rap = LE_CSR0;
 570     ll->rdp = LE_C0_STOP;
 571 
 572     free_irq (dev->irq);
 573     irq2dev_map [dev->irq] = NULL;
 574     
 575     return 0;
 576 }
 577 
 578 inline static int lance_reset (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 579 {
 580     struct lance_private *lp = (struct lance_private *)dev->priv;
 581     volatile struct lance_regs *ll = lp->ll;
 582     int status;
 583     
 584     /* Stop the lance */
 585     ll->rdp = LE_CSR0;
 586     ll->rap = LE_C0_STOP;
 587 #ifdef DEBUG_DRIVER
 588     printk ("Lance stopped: csr0=%4.4x\n", ll->rdp);
 589 #endif
 590     lance_init_ring (dev);
 591     load_csrs (lp);
 592     dev->trans_start = jiffies;
 593     dev->interrupt = 0;
 594     dev->start = 1;
 595     dev->tbusy = 0;
 596     status = init_restart_lance (lp);
 597 #ifdef DEBUG_DRIVER
 598     printk ("Lance restart=%d\n", status);
 599 #endif
 600 }
 601 
 602 static int lance_start_xmit (struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 603 {
 604     struct lance_private *lp = (struct lance_private *)dev->priv;
 605     volatile struct lance_regs *ll = lp->ll;
 606     volatile struct lance_init_block *ib = lp->init_block;
 607     int entry, skblen, len;
 608     int status = 0;
 609     static int outs;
 610 
 611     /* Transmitter timeout, serious problems */
 612     if (dev->tbusy){
 613             int tickssofar = jiffies - dev->trans_start;
 614             
 615             if (tickssofar < 100)
 616                     status = -1;
 617             else {
 618                     printk ("%s: trasmit timed out, status %04x, resetting\n",
 619                             dev->name, ll->rdp);
 620                     lance_reset (dev);
 621             }
 622             return status;
 623     }
 624 
 625     if (skb == NULL){
 626         dev_tint (dev);
 627         printk ("skb is NULL\n");
 628         return 0;
 629     }
 630 
 631     if (skb->len <= 0){
 632         printk ("skb len is %ld\n", skb->len);
 633         return 0;
 634     }
 635     /* Block a timer-based transmit from overlapping. */
 636 #ifdef OLD_METHOD
 637     dev->tbusy = 1;
 638 #else
 639     if (set_bit (0, (void *) &dev->tbusy) != 0){
 640         printk ("Transmitter access conflict.\n");
 641         return -1;
 642     }
 643 #endif
 644     skblen = skb->len;
 645 
 646     if (!TX_BUFFS_AVAIL){
 647         return -1;
 648     }
 649 
 650 #ifdef DEBUG_DRIVER
 651     /* dump the packet */
 652     for (i = 0; i < 64; i++){
 653         if ((i % 16) == 0) printk ("\n");
 654         printk ("%2.2x ", skb->data [i]);
 655     }
 656 #endif
 657     len = (skblen < ETH_ZLEN) ? ETH_ZLEN : skblen;
 658     entry = lp->tx_new & TX_RING_MOD_MASK;
 659     ib->btx_ring [entry].length = (-len) | 0xf000;
 660     ib->btx_ring [entry].misc = 0;
 661     
 662     memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
 663 
 664     /* Clear the slack of the packet, do I need this? */
 665     if (len != skblen){
 666         memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen);
 667     }
 668 
 669     
 670     /* Now, give the packet to the lance */
 671     ib->btx_ring [entry].tmd1_bits = (LE_T1_SOP|LE_T1_EOP|LE_T1_OWN);
 672     lp->tx_new = (lp->tx_new+1) & TX_RING_MOD_MASK;
 673 
 674     outs++;
 675     /* Kick the lance: transmit now */
 676     ll->rdp = LE_C0_INEA | LE_C0_TDMD;
 677     dev->trans_start = jiffies;
 678     dev_kfree_skb (skb, FREE_WRITE);
 679     
 680     if (TX_BUFFS_AVAIL)
 681         dev->tbusy = 0;
 682 
 683     return status;
 684 }
 685 
 686 static struct enet_statistics *
 687 lance_get_stats (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 688 {
 689     struct lance_private *lp = (struct lance_private *) dev->priv;
 690 
 691     return &lp->stats;
 692 }
 693 
 694 static void
 695 lance_set_multicast (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 696 {
 697 #ifdef NOT_YET
 698     struct lance_private *lp = (struct lance_private *) dev->priv;
 699     volatile struct lance_init_block *ib = lp->init_block;
 700     volatile struct lance_regs *ll = lp->ll;
 701 
 702     ll->rdp = LE_CSR0;
 703     ll->rap = LE_C0_STOP;
 704     lance_init_ring (dev);
 705     if (num_addrs >= 0){
 706         printk ("Ignoring set_multicast\n");
 707     } else {
 708         ib->mode |= LE_MO_PROM;
 709     }
 710     lance_init_ring (dev);
 711     load_csrs (lp);
 712     init_restart_lance (lp);
 713     dev->tbusy = 0;
 714 #endif
 715 }
 716 
 717 int sparc_lance_probe (struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 718 {
 719     static unsigned version_printed = 0;
 720     int    i;
 721     int    found = 0;
 722     struct linux_sbus *bus;
 723     struct linux_sbus_device *sdev = 0;
 724     struct lance_private *lp;
 725     volatile struct lance_regs *ll;
 726 
 727 #ifdef DEBUG_DRIVER
 728     printk ("Lance probe...0x%p\n", SBus_chain);
 729 #endif
 730     for_each_sbus (bus){
 731         for_each_sbusdev (sdev, bus){
 732             if (strcmp (sdev->prom_name, "le") == 0){
 733                 found = 1;
 734                 break;
 735             }
 736         }
 737     }
 738     if (!found)
 739         return ENODEV;
 740 
 741     if (dev == NULL){
 742         printk ("LANCE buffer @0x0. You don't really want this\n");
 743         dev = init_etherdev (0, sizeof (struct lance_private));
 744     } else {
 745         dev->priv = kmalloc (sizeof (struct lance_private), GFP_KERNEL);
 746     }
 747     if (sparc_lance_debug && version_printed++ == 0)
 748         printk (version);
 749 
 750     printk ("%s: LANCE ", dev->name);
 751     /* Fill the dev fields */
 752     dev->base_addr = (long) sdev;
 753 
 754     /* Copy the IDPROM ethernet address to the device structure, later we
 755      * will copy the address in the device structure to the lance initialization
 756      * block
 757      */
 758     for (i = 0; i < 6; i++){
 759         printk ("%2.2x%c", dev->dev_addr [i] = idprom->id_eaddr [i], i == 5 ? ' ': ':');
 760     }
 761     /* Get the IO region */
 762     ll = sparc_alloc_io (sdev->reg_addrs [0].phys_addr, 0,
 763                          sizeof (struct lance_regs), "Lance driver", 0x0, 0x0);
 764     
 765     /* Make certain the data structures used by the LANCE are aligned. */
 766     dev->priv = (void *)(((int)dev->priv + 7) & ~7);
 767     lp = (struct lance_private *) dev->priv;
 768     
 769     lp->init_block = (void *)
 770         sparc_dvma_malloc (sizeof (struct lance_init_block), "LANCE");
 771     
 772     lp->ll = ll;
 773     lp->name = "LANCE";
 774 
 775     /* This should never happen. */
 776     if ((int)(lp->init_block->brx_ring) & 0x07) {
 777         printk(" **ERROR** LANCE Rx and Tx rings not on even boundary.\n");
 778         return ENODEV;
 779     }
 780 
 781     dev->open = &lance_open;
 782     dev->stop = &lance_close;
 783     dev->hard_start_xmit = &lance_start_xmit;
 784     dev->get_stats = &lance_get_stats;
 785     dev->set_multicast_list = &lance_set_multicast;
 786     
 787     dev->irq = (unsigned char) sdev->irqs [0].pri;
 788     dev->dma = 0;
 789     ether_setup (dev);
 790     
 791     return 0;
 792 }
 793 /*
 794  * Local variables:
 795  *  compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I../../..//net/tcp -c lance.c"
 796  *  version-control: t
 797  *  kept-new-versions: 5
 798  * End:
 799  */

/* [previous][next][first][last][top][bottom][index][help] */