1 /* seeq8005.c: A network driver for linux. */
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 General 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";
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
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/fcntl.h>
37 #include <linux/interrupt.h>
38 #include <linux/ioport.h>
40 #include <linux/slab.h>
41 #include <linux/string.h>
42 #include <linux/init.h>
43 #include <linux/delay.h>
44 #include <linux/errno.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/bitops.h>
49 #include <linux/jiffies.h>
51 #include <asm/system.h>
57 /* First, a few definitions that the brave might change. */
58 /* A zero-terminated list of I/O addresses to be probed. */
59 static unsigned int seeq8005_portlist[] __initdata =
60 { 0x300, 0x320, 0x340, 0x360, 0};
62 /* use 0 for production, 1 for verification, >2 for debug */
66 static unsigned int net_debug = NET_DEBUG;
68 /* Information that need to be kept for each board. */
70 struct net_device_stats stats;
71 unsigned short receive_ptr; /* What address in packet memory do we expect a recv_pkt_header? */
72 long open_time; /* Useless example local info. */
75 /* The station (ethernet) address prefix, used for IDing the board. */
80 /* Index to functions, as function prototypes. */
82 static int seeq8005_probe1(struct net_device *dev, int ioaddr);
83 static int seeq8005_open(struct net_device *dev);
84 static void seeq8005_timeout(struct net_device *dev);
85 static int seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev);
86 static irqreturn_t 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.
104 static int io = 0x320;
107 struct net_device * __init seeq8005_probe(int unit)
109 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
114 return ERR_PTR(-ENODEV);
117 sprintf(dev->name, "eth%d", unit);
118 netdev_boot_setup_check(dev);
123 if (io > 0x1ff) { /* Check a single specified location. */
124 err = seeq8005_probe1(dev, io);
125 } else if (io != 0) { /* Don't probe at all. */
128 for (port = seeq8005_portlist; *port; port++) {
129 if (seeq8005_probe1(dev, *port) == 0)
137 err = register_netdev(dev);
142 release_region(dev->base_addr, SEEQ8005_IO_EXTENT);
148 /* This is the real probe routine. Linux has a history of friendly device
149 probes on the ISA bus. A good device probes avoids doing writes, and
150 verifies that the correct device exists and functions. */
152 static int __init seeq8005_probe1(struct net_device *dev, int ioaddr)
154 static unsigned version_printed;
156 unsigned char SA_prom[32];
164 if (!request_region(ioaddr, SEEQ8005_IO_EXTENT, "seeq8005"))
168 printk("seeq8005: probing at 0x%x\n",ioaddr);
170 old_stat = inw(SEEQ_STATUS); /* read status register */
171 if (old_stat == 0xffff) {
173 goto out; /* assume that 0xffff == no device */
175 if ( (old_stat & 0x1800) != 0x1800 ) { /* assume that unused bits are 1, as my manual says */
177 printk("seeq8005: reserved stat bits != 0x1800\n");
178 printk(" == 0x%04x\n",old_stat);
184 old_rear = inw(SEEQ_REA);
185 if (old_rear == 0xffff) {
187 if (inw(SEEQ_REA) == 0xffff) { /* assume that 0xffff == no device */
191 } else if ((old_rear & 0xff00) != 0xff00) { /* assume that unused bits are 1 */
193 printk("seeq8005: unused rear bits != 0xff00\n");
194 printk(" == 0x%04x\n",old_rear);
200 old_cfg2 = inw(SEEQ_CFG2); /* read CFG2 register */
201 old_cfg1 = inw(SEEQ_CFG1);
202 old_dmaar = inw(SEEQ_DMAAR);
205 printk("seeq8005: stat = 0x%04x\n",old_stat);
206 printk("seeq8005: cfg1 = 0x%04x\n",old_cfg1);
207 printk("seeq8005: cfg2 = 0x%04x\n",old_cfg2);
208 printk("seeq8005: raer = 0x%04x\n",old_rear);
209 printk("seeq8005: dmaar= 0x%04x\n",old_dmaar);
212 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD); /* setup for reading PROM */
213 outw( 0, SEEQ_DMAAR); /* set starting PROM address */
214 outw( SEEQCFG1_BUFFER_PROM, SEEQ_CFG1); /* set buffer to look at PROM */
218 for(i=0; i <32; i++) {
219 j+= SA_prom[i] = inw(SEEQ_BUFFER) & 0xff;
223 /* untested because I only have the one card */
224 if ( (j&0xff) != 0 ) { /* checksum appears to be 8bit = 0 */
225 if (net_debug>1) { /* check this before deciding that we have a card */
226 printk("seeq8005: prom sum error\n");
228 outw( old_stat, SEEQ_STATUS);
229 outw( old_dmaar, SEEQ_DMAAR);
230 outw( old_cfg1, SEEQ_CFG1);
236 outw( SEEQCFG2_RESET, SEEQ_CFG2); /* reset the card */
238 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
241 printk("seeq8005: prom sum = 0x%08x\n",j);
242 for(j=0; j<32; j+=16) {
243 printk("seeq8005: prom %02x: ",j);
245 printk("%02x ",SA_prom[j|i]);
249 if ((SA_prom[j|i]>31)&&(SA_prom[j|i]<127)) {
250 printk("%c", SA_prom[j|i]);
261 * testing the packet buffer memory doesn't work yet
262 * but all other buffer accesses do
263 * - fixing is not a priority
265 if (net_debug>1) { /* test packet buffer memory */
266 printk("seeq8005: testing packet buffer ... ");
267 outw( SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
268 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
269 outw( 0 , SEEQ_DMAAR);
270 for(i=0;i<32768;i++) {
271 outw(0x5a5a, SEEQ_BUFFER);
274 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_FIFO_EMPTY) != SEEQSTAT_FIFO_EMPTY) && time_before(jiffies, j) )
276 outw( 0 , SEEQ_DMAAR);
277 while ( ((inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, j+HZ))
279 if ( (inw(SEEQ_STATUS) & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
280 outw( SEEQCMD_WINDOW_INT_ACK | (inw(SEEQ_STATUS)& SEEQCMD_INT_MASK), SEEQ_CMD);
281 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
283 for(i=0;i<32768;i++) {
284 if (inw(SEEQ_BUFFER) != 0x5a5a)
295 if (net_debug && version_printed++ == 0)
298 printk("%s: %s found at %#3x, ", dev->name, "seeq8005", ioaddr);
300 /* Fill in the 'dev' fields. */
301 dev->base_addr = ioaddr;
304 /* Retrieve and print the ethernet address. */
305 for (i = 0; i < 6; i++)
306 printk(" %2.2x", dev->dev_addr[i] = SA_prom[i+6]);
308 if (dev->irq == 0xff)
309 ; /* Do nothing: a user-level program will set it. */
310 else if (dev->irq < 2) { /* "Auto-IRQ" */
311 unsigned long cookie = probe_irq_on();
313 outw( SEEQCMD_RX_INT_EN | SEEQCMD_SET_RX_ON | SEEQCMD_SET_RX_OFF, SEEQ_CMD );
315 dev->irq = probe_irq_off(cookie);
318 printk(" autoirq is %d\n", dev->irq);
319 } else if (dev->irq == 2)
320 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
321 * or don't know which one to set.
327 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", dev);
329 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
336 dev->open = seeq8005_open;
337 dev->stop = seeq8005_close;
338 dev->hard_start_xmit = seeq8005_send_packet;
339 dev->tx_timeout = seeq8005_timeout;
340 dev->watchdog_timeo = HZ/20;
341 dev->get_stats = seeq8005_get_stats;
342 dev->set_multicast_list = set_multicast_list;
343 dev->flags &= ~IFF_MULTICAST;
347 release_region(ioaddr, SEEQ8005_IO_EXTENT);
352 /* Open/initialize the board. This is called (in the current kernel)
353 sometime after booting when the 'ifconfig' program is run.
355 This routine should set everything up anew at each open, even
356 registers that "should" only need to be set once at boot, so that
357 there is non-reboot way to recover if something goes wrong.
359 static int seeq8005_open(struct net_device *dev)
361 struct net_local *lp = netdev_priv(dev);
364 int irqval = request_irq(dev->irq, &seeq8005_interrupt, 0, "seeq8005", dev);
366 printk ("%s: unable to get IRQ %d (irqval=%d).\n", dev->name,
372 /* Reset the hardware here. Don't forget to set the station address. */
373 seeq8005_init(dev, 1);
375 lp->open_time = jiffies;
377 netif_start_queue(dev);
381 static void seeq8005_timeout(struct net_device *dev)
383 int ioaddr = dev->base_addr;
384 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
385 tx_done(dev) ? "IRQ conflict" : "network cable problem");
386 /* Try to restart the adaptor. */
387 seeq8005_init(dev, 1);
388 dev->trans_start = jiffies;
389 netif_wake_queue(dev);
392 static int seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev)
394 struct net_local *lp = netdev_priv(dev);
395 short length = skb->len;
398 if (length < ETH_ZLEN) {
399 skb = skb_padto(skb, ETH_ZLEN);
406 /* Block a timer-based transmit from overlapping */
407 netif_stop_queue(dev);
409 hardware_send_packet(dev, buf, length);
410 dev->trans_start = jiffies;
411 lp->stats.tx_bytes += length;
413 /* You might need to clean up and record Tx statistics here. */
421 * This routine waits for the SEEQ chip to assert that the FIFO is ready
422 * by checking for a window interrupt, and then clearing it. This has to
423 * occur in the interrupt handler!
425 inline void wait_for_buffer(struct net_device * dev)
427 int ioaddr = dev->base_addr;
432 while ( ( ((status=inw(SEEQ_STATUS)) & SEEQSTAT_WINDOW_INT) != SEEQSTAT_WINDOW_INT) && time_before(jiffies, tmp))
435 if ( (status & SEEQSTAT_WINDOW_INT) == SEEQSTAT_WINDOW_INT)
436 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
439 /* The typical workload of the driver:
440 Handle the network interface interrupts. */
441 static irqreturn_t seeq8005_interrupt(int irq, void *dev_id, struct pt_regs * regs)
443 struct net_device *dev = dev_id;
444 struct net_local *lp;
445 int ioaddr, status, boguscount = 0;
448 ioaddr = dev->base_addr;
449 lp = netdev_priv(dev);
451 status = inw(SEEQ_STATUS);
454 printk("%s: int, status=0x%04x\n",dev->name,status);
457 if (status & SEEQSTAT_WINDOW_INT) {
459 outw( SEEQCMD_WINDOW_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
461 printk("%s: window int!\n",dev->name);
464 if (status & SEEQSTAT_TX_INT) {
466 outw( SEEQCMD_TX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
467 lp->stats.tx_packets++;
468 netif_wake_queue(dev); /* Inform upper layers. */
470 if (status & SEEQSTAT_RX_INT) {
472 /* Got a packet(s). */
475 status = inw(SEEQ_STATUS);
476 } while ( (++boguscount < 10) && (status & SEEQSTAT_ANY_INT)) ;
479 printk("%s: eoi\n",dev->name);
481 return IRQ_RETVAL(handled);
484 /* We have a good packet(s), get it/them out of the buffers. */
485 static void seeq8005_rx(struct net_device *dev)
487 struct net_local *lp = netdev_priv(dev);
490 int ioaddr = dev->base_addr;
498 status = inw(SEEQ_STATUS);
499 outw( lp->receive_ptr, SEEQ_DMAAR);
500 outw(SEEQCMD_FIFO_READ | SEEQCMD_RX_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
501 wait_for_buffer(dev);
502 next_packet = ntohs(inw(SEEQ_BUFFER));
503 pkt_hdr = inw(SEEQ_BUFFER);
506 printk("%s: 0x%04x recv next=0x%04x, hdr=0x%04x\n",dev->name,lp->receive_ptr,next_packet,pkt_hdr);
509 if ((next_packet == 0) || ((pkt_hdr & SEEQPKTH_CHAIN)==0)) { /* Read all the frames? */
510 return; /* Done for now */
513 if ((pkt_hdr & SEEQPKTS_DONE)==0)
516 if (next_packet < lp->receive_ptr) {
517 pkt_len = (next_packet + 0x10000 - ((DEFAULT_TEA+1)<<8)) - lp->receive_ptr - 4;
519 pkt_len = next_packet - lp->receive_ptr - 4;
522 if (next_packet < ((DEFAULT_TEA+1)<<8)) { /* is the next_packet address sane? */
523 printk("%s: recv packet ring corrupt, resetting board\n",dev->name);
524 seeq8005_init(dev,1);
528 lp->receive_ptr = next_packet;
531 printk("%s: recv len=0x%04x\n",dev->name,pkt_len);
534 if (pkt_hdr & SEEQPKTS_ANY_ERROR) { /* There was an error. */
535 lp->stats.rx_errors++;
536 if (pkt_hdr & SEEQPKTS_SHORT) lp->stats.rx_frame_errors++;
537 if (pkt_hdr & SEEQPKTS_DRIB) lp->stats.rx_frame_errors++;
538 if (pkt_hdr & SEEQPKTS_OVERSIZE) lp->stats.rx_over_errors++;
539 if (pkt_hdr & SEEQPKTS_CRC_ERR) lp->stats.rx_crc_errors++;
540 /* skip over this packet */
541 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_DMA_INT_ACK | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
542 outw( (lp->receive_ptr & 0xff00)>>8, SEEQ_REA);
544 /* Malloc up new buffer. */
548 skb = dev_alloc_skb(pkt_len);
550 printk("%s: Memory squeeze, dropping packet.\n", dev->name);
551 lp->stats.rx_dropped++;
555 skb_reserve(skb, 2); /* align data on 16 byte */
556 buf = skb_put(skb,pkt_len);
558 insw(SEEQ_BUFFER, buf, (pkt_len + 1) >> 1);
562 printk("%s: recv ",dev->name);
564 printk("%02x ",*(p++)&0xff);
569 skb->protocol=eth_type_trans(skb,dev);
571 dev->last_rx = jiffies;
572 lp->stats.rx_packets++;
573 lp->stats.rx_bytes += pkt_len;
575 } while ((--boguscount) && (pkt_hdr & SEEQPKTH_CHAIN));
577 /* If any worth-while packets have been received, netif_rx()
578 has done a mark_bh(NET_BH) for us and will work on them
579 when we get to the bottom-half routine. */
583 /* The inverse routine to net_open(). */
584 static int seeq8005_close(struct net_device *dev)
586 struct net_local *lp = netdev_priv(dev);
587 int ioaddr = dev->base_addr;
591 netif_stop_queue(dev);
593 /* Flush the Tx and disable Rx here. */
594 outw( SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
596 free_irq(dev->irq, dev);
598 /* Update the statistics here. */
604 /* Get the current statistics. This may be called with the card open or
606 static struct net_device_stats *seeq8005_get_stats(struct net_device *dev)
608 struct net_local *lp = netdev_priv(dev);
613 /* Set or clear the multicast filter for this adaptor.
614 num_addrs == -1 Promiscuous mode, receive all packets
615 num_addrs == 0 Normal mode, clear multicast list
616 num_addrs > 0 Multicast mode, receive normal and MC packets, and do
617 best-effort filtering.
619 static void set_multicast_list(struct net_device *dev)
622 * I _could_ do up to 6 addresses here, but won't (yet?)
626 int ioaddr = dev->base_addr;
628 * hmm, not even sure if my matching works _anyway_ - seem to be receiving
632 if (num_addrs) { /* Enable promiscuous mode */
633 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_ALL, SEEQ_CFG1);
634 dev->flags|=IFF_PROMISC;
635 } else { /* Disable promiscuous mode, use normal mode */
636 outw( (inw(SEEQ_CFG1) & ~SEEQCFG1_MATCH_MASK)| SEEQCFG1_MATCH_BROAD, SEEQ_CFG1);
641 void seeq8005_init(struct net_device *dev, int startp)
643 struct net_local *lp = netdev_priv(dev);
644 int ioaddr = dev->base_addr;
647 outw(SEEQCFG2_RESET, SEEQ_CFG2); /* reset device */
650 outw( SEEQCMD_FIFO_WRITE | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
651 outw( 0, SEEQ_DMAAR); /* load start address into both low and high byte */
652 /* wait_for_buffer(dev); */ /* I think that you only need a wait for memory buffer */
653 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
655 for(i=0;i<6;i++) { /* set Station address */
656 outb(dev->dev_addr[i], SEEQ_BUFFER);
660 outw( SEEQCFG1_BUFFER_TEA, SEEQ_CFG1); /* set xmit end area pointer to 16K */
661 outb( DEFAULT_TEA, SEEQ_BUFFER); /* this gives us 16K of send buffer and 48K of recv buffer */
663 lp->receive_ptr = (DEFAULT_TEA+1)<<8; /* so we can find our packet_header */
664 outw( lp->receive_ptr, SEEQ_RPR); /* Receive Pointer Register is set to recv buffer memory */
666 outw( 0x00ff, SEEQ_REA); /* Receive Area End */
669 printk("%s: SA0 = ",dev->name);
671 outw( SEEQCMD_FIFO_READ | SEEQCMD_SET_ALL_OFF, SEEQ_CMD);
672 outw( 0, SEEQ_DMAAR);
673 outw( SEEQCFG1_BUFFER_MAC0, SEEQ_CFG1);
676 printk("%02x ",inb(SEEQ_BUFFER));
681 outw( SEEQCFG1_MAC0_EN | SEEQCFG1_MATCH_BROAD | SEEQCFG1_BUFFER_BUFFER, SEEQ_CFG1);
682 outw( SEEQCFG2_AUTO_REA | SEEQCFG2_CTRLO, SEEQ_CFG2);
683 outw( SEEQCMD_SET_RX_ON | SEEQCMD_TX_INT_EN | SEEQCMD_RX_INT_EN, SEEQ_CMD);
687 old_cfg1 = inw(SEEQ_CFG1);
688 printk("%s: stat = 0x%04x\n",dev->name,inw(SEEQ_STATUS));
689 printk("%s: cfg1 = 0x%04x\n",dev->name,old_cfg1);
690 printk("%s: cfg2 = 0x%04x\n",dev->name,inw(SEEQ_CFG2));
691 printk("%s: raer = 0x%04x\n",dev->name,inw(SEEQ_REA));
692 printk("%s: dmaar= 0x%04x\n",dev->name,inw(SEEQ_DMAAR));
698 static void hardware_send_packet(struct net_device * dev, char *buf, int length)
700 int ioaddr = dev->base_addr;
701 int status = inw(SEEQ_STATUS);
702 int transmit_ptr = 0;
706 printk("%s: send 0x%04x\n",dev->name,length);
709 /* Set FIFO to writemode and set packet-buffer address */
710 outw( SEEQCMD_FIFO_WRITE | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
711 outw( transmit_ptr, SEEQ_DMAAR);
713 /* output SEEQ Packet header barfage */
714 outw( htons(length + 4), SEEQ_BUFFER);
715 outw( SEEQPKTH_XMIT | SEEQPKTH_DATA_FOLLOWS | SEEQPKTH_XMIT_INT_EN, SEEQ_BUFFER );
717 /* blat the buffer */
718 outsw( SEEQ_BUFFER, buf, (length +1) >> 1);
720 outw( 0, SEEQ_BUFFER);
721 outw( 0, SEEQ_BUFFER);
723 /* set address of start of transmit chain */
724 outw( transmit_ptr, SEEQ_TPR);
728 while ( (((status=inw(SEEQ_STATUS)) & SEEQSTAT_FIFO_EMPTY) == 0) && time_before(jiffies, tmp + HZ))
732 outw( SEEQCMD_WINDOW_INT_ACK | SEEQCMD_SET_TX_ON | (status & SEEQCMD_INT_MASK), SEEQ_CMD);
739 static struct net_device *dev_seeq;
740 MODULE_LICENSE("GPL");
741 module_param(io, int, 0);
742 module_param(irq, int, 0);
743 MODULE_PARM_DESC(io, "SEEQ 8005 I/O base address");
744 MODULE_PARM_DESC(irq, "SEEQ 8005 IRQ number");
746 int init_module(void)
748 dev_seeq = seeq8005_probe(-1);
749 if (IS_ERR(dev_seeq))
750 return PTR_ERR(dev_seeq);
754 void cleanup_module(void)
756 unregister_netdev(dev_seeq);
757 release_region(dev_seeq->base_addr, SEEQ8005_IO_EXTENT);
758 free_netdev(dev_seeq);
765 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c skeleton.c"
767 * kept-new-versions: 5