Import 2.3.18pre1
[davej-history.git] / drivers / net / seeq8005.c
blob9d9b9d63390201539fef2ad24c93138a1411cf5d
1 /* seeq8005.c: A network driver for linux. */
2 /*
3 Based on skeleton.c,
4 Written 1993-94 by Donald Becker.
5 See the skeleton.c file for further copyright information.
7 This software may be used and distributed according to the terms
8 of the GNU Public License, incorporated herein by reference.
10 The author may be reached as hamish@zot.apana.org.au
12 This file is a network device driver for the SEEQ 8005 chipset and
13 the Linux operating system.
17 static const char *version =
18 "seeq8005.c:v1.00 8/07/95 Hamish Coleman (hamish@zot.apana.org.au)\n";
21 Sources:
22 SEEQ 8005 databook
24 Version history:
25 1.00 Public release. cosmetic changes (no warnings now)
26 0.68 Turning per- packet,interrupt debug messages off - testing for release.
27 0.67 timing problems/bad buffer reads seem to be fixed now
28 0.63 *!@$ protocol=eth_type_trans -- now packets flow
29 0.56 Send working
30 0.48 Receive working
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/types.h>
36 #include <linux/fcntl.h>
37 #include <linux/interrupt.h>
38 #include <linux/ptrace.h>
39 #include <linux/ioport.h>
40 #include <linux/in.h>
41 #include <linux/malloc.h>
42 #include <linux/string.h>
43 #include <linux/init.h>
44 #include <asm/system.h>
45 #include <asm/bitops.h>
46 #include <asm/delay.h>
47 #include <asm/io.h>
48 #include <asm/dma.h>
49 #include <linux/errno.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
54 #include "seeq8005.h"
56 /* First, a few definitions that the brave might change. */
57 /* A zero-terminated list of I/O addresses to be probed. */
58 static unsigned int seeq8005_portlist[] __initdata =
59 { 0x300, 0x320, 0x340, 0x360, 0};
61 /* use 0 for production, 1 for verification, >2 for debug */
62 #ifndef NET_DEBUG
63 #define NET_DEBUG 1
64 #endif
65 static unsigned int net_debug = NET_DEBUG;
67 /* Information that need to be kept for each board. */
68 struct net_local {
69 struct net_device_stats stats;
70 unsigned short receive_ptr; /* What address in packet memory do we expect a recv_pkt_header? */
71 long open_time; /* Useless example local info. */
74 /* The station (ethernet) address prefix, used for IDing the board. */
75 #define SA_ADDR0 0x00
76 #define SA_ADDR1 0x80
77 #define SA_ADDR2 0x4b
79 /* Index to functions, as function prototypes. */
81 extern int seeq8005_probe(struct net_device *dev);
83 static int seeq8005_probe1(struct net_device *dev, int ioaddr);
84 static int seeq8005_open(struct net_device *dev);
85 static int seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev);
86 static void seeq8005_interrupt(int irq, void *dev_id, struct pt_regs *regs);
87 static void seeq8005_rx(struct net_device *dev);
88 static int seeq8005_close(struct net_device *dev);
89 static struct net_device_stats *seeq8005_get_stats(struct net_device *dev);
90 static void set_multicast_list(struct net_device *dev);
92 /* Example routines you must write ;->. */
93 #define tx_done(dev) (inw(SEEQ_STATUS) & SEEQSTAT_TX_ON)
94 static void hardware_send_packet(struct net_device *dev, char *buf, int length);
95 extern void seeq8005_init(struct net_device *dev, int startp);
96 static inline void wait_for_buffer(struct net_device *dev);
99 /* Check for a network adaptor of this type, and return '0' iff one exists.
100 If dev->base_addr == 0, probe all likely locations.
101 If dev->base_addr == 1, always return failure.
102 If dev->base_addr == 2, allocate space for the device and return success
103 (detachable devices only).
105 #ifdef HAVE_DEVLIST
106 /* Support for an alternate probe manager, which will eliminate the
107 boilerplate below. */
108 struct netdev_entry seeq8005_drv =
109 {"seeq8005", seeq8005_probe1, SEEQ8005_IO_EXTENT, seeq8005_portlist};
110 #else
111 int __init
112 seeq8005_probe(struct net_device *dev)
114 int i;
115 int base_addr = dev ? dev->base_addr : 0;
117 if (base_addr > 0x1ff) /* Check a single specified location. */
118 return seeq8005_probe1(dev, base_addr);
119 else if (base_addr != 0) /* Don't probe at all. */
120 return ENXIO;
122 for (i = 0; seeq8005_portlist[i]; i++) {
123 int ioaddr = seeq8005_portlist[i];
124 if (check_region(ioaddr, SEEQ8005_IO_EXTENT))
125 continue;
126 if (seeq8005_probe1(dev, ioaddr) == 0)
127 return 0;
130 return ENODEV;
132 #endif
134 /* This is the real probe routine. Linux has a history of friendly device
135 probes on the ISA bus. A good device probes avoids doing writes, and
136 verifies that the correct device exists and functions. */
138 static int __init seeq8005_probe1(struct net_device *dev, int ioaddr)
140 static unsigned version_printed = 0;
141 int i,j;
142 unsigned char SA_prom[32];
143 int old_cfg1;
144 int old_cfg2;
145 int old_stat;
146 int old_dmaar;
147 int old_rear;
149 if (net_debug>1)
150 printk("seeq8005: probing at 0x%x\n",ioaddr);
152 old_stat = inw(SEEQ_STATUS); /* read status register */
153 if (old_stat == 0xffff)
154 return ENODEV; /* assume that 0xffff == no device */
155 if ( (old_stat & 0x1800) != 0x1800 ) { /* assume that unused bits are 1, as my manual says */
156 if (net_debug>1) {
157 printk("seeq8005: reserved stat bits != 0x1800\n");
158 printk(" == 0x%04x\n",old_stat);
160 return ENODEV;
163 old_rear = inw(SEEQ_REA);
164 if (old_rear == 0xffff) {
165 outw(0,SEEQ_REA);
166 if (inw(SEEQ_REA) == 0xffff) { /* assume that 0xffff == no device */
167 return ENODEV;
169 } else if ((old_rear & 0xff00) != 0xff00) { /* assume that unused bits are 1 */
170 if (net_debug>1) {
171 printk("seeq8005: unused rear bits != 0xff00\n");
172 printk(" == 0x%04x\n",old_rear);
174 return ENODEV;
177 old_cfg2 = inw(SEEQ_CFG2); /* read CFG2 register */
178 old_cfg1 = inw(SEEQ_CFG1);
179 old_dmaar = inw(SEEQ_DMAAR);
181 if (net_debug>4) {
182 printk("seeq8005: stat = 0x%04x\n",old_stat);
183 printk("seeq8005: cfg1 = 0x%04x\n",old_cfg1);
184 printk("seeq8005: cfg2 = 0x%04x\n",old_cfg2);
185 printk("seeq8005: raer = 0x%04x\n",old_rear);
186 printk("seeq8005: dmaar= 0x%04x\n",old_dmaar);
189 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD); /* setup for reading PROM */
190 outw( 0, SEEQ_DMAAR); /* set starting PROM address */
191 outw( SEEQCFG1_BUFFER_PROM, SEEQ_CFG1); /* set buffer to look at PROM */
194 j=0;
195 for(i=0; i <32; i++) {
196 j+= SA_prom[i] = inw(SEEQ_BUFFER) & 0xff;
199 #if 0
200 /* untested because I only have the one card */
201 if ( (j&0xff) != 0 ) { /* checksum appears to be 8bit = 0 */
202 if (net_debug>1) { /* check this before deciding that we have a card */
203 printk("seeq8005: prom sum error\n");
205 outw( old_stat, SEEQ_STATUS);
206 outw( old_dmaar, SEEQ_DMAAR);
207 outw( old_cfg1, SEEQ_CFG1);
208 return ENODEV;
210 #endif
212 outw( SEEQCFG2_RESET, SEEQ_CFG2); /* reset the card */
213 udelay(5);
214 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
216 if (net_debug) {
217 printk("seeq8005: prom sum = 0x%08x\n",j);
218 for(j=0; j<32; j+=16) {
219 printk("seeq8005: prom %02x: ",j);
220 for(i=0;i<16;i++) {
221 printk("%02x ",SA_prom[j|i]);
223 printk(" ");
224 for(i=0;i<16;i++) {
225 if ((SA_prom[j|i]>31)&&(SA_prom[j|i]<127)) {
226 printk("%c", SA_prom[j|i]);
227 } else {
228 printk(" ");
231 printk("\n");
235 #if 0
237 * testing the packet buffer memory doesn't work yet
238 * but all other buffer accesses do
239 * - fixing is not a priority
241 if (net_debug>1) { /* test packet buffer memory */
242 printk("seeq8005: testing packet buffer ... ");
243 outw( SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
244 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
245 outw( 0 , SEEQ_DMAAR);
246 for(i=0;i<32768;i++) {
247 outw(0x5a5a, SEEQ_BUFFER);
249 j=jiffies+HZ;
250 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_FIFO_EMPTY) != SEEQSTAT_FIFO_EMPTY) && time_before(jiffies, j) )
251 mb();
252 outw( 0 , SEEQ_DMAAR);
253 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, j+HZ))
254 mb();
255 if ( (inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
256 outw( SEEQCMD_WINDOW_INT_ACK | (inw(SEEQ_STATUS)& SEEQCMD_INT_MASK), SEEQ_CMD);
257 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
258 j=0;
259 for(i=0;i<32768;i++) {
260 if (inw(SEEQ_BUFFER) != 0x5a5a)
261 j++;
263 if (j) {
264 printk("%i\n",j);
265 } else {
266 printk("ok.\n");
269 #endif
271 /* Allocate a new 'dev' if needed. */
272 if (dev == NULL)
273 dev = init_etherdev(0, sizeof(struct net_local));
275 if (net_debug && version_printed++ == 0)
276 printk(version);
278 printk("%s: %s found at %#3x, ", dev->name, "seeq8005", ioaddr);
280 /* Fill in the 'dev' fields. */
281 dev->base_addr = ioaddr;
283 /* Retrieve and print the ethernet address. */
284 for (i = 0; i < 6; i++)
285 printk(" %2.2x", dev->dev_addr[i] = SA_prom[i+6]);
287 if (dev->irq == 0xff)
288 ; /* Do nothing: a user-level program will set it. */
289 else if (dev->irq < 2) { /* "Auto-IRQ" */
290 autoirq_setup(0);
292 outw( SEEQCMD_RX_INT_EN | SEEQCMD_SET_RX_ON | SEEQCMD_SET_RX_OFF, SEEQ_CMD );
294 dev->irq = autoirq_report(0);
296 if (net_debug >= 2)
297 printk(" autoirq is %d\n", dev->irq);
298 } else if (dev->irq == 2)
299 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
300 * or don't know which one to set.
302 dev->irq = 9;
304 #if 0
306 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", dev);
307 if (irqval) {
308 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
309 dev->irq, irqval);
310 return EAGAIN;
313 #endif
315 /* Grab the region so we can find another board if autoIRQ fails. */
316 request_region(ioaddr, SEEQ8005_IO_EXTENT,"seeq8005");
318 /* Initialize the device structure. */
319 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
320 if (dev->priv == NULL)
321 return -ENOMEM;
322 memset(dev->priv, 0, sizeof(struct net_local));
324 dev->open = seeq8005_open;
325 dev->stop = seeq8005_close;
326 dev->hard_start_xmit = seeq8005_send_packet;
327 dev->get_stats = seeq8005_get_stats;
328 dev->set_multicast_list = &set_multicast_list;
330 /* Fill in the fields of the device structure with ethernet values. */
331 ether_setup(dev);
333 dev->flags &= ~IFF_MULTICAST;
335 return 0;
339 /* Open/initialize the board. This is called (in the current kernel)
340 sometime after booting when the 'ifconfig' program is run.
342 This routine should set everything up anew at each open, even
343 registers that "should" only need to be set once at boot, so that
344 there is non-reboot way to recover if something goes wrong.
346 static int
347 seeq8005_open(struct net_device *dev)
349 struct net_local *lp = (struct net_local *)dev->priv;
352 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", dev);
353 if (irqval) {
354 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
355 dev->irq, irqval);
356 return EAGAIN;
360 /* Reset the hardware here. Don't forget to set the station address. */
361 seeq8005_init(dev, 1);
363 lp->open_time = jiffies;
365 dev->tbusy = 0;
366 dev->interrupt = 0;
367 dev->start = 1;
368 return 0;
371 static int
372 seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev)
374 int ioaddr = dev->base_addr;
375 struct net_local *lp = (struct net_local *)dev->priv;
377 if (dev->tbusy) {
378 /* If we get here, some higher level has decided we are broken.
379 There should really be a "kick me" function call instead. */
380 int tickssofar = jiffies - dev->trans_start;
381 if (tickssofar < 5)
382 return 1;
383 printk("%s: transmit timed out, %s?\n", dev->name,
384 tx_done(dev) ? "IRQ conflict" : "network cable problem");
385 /* Try to restart the adaptor. */
386 seeq8005_init(dev, 1);
387 dev->tbusy=0;
388 dev->trans_start = jiffies;
391 /* Block a timer-based transmit from overlapping. This could better be
392 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
393 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0)
394 printk("%s: Transmitter access conflict.\n", dev->name);
395 else {
396 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
397 unsigned char *buf = skb->data;
399 hardware_send_packet(dev, buf, length);
400 dev->trans_start = jiffies;
401 lp->stats.tx_bytes += length;
403 dev_kfree_skb (skb);
405 /* You might need to clean up and record Tx statistics here. */
407 return 0;
410 /* The typical workload of the driver:
411 Handle the network interface interrupts. */
412 static void
413 seeq8005_interrupt(int irq, void *dev_id, struct pt_regs * regs)
415 struct net_device *dev = dev_id;
416 struct net_local *lp;
417 int ioaddr, status, boguscount = 0;
419 if (dev == NULL) {
420 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
421 return;
424 if (dev->interrupt)
425 printk ("%s: Re-entering the interrupt handler.\n", dev->name);
426 dev->interrupt = 1;
428 ioaddr = dev->base_addr;
429 lp = (struct net_local *)dev->priv;
431 status = inw(SEEQ_STATUS);
432 do {
433 if (net_debug >2) {
434 printk("%s: int, status=0x%04x\n",dev->name,status);
437 if (status & SEEQSTAT_WINDOW_INT) {
438 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
439 if (net_debug) {
440 printk("%s: window int!\n",dev->name);
443 if (status & SEEQSTAT_TX_INT) {
444 outw( SEEQCMD_TX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
445 lp->stats.tx_packets++;
446 dev->tbusy = 0;
447 mark_bh(NET_BH); /* Inform upper layers. */
449 if (status & SEEQSTAT_RX_INT) {
450 /* Got a packet(s). */
451 seeq8005_rx(dev);
453 status = inw(SEEQ_STATUS);
454 } while ( (++boguscount < 10) && (status & SEEQSTAT_ANY_INT)) ;
456 if(net_debug>2) {
457 printk("%s: eoi\n",dev->name);
459 dev->interrupt = 0;
460 return;
463 /* We have a good packet(s), get it/them out of the buffers. */
464 static void
465 seeq8005_rx(struct net_device *dev)
467 struct net_local *lp = (struct net_local *)dev->priv;
468 int boguscount = 10;
469 int pkt_hdr;
470 int ioaddr = dev->base_addr;
472 do {
473 int next_packet;
474 int pkt_len;
475 int i;
476 int status;
478 status = inw(SEEQ_STATUS);
479 outw( lp->receive_ptr, SEEQ_DMAAR);
480 outw(SEEQCMD_FIFO_READ | SEEQCMD_RX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
481 wait_for_buffer(dev);
482 next_packet = ntohs(inw(SEEQ_BUFFER));
483 pkt_hdr = inw(SEEQ_BUFFER);
485 if (net_debug>2) {
486 printk("%s: 0x%04x recv next=0x%04x, hdr=0x%04x\n",dev->name,lp->receive_ptr,next_packet,pkt_hdr);
489 if ((next_packet == 0) || ((pkt_hdr & SEEQPKTH_CHAIN)==0)) { /* Read all the frames? */
490 return; /* Done for now */
493 if ((pkt_hdr & SEEQPKTS_DONE)==0)
494 break;
496 if (next_packet < lp->receive_ptr) {
497 pkt_len = (next_packet + 0x10000 - ((DEFAULT_TEA+1)<<8)) - lp->receive_ptr - 4;
498 } else {
499 pkt_len = next_packet - lp->receive_ptr - 4;
502 if (next_packet < ((DEFAULT_TEA+1)<<8)) { /* is the next_packet address sane? */
503 printk("%s: recv packet ring corrupt, resetting board\n",dev->name);
504 seeq8005_init(dev,1);
505 return;
508 lp->receive_ptr = next_packet;
510 if (net_debug>2) {
511 printk("%s: recv len=0x%04x\n",dev->name,pkt_len);
514 if (pkt_hdr & SEEQPKTS_ANY_ERROR) { /* There was an error. */
515 lp->stats.rx_errors++;
516 if (pkt_hdr & SEEQPKTS_SHORT) lp->stats.rx_frame_errors++;
517 if (pkt_hdr & SEEQPKTS_DRIB) lp->stats.rx_frame_errors++;
518 if (pkt_hdr & SEEQPKTS_OVERSIZE) lp->stats.rx_over_errors++;
519 if (pkt_hdr & SEEQPKTS_CRC_ERR) lp->stats.rx_crc_errors++;
520 /* skip over this packet */
521 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_DMA_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
522 outw( (lp->receive_ptr & 0xff00)>>8, SEEQ_REA);
523 } else {
524 /* Malloc up new buffer. */
525 struct sk_buff *skb;
526 unsigned char *buf;
528 skb = dev_alloc_skb(pkt_len);
529 if (skb == NULL) {
530 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
531 lp->stats.rx_dropped++;
532 break;
534 skb->dev = dev;
535 skb_reserve(skb, 2); /* align data on 16 byte */
536 buf = skb_put(skb,pkt_len);
538 insw(SEEQ_BUFFER, buf, (pkt_len + 1) >> 1);
540 if (net_debug>2) {
541 char * p = buf;
542 printk("%s: recv ",dev->name);
543 for(i=0;i<14;i++) {
544 printk("%02x ",*(p++)&0xff);
546 printk("\n");
549 skb->protocol=eth_type_trans(skb,dev);
550 netif_rx(skb);
551 lp->stats.rx_packets++;
552 lp->stats.rx_bytes += pkt_len;
554 } while ((--boguscount) && (pkt_hdr & SEEQPKTH_CHAIN));
556 /* If any worth-while packets have been received, netif_rx()
557 has done a mark_bh(NET_BH) for us and will work on them
558 when we get to the bottom-half routine. */
559 return;
562 /* The inverse routine to net_open(). */
563 static int
564 seeq8005_close(struct net_device *dev)
566 struct net_local *lp = (struct net_local *)dev->priv;
567 int ioaddr = dev->base_addr;
569 lp->open_time = 0;
571 dev->tbusy = 1;
572 dev->start = 0;
574 /* Flush the Tx and disable Rx here. */
575 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
577 free_irq(dev->irq, dev);
579 /* Update the statistics here. */
581 return 0;
585 /* Get the current statistics. This may be called with the card open or
586 closed. */
587 static struct net_device_stats *seeq8005_get_stats(struct net_device *dev)
589 struct net_local *lp = (struct net_local *)dev->priv;
591 return &lp->stats;
594 /* Set or clear the multicast filter for this adaptor.
595 num_addrs == -1 Promiscuous mode, receive all packets
596 num_addrs == 0 Normal mode, clear multicast list
597 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
598 best-effort filtering.
600 static void
601 set_multicast_list(struct net_device *dev)
604 * I _could_ do up to 6 addresses here, but won't (yet?)
607 #if 0
608 int ioaddr = dev->base_addr;
610 * hmm, not even sure if my matching works _anyway_ - seem to be receiving
611 * _everything_ . . .
614 if (num_addrs) { /* Enable promiscuous mode */
615 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_ALL, SEEQ_CFG1);
616 dev->flags|=IFF_PROMISC;
617 } else { /* Disable promiscuous mode, use normal mode */
618 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_BROAD, SEEQ_CFG1);
620 #endif
623 void seeq8005_init(struct net_device *dev, int startp)
625 struct net_local *lp = (struct net_local *)dev->priv;
626 int ioaddr = dev->base_addr;
627 int i;
629 outw(SEEQCFG2_RESET, SEEQ_CFG2); /* reset device */
630 udelay(5);
632 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
633 outw( 0, SEEQ_DMAAR); /* load start address into both low and high byte */
634 /* wait_for_buffer(dev); */ /* I think that you only need a wait for memory buffer */
635 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
637 for(i=0;i<6;i++) { /* set Station address */
638 outb(dev->dev_addr[i], SEEQ_BUFFER);
639 udelay(2);
642 outw( SEEQCFG1_BUFFER_TEA, SEEQ_CFG1); /* set xmit end area pointer to 16K */
643 outb( DEFAULT_TEA, SEEQ_BUFFER); /* this gives us 16K of send buffer and 48K of recv buffer */
645 lp->receive_ptr = (DEFAULT_TEA+1)<<8; /* so we can find our packet_header */
646 outw( lp->receive_ptr, SEEQ_RPR); /* Receive Pointer Register is set to recv buffer memory */
648 outw( 0x00ff, SEEQ_REA); /* Receive Area End */
650 if (net_debug>4) {
651 printk("%s: SA0 = ",dev->name);
653 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
654 outw( 0, SEEQ_DMAAR);
655 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
657 for(i=0;i<6;i++) {
658 printk("%02x ",inb(SEEQ_BUFFER));
660 printk("\n");
663 outw( SEEQCFG1_MAC0_EN | SEEQCFG1_MATCH_BROAD | SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
664 outw( SEEQCFG2_AUTO_REA | SEEQCFG2_CTRLO, SEEQ_CFG2);
665 outw( SEEQCMD_SET_RX_ON | SEEQCMD_TX_INT_EN | SEEQCMD_RX_INT_EN, SEEQ_CMD);
667 if (net_debug>4) {
668 int old_cfg1;
669 old_cfg1 = inw(SEEQ_CFG1);
670 printk("%s: stat = 0x%04x\n",dev->name,inw(SEEQ_STATUS));
671 printk("%s: cfg1 = 0x%04x\n",dev->name,old_cfg1);
672 printk("%s: cfg2 = 0x%04x\n",dev->name,inw(SEEQ_CFG2));
673 printk("%s: raer = 0x%04x\n",dev->name,inw(SEEQ_REA));
674 printk("%s: dmaar= 0x%04x\n",dev->name,inw(SEEQ_DMAAR));
680 static void hardware_send_packet(struct net_device * dev, char *buf, int length)
682 int ioaddr = dev->base_addr;
683 int status = inw(SEEQ_STATUS);
684 int transmit_ptr = 0;
685 int tmp;
687 if (net_debug>4) {
688 printk("%s: send 0x%04x\n",dev->name,length);
691 /* Set FIFO to writemode and set packet-buffer address */
692 outw( SEEQCMD_FIFO_WRITE | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
693 outw( transmit_ptr, SEEQ_DMAAR);
695 /* output SEEQ Packet header barfage */
696 outw( htons(length + 4), SEEQ_BUFFER);
697 outw( SEEQPKTH_XMIT | SEEQPKTH_DATA_FOLLOWS | SEEQPKTH_XMIT_INT_EN, SEEQ_BUFFER );
699 /* blat the buffer */
700 outsw( SEEQ_BUFFER, buf, (length +1) >> 1);
701 /* paranoia !! */
702 outw( 0, SEEQ_BUFFER);
703 outw( 0, SEEQ_BUFFER);
705 /* set address of start of transmit chain */
706 outw( transmit_ptr, SEEQ_TPR);
708 /* drain FIFO */
709 tmp = jiffies;
710 while ( (((status=inw(SEEQ_STATUS)) & SEEQSTAT_FIFO_EMPTY) == 0) && (jiffies - tmp < HZ))
711 mb();
713 /* doit ! */
714 outw( SEEQCMD_WINDOW_INT_ACK | SEEQCMD_SET_TX_ON | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
720 * wait_for_buffer
722 * This routine waits for the SEEQ chip to assert that the FIFO is ready
723 * by checking for a window interrupt, and then clearing it
725 inline void wait_for_buffer(struct net_device * dev)
727 int ioaddr = dev->base_addr;
728 int tmp;
729 int status;
731 tmp = jiffies + HZ;
732 while ( ( ((status=inw(SEEQ_STATUS)) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, tmp))
733 mb();
735 if ( (status & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
736 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
739 #ifdef MODULE
741 static char devicename[9] = { 0, };
743 static struct net_device dev_seeq =
745 devicename, /* device name is inserted by linux/drivers/net/net_init.c */
746 0, 0, 0, 0,
747 0x300, 5,
748 0, 0, 0, NULL, seeq8005_probe
751 static int io=0x320;
752 static int irq=10;
753 MODULE_PARM(io, "i");
754 MODULE_PARM(irq, "i");
756 int init_module(void)
758 dev_seeq.irq=irq;
759 dev_seeq.base_addr=io;
760 if (register_netdev(&dev_seeq) != 0)
761 return -EIO;
762 return 0;
765 void cleanup_module(void)
768 * No need to check MOD_IN_USE, as sys_delete_module() checks.
771 unregister_netdev(&dev_seeq);
774 * Free up the private structure, or leak memory :-)
777 kfree(dev_seeq.priv);
778 dev_seeq.priv = NULL; /* gets re-allocated by el1_probe1 */
781 * If we don't do this, we can't re-insmod it later.
783 release_region(dev_seeq.base_addr, EL1_IO_EXTENT);
786 #endif /* MODULE */
789 * Local variables:
790 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c skeleton.c"
791 * version-control: t
792 * kept-new-versions: 5
793 * tab-width: 4
794 * End: