ia64/linux-2.6.18-xen.hg

annotate drivers/net/7990.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
rev   line source
ian@0 1 /*
ian@0 2 * 7990.c -- LANCE ethernet IC generic routines.
ian@0 3 * This is an attempt to separate out the bits of various ethernet
ian@0 4 * drivers that are common because they all use the AMD 7990 LANCE
ian@0 5 * (Local Area Network Controller for Ethernet) chip.
ian@0 6 *
ian@0 7 * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
ian@0 8 *
ian@0 9 * Most of this stuff was obtained by looking at other LANCE drivers,
ian@0 10 * in particular a2065.[ch]. The AMD C-LANCE datasheet was also helpful.
ian@0 11 * NB: this was made easy by the fact that Jes Sorensen had cleaned up
ian@0 12 * most of a2025 and sunlance with the aim of merging them, so the
ian@0 13 * common code was pretty obvious.
ian@0 14 */
ian@0 15 #include <linux/crc32.h>
ian@0 16 #include <linux/delay.h>
ian@0 17 #include <linux/errno.h>
ian@0 18 #include <linux/netdevice.h>
ian@0 19 #include <linux/etherdevice.h>
ian@0 20 #include <linux/init.h>
ian@0 21 #include <linux/module.h>
ian@0 22 #include <linux/kernel.h>
ian@0 23 #include <linux/types.h>
ian@0 24 #include <linux/fcntl.h>
ian@0 25 #include <linux/interrupt.h>
ian@0 26 #include <linux/ioport.h>
ian@0 27 #include <linux/in.h>
ian@0 28 #include <linux/route.h>
ian@0 29 #include <linux/slab.h>
ian@0 30 #include <linux/string.h>
ian@0 31 #include <linux/skbuff.h>
ian@0 32 #include <asm/irq.h>
ian@0 33 /* Used for the temporal inet entries and routing */
ian@0 34 #include <linux/socket.h>
ian@0 35 #include <linux/bitops.h>
ian@0 36
ian@0 37 #include <asm/system.h>
ian@0 38 #include <asm/io.h>
ian@0 39 #include <asm/dma.h>
ian@0 40 #include <asm/pgtable.h>
ian@0 41 #ifdef CONFIG_HP300
ian@0 42 #include <asm/blinken.h>
ian@0 43 #endif
ian@0 44
ian@0 45 #include "7990.h"
ian@0 46
ian@0 47 #define WRITERAP(lp,x) out_be16(lp->base + LANCE_RAP, (x))
ian@0 48 #define WRITERDP(lp,x) out_be16(lp->base + LANCE_RDP, (x))
ian@0 49 #define READRDP(lp) in_be16(lp->base + LANCE_RDP)
ian@0 50
ian@0 51 #if defined(CONFIG_HPLANCE) || defined(CONFIG_HPLANCE_MODULE)
ian@0 52 #include "hplance.h"
ian@0 53
ian@0 54 #undef WRITERAP
ian@0 55 #undef WRITERDP
ian@0 56 #undef READRDP
ian@0 57
ian@0 58 #if defined(CONFIG_MVME147_NET) || defined(CONFIG_MVME147_NET_MODULE)
ian@0 59
ian@0 60 /* Lossage Factor Nine, Mr Sulu. */
ian@0 61 #define WRITERAP(lp,x) (lp->writerap(lp,x))
ian@0 62 #define WRITERDP(lp,x) (lp->writerdp(lp,x))
ian@0 63 #define READRDP(lp) (lp->readrdp(lp))
ian@0 64
ian@0 65 #else
ian@0 66
ian@0 67 /* These inlines can be used if only CONFIG_HPLANCE is defined */
ian@0 68 static inline void WRITERAP(struct lance_private *lp, __u16 value)
ian@0 69 {
ian@0 70 do {
ian@0 71 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
ian@0 72 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
ian@0 73 }
ian@0 74
ian@0 75 static inline void WRITERDP(struct lance_private *lp, __u16 value)
ian@0 76 {
ian@0 77 do {
ian@0 78 out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
ian@0 79 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
ian@0 80 }
ian@0 81
ian@0 82 static inline __u16 READRDP(struct lance_private *lp)
ian@0 83 {
ian@0 84 __u16 value;
ian@0 85 do {
ian@0 86 value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
ian@0 87 } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
ian@0 88 return value;
ian@0 89 }
ian@0 90
ian@0 91 #endif
ian@0 92 #endif /* CONFIG_HPLANCE || CONFIG_HPLANCE_MODULE */
ian@0 93
ian@0 94 /* debugging output macros, various flavours */
ian@0 95 /* #define TEST_HITS */
ian@0 96 #ifdef UNDEF
ian@0 97 #define PRINT_RINGS() \
ian@0 98 do { \
ian@0 99 int t; \
ian@0 100 for (t=0; t < RX_RING_SIZE; t++) { \
ian@0 101 printk("R%d: @(%02X %04X) len %04X, mblen %04X, bits %02X\n",\
ian@0 102 t, ib->brx_ring[t].rmd1_hadr, ib->brx_ring[t].rmd0,\
ian@0 103 ib->brx_ring[t].length,\
ian@0 104 ib->brx_ring[t].mblength, ib->brx_ring[t].rmd1_bits);\
ian@0 105 }\
ian@0 106 for (t=0; t < TX_RING_SIZE; t++) { \
ian@0 107 printk("T%d: @(%02X %04X) len %04X, misc %04X, bits %02X\n",\
ian@0 108 t, ib->btx_ring[t].tmd1_hadr, ib->btx_ring[t].tmd0,\
ian@0 109 ib->btx_ring[t].length,\
ian@0 110 ib->btx_ring[t].misc, ib->btx_ring[t].tmd1_bits);\
ian@0 111 }\
ian@0 112 } while (0)
ian@0 113 #else
ian@0 114 #define PRINT_RINGS()
ian@0 115 #endif
ian@0 116
ian@0 117 /* Load the CSR registers. The LANCE has to be STOPped when we do this! */
ian@0 118 static void load_csrs (struct lance_private *lp)
ian@0 119 {
ian@0 120 volatile struct lance_init_block *aib = lp->lance_init_block;
ian@0 121 int leptr;
ian@0 122
ian@0 123 leptr = LANCE_ADDR (aib);
ian@0 124
ian@0 125 WRITERAP(lp, LE_CSR1); /* load address of init block */
ian@0 126 WRITERDP(lp, leptr & 0xFFFF);
ian@0 127 WRITERAP(lp, LE_CSR2);
ian@0 128 WRITERDP(lp, leptr >> 16);
ian@0 129 WRITERAP(lp, LE_CSR3);
ian@0 130 WRITERDP(lp, lp->busmaster_regval); /* set byteswap/ALEctrl/byte ctrl */
ian@0 131
ian@0 132 /* Point back to csr0 */
ian@0 133 WRITERAP(lp, LE_CSR0);
ian@0 134 }
ian@0 135
ian@0 136 /* #define to 0 or 1 appropriately */
ian@0 137 #define DEBUG_IRING 0
ian@0 138 /* Set up the Lance Rx and Tx rings and the init block */
ian@0 139 static void lance_init_ring (struct net_device *dev)
ian@0 140 {
ian@0 141 struct lance_private *lp = netdev_priv(dev);
ian@0 142 volatile struct lance_init_block *ib = lp->init_block;
ian@0 143 volatile struct lance_init_block *aib; /* for LANCE_ADDR computations */
ian@0 144 int leptr;
ian@0 145 int i;
ian@0 146
ian@0 147 aib = lp->lance_init_block;
ian@0 148
ian@0 149 lp->rx_new = lp->tx_new = 0;
ian@0 150 lp->rx_old = lp->tx_old = 0;
ian@0 151
ian@0 152 ib->mode = LE_MO_PROM; /* normal, enable Tx & Rx */
ian@0 153
ian@0 154 /* Copy the ethernet address to the lance init block
ian@0 155 * Notice that we do a byteswap if we're big endian.
ian@0 156 * [I think this is the right criterion; at least, sunlance,
ian@0 157 * a2065 and atarilance do the byteswap and lance.c (PC) doesn't.
ian@0 158 * However, the datasheet says that the BSWAP bit doesn't affect
ian@0 159 * the init block, so surely it should be low byte first for
ian@0 160 * everybody? Um.]
ian@0 161 * We could define the ib->physaddr as three 16bit values and
ian@0 162 * use (addr[1] << 8) | addr[0] & co, but this is more efficient.
ian@0 163 */
ian@0 164 #ifdef __BIG_ENDIAN
ian@0 165 ib->phys_addr [0] = dev->dev_addr [1];
ian@0 166 ib->phys_addr [1] = dev->dev_addr [0];
ian@0 167 ib->phys_addr [2] = dev->dev_addr [3];
ian@0 168 ib->phys_addr [3] = dev->dev_addr [2];
ian@0 169 ib->phys_addr [4] = dev->dev_addr [5];
ian@0 170 ib->phys_addr [5] = dev->dev_addr [4];
ian@0 171 #else
ian@0 172 for (i=0; i<6; i++)
ian@0 173 ib->phys_addr[i] = dev->dev_addr[i];
ian@0 174 #endif
ian@0 175
ian@0 176 if (DEBUG_IRING)
ian@0 177 printk ("TX rings:\n");
ian@0 178
ian@0 179 lp->tx_full = 0;
ian@0 180 /* Setup the Tx ring entries */
ian@0 181 for (i = 0; i < (1<<lp->lance_log_tx_bufs); i++) {
ian@0 182 leptr = LANCE_ADDR(&aib->tx_buf[i][0]);
ian@0 183 ib->btx_ring [i].tmd0 = leptr;
ian@0 184 ib->btx_ring [i].tmd1_hadr = leptr >> 16;
ian@0 185 ib->btx_ring [i].tmd1_bits = 0;
ian@0 186 ib->btx_ring [i].length = 0xf000; /* The ones required by tmd2 */
ian@0 187 ib->btx_ring [i].misc = 0;
ian@0 188 if (DEBUG_IRING)
ian@0 189 printk ("%d: 0x%8.8x\n", i, leptr);
ian@0 190 }
ian@0 191
ian@0 192 /* Setup the Rx ring entries */
ian@0 193 if (DEBUG_IRING)
ian@0 194 printk ("RX rings:\n");
ian@0 195 for (i = 0; i < (1<<lp->lance_log_rx_bufs); i++) {
ian@0 196 leptr = LANCE_ADDR(&aib->rx_buf[i][0]);
ian@0 197
ian@0 198 ib->brx_ring [i].rmd0 = leptr;
ian@0 199 ib->brx_ring [i].rmd1_hadr = leptr >> 16;
ian@0 200 ib->brx_ring [i].rmd1_bits = LE_R1_OWN;
ian@0 201 /* 0xf000 == bits that must be one (reserved, presumably) */
ian@0 202 ib->brx_ring [i].length = -RX_BUFF_SIZE | 0xf000;
ian@0 203 ib->brx_ring [i].mblength = 0;
ian@0 204 if (DEBUG_IRING)
ian@0 205 printk ("%d: 0x%8.8x\n", i, leptr);
ian@0 206 }
ian@0 207
ian@0 208 /* Setup the initialization block */
ian@0 209
ian@0 210 /* Setup rx descriptor pointer */
ian@0 211 leptr = LANCE_ADDR(&aib->brx_ring);
ian@0 212 ib->rx_len = (lp->lance_log_rx_bufs << 13) | (leptr >> 16);
ian@0 213 ib->rx_ptr = leptr;
ian@0 214 if (DEBUG_IRING)
ian@0 215 printk ("RX ptr: %8.8x\n", leptr);
ian@0 216
ian@0 217 /* Setup tx descriptor pointer */
ian@0 218 leptr = LANCE_ADDR(&aib->btx_ring);
ian@0 219 ib->tx_len = (lp->lance_log_tx_bufs << 13) | (leptr >> 16);
ian@0 220 ib->tx_ptr = leptr;
ian@0 221 if (DEBUG_IRING)
ian@0 222 printk ("TX ptr: %8.8x\n", leptr);
ian@0 223
ian@0 224 /* Clear the multicast filter */
ian@0 225 ib->filter [0] = 0;
ian@0 226 ib->filter [1] = 0;
ian@0 227 PRINT_RINGS();
ian@0 228 }
ian@0 229
ian@0 230 /* LANCE must be STOPped before we do this, too... */
ian@0 231 static int init_restart_lance (struct lance_private *lp)
ian@0 232 {
ian@0 233 int i;
ian@0 234
ian@0 235 WRITERAP(lp, LE_CSR0);
ian@0 236 WRITERDP(lp, LE_C0_INIT);
ian@0 237
ian@0 238 /* Need a hook here for sunlance ledma stuff */
ian@0 239
ian@0 240 /* Wait for the lance to complete initialization */
ian@0 241 for (i = 0; (i < 100) && !(READRDP(lp) & (LE_C0_ERR | LE_C0_IDON)); i++)
ian@0 242 barrier();
ian@0 243 if ((i == 100) || (READRDP(lp) & LE_C0_ERR)) {
ian@0 244 printk ("LANCE unopened after %d ticks, csr0=%4.4x.\n", i, READRDP(lp));
ian@0 245 return -1;
ian@0 246 }
ian@0 247
ian@0 248 /* Clear IDON by writing a "1", enable interrupts and start lance */
ian@0 249 WRITERDP(lp, LE_C0_IDON);
ian@0 250 WRITERDP(lp, LE_C0_INEA | LE_C0_STRT);
ian@0 251
ian@0 252 return 0;
ian@0 253 }
ian@0 254
ian@0 255 static int lance_reset (struct net_device *dev)
ian@0 256 {
ian@0 257 struct lance_private *lp = netdev_priv(dev);
ian@0 258 int status;
ian@0 259
ian@0 260 /* Stop the lance */
ian@0 261 WRITERAP(lp, LE_CSR0);
ian@0 262 WRITERDP(lp, LE_C0_STOP);
ian@0 263
ian@0 264 load_csrs (lp);
ian@0 265 lance_init_ring (dev);
ian@0 266 dev->trans_start = jiffies;
ian@0 267 status = init_restart_lance (lp);
ian@0 268 #ifdef DEBUG_DRIVER
ian@0 269 printk ("Lance restart=%d\n", status);
ian@0 270 #endif
ian@0 271 return status;
ian@0 272 }
ian@0 273
ian@0 274 static int lance_rx (struct net_device *dev)
ian@0 275 {
ian@0 276 struct lance_private *lp = netdev_priv(dev);
ian@0 277 volatile struct lance_init_block *ib = lp->init_block;
ian@0 278 volatile struct lance_rx_desc *rd;
ian@0 279 unsigned char bits;
ian@0 280 int len = 0; /* XXX shut up gcc warnings */
ian@0 281 struct sk_buff *skb = 0; /* XXX shut up gcc warnings */
ian@0 282 #ifdef TEST_HITS
ian@0 283 int i;
ian@0 284 #endif
ian@0 285
ian@0 286 #ifdef TEST_HITS
ian@0 287 printk ("[");
ian@0 288 for (i = 0; i < RX_RING_SIZE; i++) {
ian@0 289 if (i == lp->rx_new)
ian@0 290 printk ("%s",
ian@0 291 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "_" : "X");
ian@0 292 else
ian@0 293 printk ("%s",
ian@0 294 ib->brx_ring [i].rmd1_bits & LE_R1_OWN ? "." : "1");
ian@0 295 }
ian@0 296 printk ("]");
ian@0 297 #endif
ian@0 298 #ifdef CONFIG_HP300
ian@0 299 blinken_leds(0x40, 0);
ian@0 300 #endif
ian@0 301 WRITERDP(lp, LE_C0_RINT | LE_C0_INEA); /* ack Rx int, reenable ints */
ian@0 302 for (rd = &ib->brx_ring [lp->rx_new]; /* For each Rx ring we own... */
ian@0 303 !((bits = rd->rmd1_bits) & LE_R1_OWN);
ian@0 304 rd = &ib->brx_ring [lp->rx_new]) {
ian@0 305
ian@0 306 /* We got an incomplete frame? */
ian@0 307 if ((bits & LE_R1_POK) != LE_R1_POK) {
ian@0 308 lp->stats.rx_over_errors++;
ian@0 309 lp->stats.rx_errors++;
ian@0 310 continue;
ian@0 311 } else if (bits & LE_R1_ERR) {
ian@0 312 /* Count only the end frame as a rx error,
ian@0 313 * not the beginning
ian@0 314 */
ian@0 315 if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
ian@0 316 if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
ian@0 317 if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
ian@0 318 if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
ian@0 319 if (bits & LE_R1_EOP) lp->stats.rx_errors++;
ian@0 320 } else {
ian@0 321 len = (rd->mblength & 0xfff) - 4;
ian@0 322 skb = dev_alloc_skb (len+2);
ian@0 323
ian@0 324 if (skb == 0) {
ian@0 325 printk ("%s: Memory squeeze, deferring packet.\n",
ian@0 326 dev->name);
ian@0 327 lp->stats.rx_dropped++;
ian@0 328 rd->mblength = 0;
ian@0 329 rd->rmd1_bits = LE_R1_OWN;
ian@0 330 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
ian@0 331 return 0;
ian@0 332 }
ian@0 333
ian@0 334 skb->dev = dev;
ian@0 335 skb_reserve (skb, 2); /* 16 byte align */
ian@0 336 skb_put (skb, len); /* make room */
ian@0 337 eth_copy_and_sum(skb,
ian@0 338 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
ian@0 339 len, 0);
ian@0 340 skb->protocol = eth_type_trans (skb, dev);
ian@0 341 netif_rx (skb);
ian@0 342 dev->last_rx = jiffies;
ian@0 343 lp->stats.rx_packets++;
ian@0 344 lp->stats.rx_bytes += len;
ian@0 345 }
ian@0 346
ian@0 347 /* Return the packet to the pool */
ian@0 348 rd->mblength = 0;
ian@0 349 rd->rmd1_bits = LE_R1_OWN;
ian@0 350 lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
ian@0 351 }
ian@0 352 return 0;
ian@0 353 }
ian@0 354
ian@0 355 static int lance_tx (struct net_device *dev)
ian@0 356 {
ian@0 357 struct lance_private *lp = netdev_priv(dev);
ian@0 358 volatile struct lance_init_block *ib = lp->init_block;
ian@0 359 volatile struct lance_tx_desc *td;
ian@0 360 int i, j;
ian@0 361 int status;
ian@0 362
ian@0 363 #ifdef CONFIG_HP300
ian@0 364 blinken_leds(0x80, 0);
ian@0 365 #endif
ian@0 366 /* csr0 is 2f3 */
ian@0 367 WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
ian@0 368 /* csr0 is 73 */
ian@0 369
ian@0 370 j = lp->tx_old;
ian@0 371 for (i = j; i != lp->tx_new; i = j) {
ian@0 372 td = &ib->btx_ring [i];
ian@0 373
ian@0 374 /* If we hit a packet not owned by us, stop */
ian@0 375 if (td->tmd1_bits & LE_T1_OWN)
ian@0 376 break;
ian@0 377
ian@0 378 if (td->tmd1_bits & LE_T1_ERR) {
ian@0 379 status = td->misc;
ian@0 380
ian@0 381 lp->stats.tx_errors++;
ian@0 382 if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
ian@0 383 if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
ian@0 384
ian@0 385 if (status & LE_T3_CLOS) {
ian@0 386 lp->stats.tx_carrier_errors++;
ian@0 387 if (lp->auto_select) {
ian@0 388 lp->tpe = 1 - lp->tpe;
ian@0 389 printk("%s: Carrier Lost, trying %s\n",
ian@0 390 dev->name, lp->tpe?"TPE":"AUI");
ian@0 391 /* Stop the lance */
ian@0 392 WRITERAP(lp, LE_CSR0);
ian@0 393 WRITERDP(lp, LE_C0_STOP);
ian@0 394 lance_init_ring (dev);
ian@0 395 load_csrs (lp);
ian@0 396 init_restart_lance (lp);
ian@0 397 return 0;
ian@0 398 }
ian@0 399 }
ian@0 400
ian@0 401 /* buffer errors and underflows turn off the transmitter */
ian@0 402 /* Restart the adapter */
ian@0 403 if (status & (LE_T3_BUF|LE_T3_UFL)) {
ian@0 404 lp->stats.tx_fifo_errors++;
ian@0 405
ian@0 406 printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
ian@0 407 dev->name);
ian@0 408 /* Stop the lance */
ian@0 409 WRITERAP(lp, LE_CSR0);
ian@0 410 WRITERDP(lp, LE_C0_STOP);
ian@0 411 lance_init_ring (dev);
ian@0 412 load_csrs (lp);
ian@0 413 init_restart_lance (lp);
ian@0 414 return 0;
ian@0 415 }
ian@0 416 } else if ((td->tmd1_bits & LE_T1_POK) == LE_T1_POK) {
ian@0 417 /*
ian@0 418 * So we don't count the packet more than once.
ian@0 419 */
ian@0 420 td->tmd1_bits &= ~(LE_T1_POK);
ian@0 421
ian@0 422 /* One collision before packet was sent. */
ian@0 423 if (td->tmd1_bits & LE_T1_EONE)
ian@0 424 lp->stats.collisions++;
ian@0 425
ian@0 426 /* More than one collision, be optimistic. */
ian@0 427 if (td->tmd1_bits & LE_T1_EMORE)
ian@0 428 lp->stats.collisions += 2;
ian@0 429
ian@0 430 lp->stats.tx_packets++;
ian@0 431 }
ian@0 432
ian@0 433 j = (j + 1) & lp->tx_ring_mod_mask;
ian@0 434 }
ian@0 435 lp->tx_old = j;
ian@0 436 WRITERDP(lp, LE_C0_TINT | LE_C0_INEA);
ian@0 437 return 0;
ian@0 438 }
ian@0 439
ian@0 440 static irqreturn_t
ian@0 441 lance_interrupt (int irq, void *dev_id, struct pt_regs *regs)
ian@0 442 {
ian@0 443 struct net_device *dev = (struct net_device *)dev_id;
ian@0 444 struct lance_private *lp = netdev_priv(dev);
ian@0 445 int csr0;
ian@0 446
ian@0 447 spin_lock (&lp->devlock);
ian@0 448
ian@0 449 WRITERAP(lp, LE_CSR0); /* LANCE Controller Status */
ian@0 450 csr0 = READRDP(lp);
ian@0 451
ian@0 452 PRINT_RINGS();
ian@0 453
ian@0 454 if (!(csr0 & LE_C0_INTR)) { /* Check if any interrupt has */
ian@0 455 spin_unlock (&lp->devlock);
ian@0 456 return IRQ_NONE; /* been generated by the Lance. */
ian@0 457 }
ian@0 458
ian@0 459 /* Acknowledge all the interrupt sources ASAP */
ian@0 460 WRITERDP(lp, csr0 & ~(LE_C0_INEA|LE_C0_TDMD|LE_C0_STOP|LE_C0_STRT|LE_C0_INIT));
ian@0 461
ian@0 462 if ((csr0 & LE_C0_ERR)) {
ian@0 463 /* Clear the error condition */
ian@0 464 WRITERDP(lp, LE_C0_BABL|LE_C0_ERR|LE_C0_MISS|LE_C0_INEA);
ian@0 465 }
ian@0 466
ian@0 467 if (csr0 & LE_C0_RINT)
ian@0 468 lance_rx (dev);
ian@0 469
ian@0 470 if (csr0 & LE_C0_TINT)
ian@0 471 lance_tx (dev);
ian@0 472
ian@0 473 /* Log misc errors. */
ian@0 474 if (csr0 & LE_C0_BABL)
ian@0 475 lp->stats.tx_errors++; /* Tx babble. */
ian@0 476 if (csr0 & LE_C0_MISS)
ian@0 477 lp->stats.rx_errors++; /* Missed a Rx frame. */
ian@0 478 if (csr0 & LE_C0_MERR) {
ian@0 479 printk("%s: Bus master arbitration failure, status %4.4x.\n",
ian@0 480 dev->name, csr0);
ian@0 481 /* Restart the chip. */
ian@0 482 WRITERDP(lp, LE_C0_STRT);
ian@0 483 }
ian@0 484
ian@0 485 if (lp->tx_full && netif_queue_stopped(dev) && (TX_BUFFS_AVAIL >= 0)) {
ian@0 486 lp->tx_full = 0;
ian@0 487 netif_wake_queue (dev);
ian@0 488 }
ian@0 489
ian@0 490 WRITERAP(lp, LE_CSR0);
ian@0 491 WRITERDP(lp, LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_MERR|LE_C0_IDON|LE_C0_INEA);
ian@0 492
ian@0 493 spin_unlock (&lp->devlock);
ian@0 494 return IRQ_HANDLED;
ian@0 495 }
ian@0 496
ian@0 497 int lance_open (struct net_device *dev)
ian@0 498 {
ian@0 499 struct lance_private *lp = netdev_priv(dev);
ian@0 500 int res;
ian@0 501
ian@0 502 /* Install the Interrupt handler. Or we could shunt this out to specific drivers? */
ian@0 503 if (request_irq(lp->irq, lance_interrupt, 0, lp->name, dev))
ian@0 504 return -EAGAIN;
ian@0 505
ian@0 506 res = lance_reset(dev);
ian@0 507 spin_lock_init(&lp->devlock);
ian@0 508 netif_start_queue (dev);
ian@0 509
ian@0 510 return res;
ian@0 511 }
ian@0 512
ian@0 513 int lance_close (struct net_device *dev)
ian@0 514 {
ian@0 515 struct lance_private *lp = netdev_priv(dev);
ian@0 516
ian@0 517 netif_stop_queue (dev);
ian@0 518
ian@0 519 /* Stop the LANCE */
ian@0 520 WRITERAP(lp, LE_CSR0);
ian@0 521 WRITERDP(lp, LE_C0_STOP);
ian@0 522
ian@0 523 free_irq(lp->irq, dev);
ian@0 524
ian@0 525 return 0;
ian@0 526 }
ian@0 527
ian@0 528 void lance_tx_timeout(struct net_device *dev)
ian@0 529 {
ian@0 530 printk("lance_tx_timeout\n");
ian@0 531 lance_reset(dev);
ian@0 532 dev->trans_start = jiffies;
ian@0 533 netif_wake_queue (dev);
ian@0 534 }
ian@0 535
ian@0 536
ian@0 537 int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
ian@0 538 {
ian@0 539 struct lance_private *lp = netdev_priv(dev);
ian@0 540 volatile struct lance_init_block *ib = lp->init_block;
ian@0 541 int entry, skblen, len;
ian@0 542 static int outs;
ian@0 543 unsigned long flags;
ian@0 544
ian@0 545 if (!TX_BUFFS_AVAIL)
ian@0 546 return -1;
ian@0 547
ian@0 548 netif_stop_queue (dev);
ian@0 549
ian@0 550 skblen = skb->len;
ian@0 551
ian@0 552 #ifdef DEBUG_DRIVER
ian@0 553 /* dump the packet */
ian@0 554 {
ian@0 555 int i;
ian@0 556
ian@0 557 for (i = 0; i < 64; i++) {
ian@0 558 if ((i % 16) == 0)
ian@0 559 printk ("\n");
ian@0 560 printk ("%2.2x ", skb->data [i]);
ian@0 561 }
ian@0 562 }
ian@0 563 #endif
ian@0 564 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
ian@0 565 entry = lp->tx_new & lp->tx_ring_mod_mask;
ian@0 566 ib->btx_ring [entry].length = (-len) | 0xf000;
ian@0 567 ib->btx_ring [entry].misc = 0;
ian@0 568
ian@0 569 if (skb->len < ETH_ZLEN)
ian@0 570 memset((char *)&ib->tx_buf[entry][0], 0, ETH_ZLEN);
ian@0 571 memcpy ((char *)&ib->tx_buf [entry][0], skb->data, skblen);
ian@0 572
ian@0 573 /* Now, give the packet to the lance */
ian@0 574 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
ian@0 575 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
ian@0 576
ian@0 577 outs++;
ian@0 578 /* Kick the lance: transmit now */
ian@0 579 WRITERDP(lp, LE_C0_INEA | LE_C0_TDMD);
ian@0 580 dev->trans_start = jiffies;
ian@0 581 dev_kfree_skb (skb);
ian@0 582
ian@0 583 spin_lock_irqsave (&lp->devlock, flags);
ian@0 584 if (TX_BUFFS_AVAIL)
ian@0 585 netif_start_queue (dev);
ian@0 586 else
ian@0 587 lp->tx_full = 1;
ian@0 588 spin_unlock_irqrestore (&lp->devlock, flags);
ian@0 589
ian@0 590 return 0;
ian@0 591 }
ian@0 592
ian@0 593 struct net_device_stats *lance_get_stats (struct net_device *dev)
ian@0 594 {
ian@0 595 struct lance_private *lp = netdev_priv(dev);
ian@0 596
ian@0 597 return &lp->stats;
ian@0 598 }
ian@0 599
ian@0 600 /* taken from the depca driver via a2065.c */
ian@0 601 static void lance_load_multicast (struct net_device *dev)
ian@0 602 {
ian@0 603 struct lance_private *lp = netdev_priv(dev);
ian@0 604 volatile struct lance_init_block *ib = lp->init_block;
ian@0 605 volatile u16 *mcast_table = (u16 *)&ib->filter;
ian@0 606 struct dev_mc_list *dmi=dev->mc_list;
ian@0 607 char *addrs;
ian@0 608 int i;
ian@0 609 u32 crc;
ian@0 610
ian@0 611 /* set all multicast bits */
ian@0 612 if (dev->flags & IFF_ALLMULTI){
ian@0 613 ib->filter [0] = 0xffffffff;
ian@0 614 ib->filter [1] = 0xffffffff;
ian@0 615 return;
ian@0 616 }
ian@0 617 /* clear the multicast filter */
ian@0 618 ib->filter [0] = 0;
ian@0 619 ib->filter [1] = 0;
ian@0 620
ian@0 621 /* Add addresses */
ian@0 622 for (i = 0; i < dev->mc_count; i++){
ian@0 623 addrs = dmi->dmi_addr;
ian@0 624 dmi = dmi->next;
ian@0 625
ian@0 626 /* multicast address? */
ian@0 627 if (!(*addrs & 1))
ian@0 628 continue;
ian@0 629
ian@0 630 crc = ether_crc_le(6, addrs);
ian@0 631 crc = crc >> 26;
ian@0 632 mcast_table [crc >> 4] |= 1 << (crc & 0xf);
ian@0 633 }
ian@0 634 return;
ian@0 635 }
ian@0 636
ian@0 637
ian@0 638 void lance_set_multicast (struct net_device *dev)
ian@0 639 {
ian@0 640 struct lance_private *lp = netdev_priv(dev);
ian@0 641 volatile struct lance_init_block *ib = lp->init_block;
ian@0 642 int stopped;
ian@0 643
ian@0 644 stopped = netif_queue_stopped(dev);
ian@0 645 if (!stopped)
ian@0 646 netif_stop_queue (dev);
ian@0 647
ian@0 648 while (lp->tx_old != lp->tx_new)
ian@0 649 schedule();
ian@0 650
ian@0 651 WRITERAP(lp, LE_CSR0);
ian@0 652 WRITERDP(lp, LE_C0_STOP);
ian@0 653 lance_init_ring (dev);
ian@0 654
ian@0 655 if (dev->flags & IFF_PROMISC) {
ian@0 656 ib->mode |= LE_MO_PROM;
ian@0 657 } else {
ian@0 658 ib->mode &= ~LE_MO_PROM;
ian@0 659 lance_load_multicast (dev);
ian@0 660 }
ian@0 661 load_csrs (lp);
ian@0 662 init_restart_lance (lp);
ian@0 663
ian@0 664 if (!stopped)
ian@0 665 netif_start_queue (dev);
ian@0 666 }
ian@0 667
ian@0 668 #ifdef CONFIG_NET_POLL_CONTROLLER
ian@0 669 void lance_poll(struct net_device *dev)
ian@0 670 {
ian@0 671 struct lance_private *lp = netdev_priv(dev);
ian@0 672
ian@0 673 spin_lock (&lp->devlock);
ian@0 674 WRITERAP(lp, LE_CSR0);
ian@0 675 WRITERDP(lp, LE_C0_STRT);
ian@0 676 spin_unlock (&lp->devlock);
ian@0 677 lance_interrupt(dev->irq, dev, NULL);
ian@0 678 }
ian@0 679 #endif
ian@0 680
ian@0 681 MODULE_LICENSE("GPL");