ia64/linux-2.6.18-xen.hg

annotate drivers/net/znet.c @ 912:dd42cdb0ab89

[IA64] Build blktap2 driver by default in x86 builds.

add CONFIG_XEN_BLKDEV_TAP2=y to buildconfigs/linux-defconfig_xen_ia64.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 12:09:16 2009 +0900 (2009-06-29)
parents 831230e53067
children
rev   line source
ian@0 1 /* znet.c: An Zenith Z-Note ethernet driver for linux. */
ian@0 2
ian@0 3 /*
ian@0 4 Written by Donald Becker.
ian@0 5
ian@0 6 The author may be reached as becker@scyld.com.
ian@0 7 This driver is based on the Linux skeleton driver. The copyright of the
ian@0 8 skeleton driver is held by the United States Government, as represented
ian@0 9 by DIRNSA, and it is released under the GPL.
ian@0 10
ian@0 11 Thanks to Mike Hollick for alpha testing and suggestions.
ian@0 12
ian@0 13 References:
ian@0 14 The Crynwr packet driver.
ian@0 15
ian@0 16 "82593 CSMA/CD Core LAN Controller" Intel datasheet, 1992
ian@0 17 Intel Microcommunications Databook, Vol. 1, 1990.
ian@0 18 As usual with Intel, the documentation is incomplete and inaccurate.
ian@0 19 I had to read the Crynwr packet driver to figure out how to actually
ian@0 20 use the i82593, and guess at what register bits matched the loosely
ian@0 21 related i82586.
ian@0 22
ian@0 23 Theory of Operation
ian@0 24
ian@0 25 The i82593 used in the Zenith Z-Note series operates using two(!) slave
ian@0 26 DMA channels, one interrupt, and one 8-bit I/O port.
ian@0 27
ian@0 28 While there several ways to configure '593 DMA system, I chose the one
ian@0 29 that seemed commensurate with the highest system performance in the face
ian@0 30 of moderate interrupt latency: Both DMA channels are configured as
ian@0 31 recirculating ring buffers, with one channel (#0) dedicated to Rx and
ian@0 32 the other channel (#1) to Tx and configuration. (Note that this is
ian@0 33 different than the Crynwr driver, where the Tx DMA channel is initialized
ian@0 34 before each operation. That approach simplifies operation and Tx error
ian@0 35 recovery, but requires additional I/O in normal operation and precludes
ian@0 36 transmit buffer chaining.)
ian@0 37
ian@0 38 Both rings are set to 8192 bytes using {TX,RX}_RING_SIZE. This provides
ian@0 39 a reasonable ring size for Rx, while simplifying DMA buffer allocation --
ian@0 40 DMA buffers must not cross a 128K boundary. (In truth the size selection
ian@0 41 was influenced by my lack of '593 documentation. I thus was constrained
ian@0 42 to use the Crynwr '593 initialization table, which sets the Rx ring size
ian@0 43 to 8K.)
ian@0 44
ian@0 45 Despite my usual low opinion about Intel-designed parts, I must admit
ian@0 46 that the bulk data handling of the i82593 is a good design for
ian@0 47 an integrated system, like a laptop, where using two slave DMA channels
ian@0 48 doesn't pose a problem. I still take issue with using only a single I/O
ian@0 49 port. In the same controlled environment there are essentially no
ian@0 50 limitations on I/O space, and using multiple locations would eliminate
ian@0 51 the need for multiple operations when looking at status registers,
ian@0 52 setting the Rx ring boundary, or switching to promiscuous mode.
ian@0 53
ian@0 54 I also question Zenith's selection of the '593: one of the advertised
ian@0 55 advantages of earlier Intel parts was that if you figured out the magic
ian@0 56 initialization incantation you could use the same part on many different
ian@0 57 network types. Zenith's use of the "FriendlyNet" (sic) connector rather
ian@0 58 than an on-board transceiver leads me to believe that they were planning
ian@0 59 to take advantage of this. But, uhmmm, the '593 omits all but ethernet
ian@0 60 functionality from the serial subsystem.
ian@0 61 */
ian@0 62
ian@0 63 /* 10/2002
ian@0 64
ian@0 65 o Resurected for Linux 2.5+ by Marc Zyngier <maz@wild-wind.fr.eu.org> :
ian@0 66
ian@0 67 - Removed strange DMA snooping in znet_sent_packet, which lead to
ian@0 68 TX buffer corruption on my laptop.
ian@0 69 - Use init_etherdev stuff.
ian@0 70 - Use kmalloc-ed DMA buffers.
ian@0 71 - Use as few global variables as possible.
ian@0 72 - Use proper resources management.
ian@0 73 - Use wireless/i82593.h as much as possible (structure, constants)
ian@0 74 - Compiles as module or build-in.
ian@0 75 - Now survives unplugging/replugging cable.
ian@0 76
ian@0 77 Some code was taken from wavelan_cs.
ian@0 78
ian@0 79 Tested on a vintage Zenith Z-Note 433Lnp+. Probably broken on
ian@0 80 anything else. Testers (and detailed bug reports) are welcome :-).
ian@0 81
ian@0 82 o TODO :
ian@0 83
ian@0 84 - Properly handle multicast
ian@0 85 - Understand why some traffic patterns add a 1s latency...
ian@0 86 */
ian@0 87
ian@0 88 #include <linux/module.h>
ian@0 89 #include <linux/kernel.h>
ian@0 90 #include <linux/string.h>
ian@0 91 #include <linux/errno.h>
ian@0 92 #include <linux/interrupt.h>
ian@0 93 #include <linux/ioport.h>
ian@0 94 #include <linux/init.h>
ian@0 95 #include <linux/delay.h>
ian@0 96 #include <linux/netdevice.h>
ian@0 97 #include <linux/etherdevice.h>
ian@0 98 #include <linux/skbuff.h>
ian@0 99 #include <linux/if_arp.h>
ian@0 100 #include <linux/bitops.h>
ian@0 101
ian@0 102 #include <asm/system.h>
ian@0 103 #include <asm/io.h>
ian@0 104 #include <asm/dma.h>
ian@0 105
ian@0 106 /* This include could be elsewhere, since it is not wireless specific */
ian@0 107 #include "wireless/i82593.h"
ian@0 108
ian@0 109 static char version[] __initdata = "znet.c:v1.02 9/23/94 becker@scyld.com\n";
ian@0 110
ian@0 111 #ifndef ZNET_DEBUG
ian@0 112 #define ZNET_DEBUG 1
ian@0 113 #endif
ian@0 114 static unsigned int znet_debug = ZNET_DEBUG;
ian@0 115 module_param (znet_debug, int, 0);
ian@0 116 MODULE_PARM_DESC (znet_debug, "ZNet debug level");
ian@0 117 MODULE_LICENSE("GPL");
ian@0 118
ian@0 119 /* The DMA modes we need aren't in <dma.h>. */
ian@0 120 #define DMA_RX_MODE 0x14 /* Auto init, I/O to mem, ++, demand. */
ian@0 121 #define DMA_TX_MODE 0x18 /* Auto init, Mem to I/O, ++, demand. */
ian@0 122 #define dma_page_eq(ptr1, ptr2) ((long)(ptr1)>>17 == (long)(ptr2)>>17)
ian@0 123 #define RX_BUF_SIZE 8192
ian@0 124 #define TX_BUF_SIZE 8192
ian@0 125 #define DMA_BUF_SIZE (RX_BUF_SIZE + 16) /* 8k + 16 bytes for trailers */
ian@0 126
ian@0 127 #define TX_TIMEOUT 10
ian@0 128
ian@0 129 struct znet_private {
ian@0 130 int rx_dma, tx_dma;
ian@0 131 struct net_device_stats stats;
ian@0 132 spinlock_t lock;
ian@0 133 short sia_base, sia_size, io_size;
ian@0 134 struct i82593_conf_block i593_init;
ian@0 135 /* The starting, current, and end pointers for the packet buffers. */
ian@0 136 ushort *rx_start, *rx_cur, *rx_end;
ian@0 137 ushort *tx_start, *tx_cur, *tx_end;
ian@0 138 ushort tx_buf_len; /* Tx buffer length, in words. */
ian@0 139 };
ian@0 140
ian@0 141 /* Only one can be built-in;-> */
ian@0 142 static struct net_device *znet_dev;
ian@0 143
ian@0 144 struct netidblk {
ian@0 145 char magic[8]; /* The magic number (string) "NETIDBLK" */
ian@0 146 unsigned char netid[8]; /* The physical station address */
ian@0 147 char nettype, globalopt;
ian@0 148 char vendor[8]; /* The machine vendor and product name. */
ian@0 149 char product[8];
ian@0 150 char irq1, irq2; /* Interrupts, only one is currently used. */
ian@0 151 char dma1, dma2;
ian@0 152 short dma_mem_misc[8]; /* DMA buffer locations (unused in Linux). */
ian@0 153 short iobase1, iosize1;
ian@0 154 short iobase2, iosize2; /* Second iobase unused. */
ian@0 155 char driver_options; /* Misc. bits */
ian@0 156 char pad;
ian@0 157 };
ian@0 158
ian@0 159 static int znet_open(struct net_device *dev);
ian@0 160 static int znet_send_packet(struct sk_buff *skb, struct net_device *dev);
ian@0 161 static irqreturn_t znet_interrupt(int irq, void *dev_id, struct pt_regs *regs);
ian@0 162 static void znet_rx(struct net_device *dev);
ian@0 163 static int znet_close(struct net_device *dev);
ian@0 164 static struct net_device_stats *net_get_stats(struct net_device *dev);
ian@0 165 static void hardware_init(struct net_device *dev);
ian@0 166 static void update_stop_hit(short ioaddr, unsigned short rx_stop_offset);
ian@0 167 static void znet_tx_timeout (struct net_device *dev);
ian@0 168
ian@0 169 /* Request needed resources */
ian@0 170 static int znet_request_resources (struct net_device *dev)
ian@0 171 {
ian@0 172 struct znet_private *znet = dev->priv;
ian@0 173 unsigned long flags;
ian@0 174
ian@0 175 if (request_irq (dev->irq, &znet_interrupt, 0, "ZNet", dev))
ian@0 176 goto failed;
ian@0 177 if (request_dma (znet->rx_dma, "ZNet rx"))
ian@0 178 goto free_irq;
ian@0 179 if (request_dma (znet->tx_dma, "ZNet tx"))
ian@0 180 goto free_rx_dma;
ian@0 181 if (!request_region (znet->sia_base, znet->sia_size, "ZNet SIA"))
ian@0 182 goto free_tx_dma;
ian@0 183 if (!request_region (dev->base_addr, znet->io_size, "ZNet I/O"))
ian@0 184 goto free_sia;
ian@0 185
ian@0 186 return 0; /* Happy ! */
ian@0 187
ian@0 188 free_sia:
ian@0 189 release_region (znet->sia_base, znet->sia_size);
ian@0 190 free_tx_dma:
ian@0 191 flags = claim_dma_lock();
ian@0 192 free_dma (znet->tx_dma);
ian@0 193 release_dma_lock (flags);
ian@0 194 free_rx_dma:
ian@0 195 flags = claim_dma_lock();
ian@0 196 free_dma (znet->rx_dma);
ian@0 197 release_dma_lock (flags);
ian@0 198 free_irq:
ian@0 199 free_irq (dev->irq, dev);
ian@0 200 failed:
ian@0 201 return -1;
ian@0 202 }
ian@0 203
ian@0 204 static void znet_release_resources (struct net_device *dev)
ian@0 205 {
ian@0 206 struct znet_private *znet = dev->priv;
ian@0 207 unsigned long flags;
ian@0 208
ian@0 209 release_region (znet->sia_base, znet->sia_size);
ian@0 210 release_region (dev->base_addr, znet->io_size);
ian@0 211 flags = claim_dma_lock();
ian@0 212 free_dma (znet->tx_dma);
ian@0 213 free_dma (znet->rx_dma);
ian@0 214 release_dma_lock (flags);
ian@0 215 free_irq (dev->irq, dev);
ian@0 216 }
ian@0 217
ian@0 218 /* Keep the magical SIA stuff in a single function... */
ian@0 219 static void znet_transceiver_power (struct net_device *dev, int on)
ian@0 220 {
ian@0 221 struct znet_private *znet = dev->priv;
ian@0 222 unsigned char v;
ian@0 223
ian@0 224 /* Turn on/off the 82501 SIA, using zenith-specific magic. */
ian@0 225 /* Select LAN control register */
ian@0 226 outb(0x10, znet->sia_base);
ian@0 227
ian@0 228 if (on)
ian@0 229 v = inb(znet->sia_base + 1) | 0x84;
ian@0 230 else
ian@0 231 v = inb(znet->sia_base + 1) & ~0x84;
ian@0 232
ian@0 233 outb(v, znet->sia_base+1); /* Turn on/off LAN power (bit 2). */
ian@0 234 }
ian@0 235
ian@0 236 /* Init the i82593, with current promisc/mcast configuration.
ian@0 237 Also used from hardware_init. */
ian@0 238 static void znet_set_multicast_list (struct net_device *dev)
ian@0 239 {
ian@0 240 struct znet_private *znet = dev->priv;
ian@0 241 short ioaddr = dev->base_addr;
ian@0 242 struct i82593_conf_block *cfblk = &znet->i593_init;
ian@0 243
ian@0 244 memset(cfblk, 0x00, sizeof(struct i82593_conf_block));
ian@0 245
ian@0 246 /* The configuration block. What an undocumented nightmare.
ian@0 247 The first set of values are those suggested (without explanation)
ian@0 248 for ethernet in the Intel 82586 databook. The rest appear to be
ian@0 249 completely undocumented, except for cryptic notes in the Crynwr
ian@0 250 packet driver. This driver uses the Crynwr values verbatim. */
ian@0 251
ian@0 252 /* maz : Rewritten to take advantage of the wanvelan includes.
ian@0 253 At least we have names, not just blind values */
ian@0 254
ian@0 255 /* Byte 0 */
ian@0 256 cfblk->fifo_limit = 10; /* = 16 B rx and 80 B tx fifo thresholds */
ian@0 257 cfblk->forgnesi = 0; /* 0=82C501, 1=AMD7992B compatibility */
ian@0 258 cfblk->fifo_32 = 1;
ian@0 259 cfblk->d6mod = 0; /* Run in i82593 advanced mode */
ian@0 260 cfblk->throttle_enb = 1;
ian@0 261
ian@0 262 /* Byte 1 */
ian@0 263 cfblk->throttle = 8; /* Continuous w/interrupts, 128-clock DMA. */
ian@0 264 cfblk->cntrxint = 0; /* enable continuous mode receive interrupts */
ian@0 265 cfblk->contin = 1; /* enable continuous mode */
ian@0 266
ian@0 267 /* Byte 2 */
ian@0 268 cfblk->addr_len = ETH_ALEN;
ian@0 269 cfblk->acloc = 1; /* Disable source addr insertion by i82593 */
ian@0 270 cfblk->preamb_len = 2; /* 8 bytes preamble */
ian@0 271 cfblk->loopback = 0; /* Loopback off */
ian@0 272
ian@0 273 /* Byte 3 */
ian@0 274 cfblk->lin_prio = 0; /* Default priorities & backoff methods. */
ian@0 275 cfblk->tbofstop = 0;
ian@0 276 cfblk->exp_prio = 0;
ian@0 277 cfblk->bof_met = 0;
ian@0 278
ian@0 279 /* Byte 4 */
ian@0 280 cfblk->ifrm_spc = 6; /* 96 bit times interframe spacing */
ian@0 281
ian@0 282 /* Byte 5 */
ian@0 283 cfblk->slottim_low = 0; /* 512 bit times slot time (low) */
ian@0 284
ian@0 285 /* Byte 6 */
ian@0 286 cfblk->slottim_hi = 2; /* 512 bit times slot time (high) */
ian@0 287 cfblk->max_retr = 15; /* 15 collisions retries */
ian@0 288
ian@0 289 /* Byte 7 */
ian@0 290 cfblk->prmisc = ((dev->flags & IFF_PROMISC) ? 1 : 0); /* Promiscuous mode */
ian@0 291 cfblk->bc_dis = 0; /* Enable broadcast reception */
ian@0 292 cfblk->crs_1 = 0; /* Don't transmit without carrier sense */
ian@0 293 cfblk->nocrc_ins = 0; /* i82593 generates CRC */
ian@0 294 cfblk->crc_1632 = 0; /* 32-bit Autodin-II CRC */
ian@0 295 cfblk->crs_cdt = 0; /* CD not to be interpreted as CS */
ian@0 296
ian@0 297 /* Byte 8 */
ian@0 298 cfblk->cs_filter = 0; /* CS is recognized immediately */
ian@0 299 cfblk->crs_src = 0; /* External carrier sense */
ian@0 300 cfblk->cd_filter = 0; /* CD is recognized immediately */
ian@0 301
ian@0 302 /* Byte 9 */
ian@0 303 cfblk->min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length */
ian@0 304
ian@0 305 /* Byte A */
ian@0 306 cfblk->lng_typ = 1; /* Type/length checks OFF */
ian@0 307 cfblk->lng_fld = 1; /* Disable 802.3 length field check */
ian@0 308 cfblk->rxcrc_xf = 1; /* Don't transfer CRC to memory */
ian@0 309 cfblk->artx = 1; /* Disable automatic retransmission */
ian@0 310 cfblk->sarec = 1; /* Disable source addr trig of CD */
ian@0 311 cfblk->tx_jabber = 0; /* Disable jabber jam sequence */
ian@0 312 cfblk->hash_1 = 1; /* Use bits 0-5 in mc address hash */
ian@0 313 cfblk->lbpkpol = 0; /* Loopback pin active high */
ian@0 314
ian@0 315 /* Byte B */
ian@0 316 cfblk->fdx = 0; /* Disable full duplex operation */
ian@0 317
ian@0 318 /* Byte C */
ian@0 319 cfblk->dummy_6 = 0x3f; /* all ones, Default multicast addresses & backoff. */
ian@0 320 cfblk->mult_ia = 0; /* No multiple individual addresses */
ian@0 321 cfblk->dis_bof = 0; /* Disable the backoff algorithm ?! */
ian@0 322
ian@0 323 /* Byte D */
ian@0 324 cfblk->dummy_1 = 1; /* set to 1 */
ian@0 325 cfblk->tx_ifs_retrig = 3; /* Hmm... Disabled */
ian@0 326 cfblk->mc_all = (dev->mc_list || (dev->flags&IFF_ALLMULTI));/* multicast all mode */
ian@0 327 cfblk->rcv_mon = 0; /* Monitor mode disabled */
ian@0 328 cfblk->frag_acpt = 0; /* Do not accept fragments */
ian@0 329 cfblk->tstrttrs = 0; /* No start transmission threshold */
ian@0 330
ian@0 331 /* Byte E */
ian@0 332 cfblk->fretx = 1; /* FIFO automatic retransmission */
ian@0 333 cfblk->runt_eop = 0; /* drop "runt" packets */
ian@0 334 cfblk->hw_sw_pin = 0; /* ?? */
ian@0 335 cfblk->big_endn = 0; /* Big Endian ? no... */
ian@0 336 cfblk->syncrqs = 1; /* Synchronous DRQ deassertion... */
ian@0 337 cfblk->sttlen = 1; /* 6 byte status registers */
ian@0 338 cfblk->rx_eop = 0; /* Signal EOP on packet reception */
ian@0 339 cfblk->tx_eop = 0; /* Signal EOP on packet transmission */
ian@0 340
ian@0 341 /* Byte F */
ian@0 342 cfblk->rbuf_size = RX_BUF_SIZE >> 12; /* Set receive buffer size */
ian@0 343 cfblk->rcvstop = 1; /* Enable Receive Stop Register */
ian@0 344
ian@0 345 if (znet_debug > 2) {
ian@0 346 int i;
ian@0 347 unsigned char *c;
ian@0 348
ian@0 349 for (i = 0, c = (char *) cfblk; i < sizeof (*cfblk); i++)
ian@0 350 printk ("%02X ", c[i]);
ian@0 351 printk ("\n");
ian@0 352 }
ian@0 353
ian@0 354 *znet->tx_cur++ = sizeof(struct i82593_conf_block);
ian@0 355 memcpy(znet->tx_cur, cfblk, sizeof(struct i82593_conf_block));
ian@0 356 znet->tx_cur += sizeof(struct i82593_conf_block)/2;
ian@0 357 outb(OP0_CONFIGURE | CR0_CHNL, ioaddr);
ian@0 358
ian@0 359 /* XXX FIXME maz : Add multicast addresses here, so having a
ian@0 360 * multicast address configured isn't equal to IFF_ALLMULTI */
ian@0 361 }
ian@0 362
ian@0 363 /* The Z-Note probe is pretty easy. The NETIDBLK exists in the safe-to-probe
ian@0 364 BIOS area. We just scan for the signature, and pull the vital parameters
ian@0 365 out of the structure. */
ian@0 366
ian@0 367 static int __init znet_probe (void)
ian@0 368 {
ian@0 369 int i;
ian@0 370 struct netidblk *netinfo;
ian@0 371 struct znet_private *znet;
ian@0 372 struct net_device *dev;
ian@0 373 char *p;
ian@0 374 int err = -ENOMEM;
ian@0 375
ian@0 376 /* This code scans the region 0xf0000 to 0xfffff for a "NETIDBLK". */
ian@0 377 for(p = (char *)phys_to_virt(0xf0000); p < (char *)phys_to_virt(0x100000); p++)
ian@0 378 if (*p == 'N' && strncmp(p, "NETIDBLK", 8) == 0)
ian@0 379 break;
ian@0 380
ian@0 381 if (p >= (char *)phys_to_virt(0x100000)) {
ian@0 382 if (znet_debug > 1)
ian@0 383 printk(KERN_INFO "No Z-Note ethernet adaptor found.\n");
ian@0 384 return -ENODEV;
ian@0 385 }
ian@0 386
ian@0 387 dev = alloc_etherdev(sizeof(struct znet_private));
ian@0 388 if (!dev)
ian@0 389 return -ENOMEM;
ian@0 390
ian@0 391 SET_MODULE_OWNER (dev);
ian@0 392
ian@0 393 znet = dev->priv;
ian@0 394
ian@0 395 netinfo = (struct netidblk *)p;
ian@0 396 dev->base_addr = netinfo->iobase1;
ian@0 397 dev->irq = netinfo->irq1;
ian@0 398
ian@0 399 printk(KERN_INFO "%s: ZNET at %#3lx,", dev->name, dev->base_addr);
ian@0 400
ian@0 401 /* The station address is in the "netidblk" at 0x0f0000. */
ian@0 402 for (i = 0; i < 6; i++)
ian@0 403 printk(" %2.2x", dev->dev_addr[i] = netinfo->netid[i]);
ian@0 404
ian@0 405 printk(", using IRQ %d DMA %d and %d.\n", dev->irq, netinfo->dma1,
ian@0 406 netinfo->dma2);
ian@0 407
ian@0 408 if (znet_debug > 1) {
ian@0 409 printk(KERN_INFO "%s: vendor '%16.16s' IRQ1 %d IRQ2 %d DMA1 %d DMA2 %d.\n",
ian@0 410 dev->name, netinfo->vendor,
ian@0 411 netinfo->irq1, netinfo->irq2,
ian@0 412 netinfo->dma1, netinfo->dma2);
ian@0 413 printk(KERN_INFO "%s: iobase1 %#x size %d iobase2 %#x size %d net type %2.2x.\n",
ian@0 414 dev->name, netinfo->iobase1, netinfo->iosize1,
ian@0 415 netinfo->iobase2, netinfo->iosize2, netinfo->nettype);
ian@0 416 }
ian@0 417
ian@0 418 if (znet_debug > 0)
ian@0 419 printk(KERN_INFO "%s", version);
ian@0 420
ian@0 421 znet->rx_dma = netinfo->dma1;
ian@0 422 znet->tx_dma = netinfo->dma2;
ian@0 423 spin_lock_init(&znet->lock);
ian@0 424 znet->sia_base = 0xe6; /* Magic address for the 82501 SIA */
ian@0 425 znet->sia_size = 2;
ian@0 426 /* maz: Despite the '593 being advertised above as using a
ian@0 427 * single 8bits I/O port, this driver does many 16bits
ian@0 428 * access. So set io_size accordingly */
ian@0 429 znet->io_size = 2;
ian@0 430
ian@0 431 if (!(znet->rx_start = kmalloc (DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA)))
ian@0 432 goto free_dev;
ian@0 433 if (!(znet->tx_start = kmalloc (DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA)))
ian@0 434 goto free_rx;
ian@0 435
ian@0 436 if (!dma_page_eq (znet->rx_start, znet->rx_start + (RX_BUF_SIZE/2-1)) ||
ian@0 437 !dma_page_eq (znet->tx_start, znet->tx_start + (TX_BUF_SIZE/2-1))) {
ian@0 438 printk (KERN_WARNING "tx/rx crossing DMA frontiers, giving up\n");
ian@0 439 goto free_tx;
ian@0 440 }
ian@0 441
ian@0 442 znet->rx_end = znet->rx_start + RX_BUF_SIZE/2;
ian@0 443 znet->tx_buf_len = TX_BUF_SIZE/2;
ian@0 444 znet->tx_end = znet->tx_start + znet->tx_buf_len;
ian@0 445
ian@0 446 /* The ZNET-specific entries in the device structure. */
ian@0 447 dev->open = &znet_open;
ian@0 448 dev->hard_start_xmit = &znet_send_packet;
ian@0 449 dev->stop = &znet_close;
ian@0 450 dev->get_stats = net_get_stats;
ian@0 451 dev->set_multicast_list = &znet_set_multicast_list;
ian@0 452 dev->tx_timeout = znet_tx_timeout;
ian@0 453 dev->watchdog_timeo = TX_TIMEOUT;
ian@0 454 err = register_netdev(dev);
ian@0 455 if (err)
ian@0 456 goto free_tx;
ian@0 457 znet_dev = dev;
ian@0 458 return 0;
ian@0 459
ian@0 460 free_tx:
ian@0 461 kfree(znet->tx_start);
ian@0 462 free_rx:
ian@0 463 kfree(znet->rx_start);
ian@0 464 free_dev:
ian@0 465 free_netdev(dev);
ian@0 466 return err;
ian@0 467 }
ian@0 468
ian@0 469
ian@0 470 static int znet_open(struct net_device *dev)
ian@0 471 {
ian@0 472 int ioaddr = dev->base_addr;
ian@0 473
ian@0 474 if (znet_debug > 2)
ian@0 475 printk(KERN_DEBUG "%s: znet_open() called.\n", dev->name);
ian@0 476
ian@0 477 /* These should never fail. You can't add devices to a sealed box! */
ian@0 478 if (znet_request_resources (dev)) {
ian@0 479 printk(KERN_WARNING "%s: Not opened -- resource busy?!?\n", dev->name);
ian@0 480 return -EBUSY;
ian@0 481 }
ian@0 482
ian@0 483 znet_transceiver_power (dev, 1);
ian@0 484
ian@0 485 /* According to the Crynwr driver we should wait 50 msec. for the
ian@0 486 LAN clock to stabilize. My experiments indicates that the '593 can
ian@0 487 be initialized immediately. The delay is probably needed for the
ian@0 488 DC-to-DC converter to come up to full voltage, and for the oscillator
ian@0 489 to be spot-on at 20Mhz before transmitting.
ian@0 490 Until this proves to be a problem we rely on the higher layers for the
ian@0 491 delay and save allocating a timer entry. */
ian@0 492
ian@0 493 /* maz : Well, I'm getting every time the following message
ian@0 494 * without the delay on a 486@33. This machine is much too
ian@0 495 * fast... :-) So maybe the Crynwr driver wasn't wrong after
ian@0 496 * all, even if the message is completly harmless on my
ian@0 497 * setup. */
ian@0 498 mdelay (50);
ian@0 499
ian@0 500 /* This follows the packet driver's lead, and checks for success. */
ian@0 501 if (inb(ioaddr) != 0x10 && inb(ioaddr) != 0x00)
ian@0 502 printk(KERN_WARNING "%s: Problem turning on the transceiver power.\n",
ian@0 503 dev->name);
ian@0 504
ian@0 505 hardware_init(dev);
ian@0 506 netif_start_queue (dev);
ian@0 507
ian@0 508 return 0;
ian@0 509 }
ian@0 510
ian@0 511
ian@0 512 static void znet_tx_timeout (struct net_device *dev)
ian@0 513 {
ian@0 514 int ioaddr = dev->base_addr;
ian@0 515 ushort event, tx_status, rx_offset, state;
ian@0 516
ian@0 517 outb (CR0_STATUS_0, ioaddr);
ian@0 518 event = inb (ioaddr);
ian@0 519 outb (CR0_STATUS_1, ioaddr);
ian@0 520 tx_status = inw (ioaddr);
ian@0 521 outb (CR0_STATUS_2, ioaddr);
ian@0 522 rx_offset = inw (ioaddr);
ian@0 523 outb (CR0_STATUS_3, ioaddr);
ian@0 524 state = inb (ioaddr);
ian@0 525 printk (KERN_WARNING "%s: transmit timed out, status %02x %04x %04x %02x,"
ian@0 526 " resetting.\n", dev->name, event, tx_status, rx_offset, state);
ian@0 527 if (tx_status == TX_LOST_CRS)
ian@0 528 printk (KERN_WARNING "%s: Tx carrier error, check transceiver cable.\n",
ian@0 529 dev->name);
ian@0 530 outb (OP0_RESET, ioaddr);
ian@0 531 hardware_init (dev);
ian@0 532 netif_wake_queue (dev);
ian@0 533 }
ian@0 534
ian@0 535 static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
ian@0 536 {
ian@0 537 int ioaddr = dev->base_addr;
ian@0 538 struct znet_private *znet = dev->priv;
ian@0 539 unsigned long flags;
ian@0 540 short length = skb->len;
ian@0 541
ian@0 542 if (znet_debug > 4)
ian@0 543 printk(KERN_DEBUG "%s: ZNet_send_packet.\n", dev->name);
ian@0 544
ian@0 545 if (length < ETH_ZLEN) {
ian@0 546 if (skb_padto(skb, ETH_ZLEN))
ian@0 547 return 0;
ian@0 548 length = ETH_ZLEN;
ian@0 549 }
ian@0 550
ian@0 551 netif_stop_queue (dev);
ian@0 552
ian@0 553 /* Check that the part hasn't reset itself, probably from suspend. */
ian@0 554 outb(CR0_STATUS_0, ioaddr);
ian@0 555 if (inw(ioaddr) == 0x0010 &&
ian@0 556 inw(ioaddr) == 0x0000 &&
ian@0 557 inw(ioaddr) == 0x0010) {
ian@0 558 if (znet_debug > 1)
ian@0 559 printk (KERN_WARNING "%s : waking up\n", dev->name);
ian@0 560 hardware_init(dev);
ian@0 561 znet_transceiver_power (dev, 1);
ian@0 562 }
ian@0 563
ian@0 564 if (1) {
ian@0 565 unsigned char *buf = (void *)skb->data;
ian@0 566 ushort *tx_link = znet->tx_cur - 1;
ian@0 567 ushort rnd_len = (length + 1)>>1;
ian@0 568
ian@0 569 znet->stats.tx_bytes+=length;
ian@0 570
ian@0 571 if (znet->tx_cur >= znet->tx_end)
ian@0 572 znet->tx_cur = znet->tx_start;
ian@0 573 *znet->tx_cur++ = length;
ian@0 574 if (znet->tx_cur + rnd_len + 1 > znet->tx_end) {
ian@0 575 int semi_cnt = (znet->tx_end - znet->tx_cur)<<1; /* Cvrt to byte cnt. */
ian@0 576 memcpy(znet->tx_cur, buf, semi_cnt);
ian@0 577 rnd_len -= semi_cnt>>1;
ian@0 578 memcpy(znet->tx_start, buf + semi_cnt, length - semi_cnt);
ian@0 579 znet->tx_cur = znet->tx_start + rnd_len;
ian@0 580 } else {
ian@0 581 memcpy(znet->tx_cur, buf, skb->len);
ian@0 582 znet->tx_cur += rnd_len;
ian@0 583 }
ian@0 584 *znet->tx_cur++ = 0;
ian@0 585
ian@0 586 spin_lock_irqsave(&znet->lock, flags);
ian@0 587 {
ian@0 588 *tx_link = OP0_TRANSMIT | CR0_CHNL;
ian@0 589 /* Is this always safe to do? */
ian@0 590 outb(OP0_TRANSMIT | CR0_CHNL, ioaddr);
ian@0 591 }
ian@0 592 spin_unlock_irqrestore (&znet->lock, flags);
ian@0 593
ian@0 594 dev->trans_start = jiffies;
ian@0 595 netif_start_queue (dev);
ian@0 596
ian@0 597 if (znet_debug > 4)
ian@0 598 printk(KERN_DEBUG "%s: Transmitter queued, length %d.\n", dev->name, length);
ian@0 599 }
ian@0 600 dev_kfree_skb(skb);
ian@0 601 return 0;
ian@0 602 }
ian@0 603
ian@0 604 /* The ZNET interrupt handler. */
ian@0 605 static irqreturn_t znet_interrupt(int irq, void *dev_id, struct pt_regs * regs)
ian@0 606 {
ian@0 607 struct net_device *dev = dev_id;
ian@0 608 struct znet_private *znet = dev->priv;
ian@0 609 int ioaddr;
ian@0 610 int boguscnt = 20;
ian@0 611 int handled = 0;
ian@0 612
ian@0 613 if (dev == NULL) {
ian@0 614 printk(KERN_WARNING "znet_interrupt(): IRQ %d for unknown device.\n", irq);
ian@0 615 return IRQ_NONE;
ian@0 616 }
ian@0 617
ian@0 618 spin_lock (&znet->lock);
ian@0 619
ian@0 620 ioaddr = dev->base_addr;
ian@0 621
ian@0 622 outb(CR0_STATUS_0, ioaddr);
ian@0 623 do {
ian@0 624 ushort status = inb(ioaddr);
ian@0 625 if (znet_debug > 5) {
ian@0 626 ushort result, rx_ptr, running;
ian@0 627 outb(CR0_STATUS_1, ioaddr);
ian@0 628 result = inw(ioaddr);
ian@0 629 outb(CR0_STATUS_2, ioaddr);
ian@0 630 rx_ptr = inw(ioaddr);
ian@0 631 outb(CR0_STATUS_3, ioaddr);
ian@0 632 running = inb(ioaddr);
ian@0 633 printk(KERN_DEBUG "%s: interrupt, status %02x, %04x %04x %02x serial %d.\n",
ian@0 634 dev->name, status, result, rx_ptr, running, boguscnt);
ian@0 635 }
ian@0 636 if ((status & SR0_INTERRUPT) == 0)
ian@0 637 break;
ian@0 638
ian@0 639 handled = 1;
ian@0 640
ian@0 641 if ((status & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
ian@0 642 (status & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
ian@0 643 (status & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE) {
ian@0 644 int tx_status;
ian@0 645 outb(CR0_STATUS_1, ioaddr);
ian@0 646 tx_status = inw(ioaddr);
ian@0 647 /* It's undocumented, but tx_status seems to match the i82586. */
ian@0 648 if (tx_status & TX_OK) {
ian@0 649 znet->stats.tx_packets++;
ian@0 650 znet->stats.collisions += tx_status & TX_NCOL_MASK;
ian@0 651 } else {
ian@0 652 if (tx_status & (TX_LOST_CTS | TX_LOST_CRS))
ian@0 653 znet->stats.tx_carrier_errors++;
ian@0 654 if (tx_status & TX_UND_RUN)
ian@0 655 znet->stats.tx_fifo_errors++;
ian@0 656 if (!(tx_status & TX_HRT_BEAT))
ian@0 657 znet->stats.tx_heartbeat_errors++;
ian@0 658 if (tx_status & TX_MAX_COL)
ian@0 659 znet->stats.tx_aborted_errors++;
ian@0 660 /* ...and the catch-all. */
ian@0 661 if ((tx_status | (TX_LOST_CRS | TX_LOST_CTS | TX_UND_RUN | TX_HRT_BEAT | TX_MAX_COL)) != (TX_LOST_CRS | TX_LOST_CTS | TX_UND_RUN | TX_HRT_BEAT | TX_MAX_COL))
ian@0 662 znet->stats.tx_errors++;
ian@0 663
ian@0 664 /* Transceiver may be stuck if cable
ian@0 665 * was removed while emiting a
ian@0 666 * packet. Flip it off, then on to
ian@0 667 * reset it. This is very empirical,
ian@0 668 * but it seems to work. */
ian@0 669
ian@0 670 znet_transceiver_power (dev, 0);
ian@0 671 znet_transceiver_power (dev, 1);
ian@0 672 }
ian@0 673 netif_wake_queue (dev);
ian@0 674 }
ian@0 675
ian@0 676 if ((status & SR0_RECEPTION) ||
ian@0 677 (status & SR0_EVENT_MASK) == SR0_STOP_REG_HIT) {
ian@0 678 znet_rx(dev);
ian@0 679 }
ian@0 680 /* Clear the interrupts we've handled. */
ian@0 681 outb(CR0_INT_ACK, ioaddr);
ian@0 682 } while (boguscnt--);
ian@0 683
ian@0 684 spin_unlock (&znet->lock);
ian@0 685
ian@0 686 return IRQ_RETVAL(handled);
ian@0 687 }
ian@0 688
ian@0 689 static void znet_rx(struct net_device *dev)
ian@0 690 {
ian@0 691 struct znet_private *znet = dev->priv;
ian@0 692 int ioaddr = dev->base_addr;
ian@0 693 int boguscount = 1;
ian@0 694 short next_frame_end_offset = 0; /* Offset of next frame start. */
ian@0 695 short *cur_frame_end;
ian@0 696 short cur_frame_end_offset;
ian@0 697
ian@0 698 outb(CR0_STATUS_2, ioaddr);
ian@0 699 cur_frame_end_offset = inw(ioaddr);
ian@0 700
ian@0 701 if (cur_frame_end_offset == znet->rx_cur - znet->rx_start) {
ian@0 702 printk(KERN_WARNING "%s: Interrupted, but nothing to receive, offset %03x.\n",
ian@0 703 dev->name, cur_frame_end_offset);
ian@0 704 return;
ian@0 705 }
ian@0 706
ian@0 707 /* Use same method as the Crynwr driver: construct a forward list in
ian@0 708 the same area of the backwards links we now have. This allows us to
ian@0 709 pass packets to the upper layers in the order they were received --
ian@0 710 important for fast-path sequential operations. */
ian@0 711 while (znet->rx_start + cur_frame_end_offset != znet->rx_cur
ian@0 712 && ++boguscount < 5) {
ian@0 713 unsigned short hi_cnt, lo_cnt, hi_status, lo_status;
ian@0 714 int count, status;
ian@0 715
ian@0 716 if (cur_frame_end_offset < 4) {
ian@0 717 /* Oh no, we have a special case: the frame trailer wraps around
ian@0 718 the end of the ring buffer. We've saved space at the end of
ian@0 719 the ring buffer for just this problem. */
ian@0 720 memcpy(znet->rx_end, znet->rx_start, 8);
ian@0 721 cur_frame_end_offset += (RX_BUF_SIZE/2);
ian@0 722 }
ian@0 723 cur_frame_end = znet->rx_start + cur_frame_end_offset - 4;
ian@0 724
ian@0 725 lo_status = *cur_frame_end++;
ian@0 726 hi_status = *cur_frame_end++;
ian@0 727 status = ((hi_status & 0xff) << 8) + (lo_status & 0xff);
ian@0 728 lo_cnt = *cur_frame_end++;
ian@0 729 hi_cnt = *cur_frame_end++;
ian@0 730 count = ((hi_cnt & 0xff) << 8) + (lo_cnt & 0xff);
ian@0 731
ian@0 732 if (znet_debug > 5)
ian@0 733 printk(KERN_DEBUG "Constructing trailer at location %03x, %04x %04x %04x %04x"
ian@0 734 " count %#x status %04x.\n",
ian@0 735 cur_frame_end_offset<<1, lo_status, hi_status, lo_cnt, hi_cnt,
ian@0 736 count, status);
ian@0 737 cur_frame_end[-4] = status;
ian@0 738 cur_frame_end[-3] = next_frame_end_offset;
ian@0 739 cur_frame_end[-2] = count;
ian@0 740 next_frame_end_offset = cur_frame_end_offset;
ian@0 741 cur_frame_end_offset -= ((count + 1)>>1) + 3;
ian@0 742 if (cur_frame_end_offset < 0)
ian@0 743 cur_frame_end_offset += RX_BUF_SIZE/2;
ian@0 744 };
ian@0 745
ian@0 746 /* Now step forward through the list. */
ian@0 747 do {
ian@0 748 ushort *this_rfp_ptr = znet->rx_start + next_frame_end_offset;
ian@0 749 int status = this_rfp_ptr[-4];
ian@0 750 int pkt_len = this_rfp_ptr[-2];
ian@0 751
ian@0 752 if (znet_debug > 5)
ian@0 753 printk(KERN_DEBUG "Looking at trailer ending at %04x status %04x length %03x"
ian@0 754 " next %04x.\n", next_frame_end_offset<<1, status, pkt_len,
ian@0 755 this_rfp_ptr[-3]<<1);
ian@0 756 /* Once again we must assume that the i82586 docs apply. */
ian@0 757 if ( ! (status & RX_RCV_OK)) { /* There was an error. */
ian@0 758 znet->stats.rx_errors++;
ian@0 759 if (status & RX_CRC_ERR) znet->stats.rx_crc_errors++;
ian@0 760 if (status & RX_ALG_ERR) znet->stats.rx_frame_errors++;
ian@0 761 #if 0
ian@0 762 if (status & 0x0200) znet->stats.rx_over_errors++; /* Wrong. */
ian@0 763 if (status & 0x0100) znet->stats.rx_fifo_errors++;
ian@0 764 #else
ian@0 765 /* maz : Wild guess... */
ian@0 766 if (status & RX_OVRRUN) znet->stats.rx_over_errors++;
ian@0 767 #endif
ian@0 768 if (status & RX_SRT_FRM) znet->stats.rx_length_errors++;
ian@0 769 } else if (pkt_len > 1536) {
ian@0 770 znet->stats.rx_length_errors++;
ian@0 771 } else {
ian@0 772 /* Malloc up new buffer. */
ian@0 773 struct sk_buff *skb;
ian@0 774
ian@0 775 skb = dev_alloc_skb(pkt_len);
ian@0 776 if (skb == NULL) {
ian@0 777 if (znet_debug)
ian@0 778 printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
ian@0 779 znet->stats.rx_dropped++;
ian@0 780 break;
ian@0 781 }
ian@0 782 skb->dev = dev;
ian@0 783
ian@0 784 if (&znet->rx_cur[(pkt_len+1)>>1] > znet->rx_end) {
ian@0 785 int semi_cnt = (znet->rx_end - znet->rx_cur)<<1;
ian@0 786 memcpy(skb_put(skb,semi_cnt), znet->rx_cur, semi_cnt);
ian@0 787 memcpy(skb_put(skb,pkt_len-semi_cnt), znet->rx_start,
ian@0 788 pkt_len - semi_cnt);
ian@0 789 } else {
ian@0 790 memcpy(skb_put(skb,pkt_len), znet->rx_cur, pkt_len);
ian@0 791 if (znet_debug > 6) {
ian@0 792 unsigned int *packet = (unsigned int *) skb->data;
ian@0 793 printk(KERN_DEBUG "Packet data is %08x %08x %08x %08x.\n", packet[0],
ian@0 794 packet[1], packet[2], packet[3]);
ian@0 795 }
ian@0 796 }
ian@0 797 skb->protocol=eth_type_trans(skb,dev);
ian@0 798 netif_rx(skb);
ian@0 799 dev->last_rx = jiffies;
ian@0 800 znet->stats.rx_packets++;
ian@0 801 znet->stats.rx_bytes += pkt_len;
ian@0 802 }
ian@0 803 znet->rx_cur = this_rfp_ptr;
ian@0 804 if (znet->rx_cur >= znet->rx_end)
ian@0 805 znet->rx_cur -= RX_BUF_SIZE/2;
ian@0 806 update_stop_hit(ioaddr, (znet->rx_cur - znet->rx_start)<<1);
ian@0 807 next_frame_end_offset = this_rfp_ptr[-3];
ian@0 808 if (next_frame_end_offset == 0) /* Read all the frames? */
ian@0 809 break; /* Done for now */
ian@0 810 this_rfp_ptr = znet->rx_start + next_frame_end_offset;
ian@0 811 } while (--boguscount);
ian@0 812
ian@0 813 /* If any worth-while packets have been received, dev_rint()
ian@0 814 has done a mark_bh(INET_BH) for us and will work on them
ian@0 815 when we get to the bottom-half routine. */
ian@0 816 return;
ian@0 817 }
ian@0 818
ian@0 819 /* The inverse routine to znet_open(). */
ian@0 820 static int znet_close(struct net_device *dev)
ian@0 821 {
ian@0 822 int ioaddr = dev->base_addr;
ian@0 823
ian@0 824 netif_stop_queue (dev);
ian@0 825
ian@0 826 outb(OP0_RESET, ioaddr); /* CMD0_RESET */
ian@0 827
ian@0 828 if (znet_debug > 1)
ian@0 829 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
ian@0 830 /* Turn off transceiver power. */
ian@0 831 znet_transceiver_power (dev, 0);
ian@0 832
ian@0 833 znet_release_resources (dev);
ian@0 834
ian@0 835 return 0;
ian@0 836 }
ian@0 837
ian@0 838 /* Get the current statistics. This may be called with the card open or
ian@0 839 closed. */
ian@0 840 static struct net_device_stats *net_get_stats(struct net_device *dev)
ian@0 841 {
ian@0 842 struct znet_private *znet = dev->priv;
ian@0 843
ian@0 844 return &znet->stats;
ian@0 845 }
ian@0 846
ian@0 847 static void show_dma(struct net_device *dev)
ian@0 848 {
ian@0 849 short ioaddr = dev->base_addr;
ian@0 850 unsigned char stat = inb (ioaddr);
ian@0 851 struct znet_private *znet = dev->priv;
ian@0 852 unsigned long flags;
ian@0 853 short dma_port = ((znet->tx_dma&3)<<2) + IO_DMA2_BASE;
ian@0 854 unsigned addr = inb(dma_port);
ian@0 855 short residue;
ian@0 856
ian@0 857 addr |= inb(dma_port) << 8;
ian@0 858 residue = get_dma_residue(znet->tx_dma);
ian@0 859
ian@0 860 if (znet_debug > 1) {
ian@0 861 flags=claim_dma_lock();
ian@0 862 printk(KERN_DEBUG "Stat:%02x Addr: %04x cnt:%3x\n",
ian@0 863 stat, addr<<1, residue);
ian@0 864 release_dma_lock(flags);
ian@0 865 }
ian@0 866 }
ian@0 867
ian@0 868 /* Initialize the hardware. We have to do this when the board is open()ed
ian@0 869 or when we come out of suspend mode. */
ian@0 870 static void hardware_init(struct net_device *dev)
ian@0 871 {
ian@0 872 unsigned long flags;
ian@0 873 short ioaddr = dev->base_addr;
ian@0 874 struct znet_private *znet = dev->priv;
ian@0 875
ian@0 876 znet->rx_cur = znet->rx_start;
ian@0 877 znet->tx_cur = znet->tx_start;
ian@0 878
ian@0 879 /* Reset the chip, and start it up. */
ian@0 880 outb(OP0_RESET, ioaddr);
ian@0 881
ian@0 882 flags=claim_dma_lock();
ian@0 883 disable_dma(znet->rx_dma); /* reset by an interrupting task. */
ian@0 884 clear_dma_ff(znet->rx_dma);
ian@0 885 set_dma_mode(znet->rx_dma, DMA_RX_MODE);
ian@0 886 set_dma_addr(znet->rx_dma, (unsigned int) znet->rx_start);
ian@0 887 set_dma_count(znet->rx_dma, RX_BUF_SIZE);
ian@0 888 enable_dma(znet->rx_dma);
ian@0 889 /* Now set up the Tx channel. */
ian@0 890 disable_dma(znet->tx_dma);
ian@0 891 clear_dma_ff(znet->tx_dma);
ian@0 892 set_dma_mode(znet->tx_dma, DMA_TX_MODE);
ian@0 893 set_dma_addr(znet->tx_dma, (unsigned int) znet->tx_start);
ian@0 894 set_dma_count(znet->tx_dma, znet->tx_buf_len<<1);
ian@0 895 enable_dma(znet->tx_dma);
ian@0 896 release_dma_lock(flags);
ian@0 897
ian@0 898 if (znet_debug > 1)
ian@0 899 printk(KERN_DEBUG "%s: Initializing the i82593, rx buf %p tx buf %p\n",
ian@0 900 dev->name, znet->rx_start,znet->tx_start);
ian@0 901 /* Do an empty configure command, just like the Crynwr driver. This
ian@0 902 resets to chip to its default values. */
ian@0 903 *znet->tx_cur++ = 0;
ian@0 904 *znet->tx_cur++ = 0;
ian@0 905 show_dma(dev);
ian@0 906 outb(OP0_CONFIGURE | CR0_CHNL, ioaddr);
ian@0 907
ian@0 908 znet_set_multicast_list (dev);
ian@0 909
ian@0 910 *znet->tx_cur++ = 6;
ian@0 911 memcpy(znet->tx_cur, dev->dev_addr, 6);
ian@0 912 znet->tx_cur += 3;
ian@0 913 show_dma(dev);
ian@0 914 outb(OP0_IA_SETUP | CR0_CHNL, ioaddr);
ian@0 915 show_dma(dev);
ian@0 916
ian@0 917 update_stop_hit(ioaddr, 8192);
ian@0 918 if (znet_debug > 1) printk(KERN_DEBUG "enabling Rx.\n");
ian@0 919 outb(OP0_RCV_ENABLE, ioaddr);
ian@0 920 netif_start_queue (dev);
ian@0 921 }
ian@0 922
ian@0 923 static void update_stop_hit(short ioaddr, unsigned short rx_stop_offset)
ian@0 924 {
ian@0 925 outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, ioaddr);
ian@0 926 if (znet_debug > 5)
ian@0 927 printk(KERN_DEBUG "Updating stop hit with value %02x.\n",
ian@0 928 (rx_stop_offset >> 6) | CR1_STOP_REG_UPDATE);
ian@0 929 outb((rx_stop_offset >> 6) | CR1_STOP_REG_UPDATE, ioaddr);
ian@0 930 outb(OP1_SWIT_TO_PORT_0, ioaddr);
ian@0 931 }
ian@0 932
ian@0 933 static __exit void znet_cleanup (void)
ian@0 934 {
ian@0 935 if (znet_dev) {
ian@0 936 struct znet_private *znet = znet_dev->priv;
ian@0 937
ian@0 938 unregister_netdev (znet_dev);
ian@0 939 kfree (znet->rx_start);
ian@0 940 kfree (znet->tx_start);
ian@0 941 free_netdev (znet_dev);
ian@0 942 }
ian@0 943 }
ian@0 944
ian@0 945 module_init (znet_probe);
ian@0 946 module_exit (znet_cleanup);