1 /* Intel Professional Workstation/panther ethernet driver */
2 /* lp486e.c: A panther 82596 ethernet driver for linux. */
4 History and copyrights:
7 Written 1993 by Donald Becker.
8 Copyright 1993 United States Government as represented by the Director,
9 National Security Agency. This software may only be used and
10 distributed according to the terms of the GNU General Public License
11 as modified by SRC, incorporated herein by reference.
13 The author may be reached as becker@scyld.com, or C/O
14 Scyld Computing Corporation
15 410 Severn Ave., Suite 210
19 Written 1994 by Mark Evans.
20 This driver is for the Apricot 82596 bus-master interface
22 Modularised 12/94 Mark Evans
24 Professional Workstation
25 Derived from apricot.c by Ard van Breemen
26 <ard@murphy.nl>|<ard@cstmel.hobby.nl>|<ard@cstmel.nl.eu.org>
29 Thanks to Murphy Software BV for letting me write this in their time.
30 Well, actually, I get payed doing this...
31 (Also: see http://www.murphy.nl for murphy, and my homepage ~ard for
32 more information on the Professional Workstation)
38 There are currently two motherboards that I know of in the
39 professional workstation. The only one that I know is the
40 intel panther motherboard. -- ard
43 The pws is equipped with an intel 82596. This is a very intelligent controller
44 which runs its own micro-code. Communication with the hostprocessor is done
45 through linked lists of commands and buffers in the hostprocessors memory.
46 A complete description of the 82596 is available from intel. Search for
47 a file called "29021806.pdf". It is a complete description of the chip itself.
48 To use it for the pws some additions are needed regarding generation of
49 the PORT and CA signal, and the interrupt glue needed for a pc.
51 PORT SIZE ACTION MEANING
52 0xCB0 2 WRITE Lower 16 bits for PORT command
53 0xCB2 2 WRITE Upper 16 bits for PORT command, and issue of PORT command
54 0xCB4 1 WRITE Generation of CA signal
55 0xCB8 1 WRITE Clear interrupt glue
56 All other communication is through memory!
59 #define SLOW_DOWN_IO udelay(5);
61 #include <linux/module.h>
62 #include <linux/init.h>
63 #include <linux/delay.h>
64 #include <linux/kernel.h>
65 #include <linux/sched.h>
66 #include <linux/string.h>
67 #include <linux/ptrace.h>
68 #include <linux/errno.h>
69 #include <linux/ioport.h>
70 #include <linux/slab.h>
71 #include <linux/interrupt.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
74 #include <linux/skbuff.h>
76 #include <asm/bitops.h>
80 /* debug print flags */
81 #define LOG_SRCDST 0x80000000
82 #define LOG_STATINT 0x40000000
83 #define LOG_STARTINT 0x20000000
85 #define i596_debug debug
87 static int i596_debug = 0;
89 static const char * const medianame[] = {
91 "10baseT-FD", "AUI-FD",
94 #define LP486E_TOTAL_SIZE 16
96 #define I596_NULL (0xffffffff)
98 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
99 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
100 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
102 #define CMD_FLEX 0x0008 /* Enable flexible memory model */
108 CmdMulticastList = 3,
115 char *CUcmdnames[8] = { "NOP", "IASetup", "Configure", "MulticastList",
116 "Tx", "TDR", "Dump", "Diagnose" };
118 /* Status word bits */
119 #define STAT_CX 0x8000 /* The CU finished executing a command
120 with the Interrupt bit set */
121 #define STAT_FR 0x4000 /* The RU finished receiving a frame */
122 #define STAT_CNA 0x2000 /* The CU left the active state */
123 #define STAT_RNR 0x1000 /* The RU left the active state */
124 #define STAT_ACK (STAT_CX | STAT_FR | STAT_CNA | STAT_RNR)
125 #define STAT_CUS 0x0700 /* Status of CU: 0: idle, 1: suspended,
126 2: active, 3-7: unused */
127 #define STAT_RUS 0x00f0 /* Status of RU: 0: idle, 1: suspended,
128 2: no resources, 4: ready,
129 10: no resources due to no more RBDs,
130 12: no more RBDs, other: unused */
131 #define STAT_T 0x0008 /* Bus throttle timers loaded */
132 #define STAT_ZERO 0x0807 /* Always zero */
135 static char *CUstates[8] = {
136 "idle", "suspended", "active", 0, 0, 0, 0, 0
138 static char *RUstates[16] = {
139 "idle", "suspended", "no resources", 0, "ready", 0, 0, 0,
140 0, 0, "no RBDs", 0, "out of RBDs", 0, 0, 0
144 i596_out_status(int status) {
148 printk("status %4.4x:", status);
149 if (status == 0xffff)
150 printk(" strange..\n");
152 if (status & STAT_CX)
154 if (status & STAT_CNA)
155 printk(" CU stopped");
156 if (status & STAT_FR)
157 printk(" got a frame");
158 if (status & STAT_RNR)
159 printk(" RU stopped");
161 printk(" throttled");
162 if (status & STAT_ZERO)
164 s = CUstates[(status & STAT_CUS) >> 8];
168 printk(" CU(%s)", s);
169 s = RUstates[(status & STAT_RUS) >> 4];
173 printk(" RU(%s)", s);
175 printk(" bad status");
181 /* Command word bits */
182 #define ACK_CX 0x8000
183 #define ACK_FR 0x4000
184 #define ACK_CNA 0x2000
185 #define ACK_RNR 0x1000
187 #define CUC_START 0x0100
188 #define CUC_RESUME 0x0200
189 #define CUC_SUSPEND 0x0300
190 #define CUC_ABORT 0x0400
192 #define RX_START 0x0010
193 #define RX_RESUME 0x0020
194 #define RX_SUSPEND 0x0030
195 #define RX_ABORT 0x0040
197 typedef u32 phys_addr;
199 static inline phys_addr
200 va_to_pa(volatile void *x) {
201 return x ? virt_to_bus(x) : I596_NULL;
205 pa_to_va(phys_addr x) {
206 return (x == I596_NULL) ? NULL : bus_to_virt(x);
209 /* status bits for cmd */
210 #define CMD_STAT_C 0x8000 /* CU command complete */
211 #define CMD_STAT_B 0x4000 /* CU command in progress */
212 #define CMD_STAT_OK 0x2000 /* CU command completed without errors */
213 #define CMD_STAT_A 0x1000 /* CU command abnormally terminated */
215 struct i596_cmd { /* 8 bytes */
216 unsigned short status;
217 unsigned short command;
218 phys_addr pa_next; /* va_to_pa(struct i596_cmd *next) */
222 #define SIZE_MASK 0x3fff
227 phys_addr pa_next; /* va_to_pa(struct i596_tbd *next) */
228 phys_addr pa_data; /* va_to_pa(char *data) */
234 phys_addr pa_tbd; /* va_to_pa(struct i596_tbd *tbd) */
239 /* status bits for rfd */
240 #define RFD_STAT_C 0x8000 /* Frame reception complete */
241 #define RFD_STAT_B 0x4000 /* Frame reception in progress */
242 #define RFD_STAT_OK 0x2000 /* Frame received without errors */
243 #define RFD_STATUS 0x1fff
244 #define RFD_LENGTH_ERR 0x1000
245 #define RFD_CRC_ERR 0x0800
246 #define RFD_ALIGN_ERR 0x0400
247 #define RFD_NOBUFS_ERR 0x0200
248 #define RFD_DMA_ERR 0x0100 /* DMA overrun failure to acquire system bus */
249 #define RFD_SHORT_FRAME_ERR 0x0080
250 #define RFD_NOEOP_ERR 0x0040
251 #define RFD_TRUNC_ERR 0x0020
252 #define RFD_MULTICAST 0x0002 /* 0: destination had our address
253 1: destination was broadcast/multicast */
254 #define RFD_COLLISION 0x0001
256 /* receive frame descriptor */
260 phys_addr pa_next; /* va_to_pa(struct i596_rfd *next) */
261 phys_addr pa_rbd; /* va_to_pa(struct i596_rbd *rbd) */
262 unsigned short count;
267 #define RBD_EL 0x8000
269 #define RBD_SIZEMASK 0x3fff
270 #define RBD_EOF 0x8000
273 /* receive buffer descriptor */
277 phys_addr pa_next; /* va_to_pa(struct i596_tbd *next) */
278 phys_addr pa_data; /* va_to_pa(char *data) */
279 phys_addr pa_prev; /* va_to_pa(struct i596_tbd *prev) */
281 /* Driver private part */
285 #define RX_RING_SIZE 64
286 #define RX_SKBSIZE (ETH_FRAME_LEN+10)
287 #define RX_RBD_SIZE 32
289 /* System Control Block - 40 bytes */
293 phys_addr pa_cmd; /* 4 - va_to_pa(struct i596_cmd *cmd) */
294 phys_addr pa_rfd; /* 8 - va_to_pa(struct i596_rfd *rfd) */
295 u32 crc_err; /* 12 */
296 u32 align_err; /* 16 */
297 u32 resource_err; /* 20 */
298 u32 over_err; /* 24 */
299 u32 rcvdt_err; /* 28 */
300 u32 short_err; /* 32 */
305 /* Intermediate System Configuration Pointer - 8 bytes */
308 phys_addr pa_scb; /* 4 - va_to_pa(struct i596_scb *scb) */
311 /* System Configuration Pointer - 12 bytes */
315 phys_addr pa_iscp; /* 8 - va_to_pa(struct i596_iscp *iscp) */
318 /* Selftest and dump results - needs 16-byte alignment */
320 * The size of the dump area is 304 bytes. When the dump is executed
321 * by the Port command an extra word will be appended to the dump area.
322 * The extra word is a copy of the Dump status word (containing the
323 * C, B, OK bits). [I find 0xa006, with a0 for C+OK and 6 for dump]
326 u16 dump[153]; /* (304 = 130h) + 2 bytes */
329 struct i596_private { /* aligned to a 16-byte boundary */
330 struct i596_scp scp; /* 0 - needs 16-byte alignment */
331 struct i596_iscp iscp; /* 12 */
332 struct i596_scb scb; /* 20 */
334 struct i596_dump dump; /* 64 - needs 16-byte alignment */
336 struct i596_cmd set_add;
337 char eth_addr[8]; /* directly follows set_add */
339 struct i596_cmd set_conf;
340 char i596_config[16]; /* directly follows set_conf */
343 unsigned long tdr_stat; /* directly follows tdr */
346 volatile struct i596_rbd *rbd_list;
347 volatile struct i596_rbd *rbd_tail;
348 volatile struct i596_rfd *rx_tail;
349 volatile struct i596_cmd *cmd_tail;
350 volatile struct i596_cmd *cmd_head;
352 unsigned long last_cmd;
353 struct net_device_stats stats;
356 static char init_setup[14] = {
357 0x8E, /* length 14 bytes, prefetch on */
358 0xC8, /* default: fifo to 8, monitor off */
359 0x40, /* default: don't save bad frames (apricot.c had 0x80) */
360 0x2E, /* (default is 0x26)
361 No source address insertion, 8 byte preamble */
362 0x00, /* default priority and backoff */
363 0x60, /* default interframe spacing */
364 0x00, /* default slot time LSB */
365 0xf2, /* default slot time and nr of retries */
366 0x00, /* default various bits
367 (0: promiscuous mode, 1: broadcast disable,
368 2: encoding mode, 3: transmit on no CRS,
369 4: no CRC insertion, 5: CRC type,
370 6: bit stuffing, 7: padding) */
371 0x00, /* default carrier sense and collision detect */
372 0x40, /* default minimum frame length */
373 0xff, /* (default is 0xff, and that is what apricot.c has;
374 elp486.c has 0xfb: Enable crc append in memory.) */
375 0x00, /* default: not full duplex */
376 0x7f /* (default is 0x3f) multi IA */
379 static int i596_open(struct net_device *dev);
380 static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
381 static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);
382 static int i596_close(struct net_device *dev);
383 static struct net_device_stats *i596_get_stats(struct net_device *dev);
384 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
385 static void print_eth(char *);
386 static void set_multicast_list(struct net_device *dev);
387 static void i596_tx_timeout(struct net_device *dev);
390 i596_timeout(struct net_device *dev, char *msg, int ct) {
391 volatile struct i596_private *lp;
394 lp = (struct i596_private *) dev->priv;
395 while (lp->scb.command) {
396 if (--boguscnt == 0) {
397 printk("%s: %s timed out - stat %4.4x, cmd %4.4x\n",
399 lp->scb.status, lp->scb.command);
408 init_rx_bufs(struct net_device *dev, int num) {
409 volatile struct i596_private *lp;
410 struct i596_rfd *rfd;
412 // struct i596_rbd *rbd;
414 lp = (struct i596_private *) dev->priv;
415 lp->scb.pa_rfd = I596_NULL;
417 for (i = 0; i < num; i++) {
418 rfd = kmalloc(sizeof(struct i596_rfd), GFP_KERNEL);
423 rfd->pa_rbd = I596_NULL;
432 rfd->pa_next = lp->scb.pa_rfd;
433 lp->scb.pa_rfd = va_to_pa(rfd);
434 lp->rx_tail->pa_next = lp->scb.pa_rfd;
438 for (i = 0; i<RX_RBD_SIZE; i++) {
439 rbd = kmalloc(sizeof(struct i596_rbd), GFP_KERNEL);
443 rbd->skb = dev_alloc_skb(RX_SKB_SIZE);
445 printk("dev_alloc_skb failed");
447 rbd->next = rfd->rbd;
449 rfd->rbd->prev = rbd;
450 rbd->size = RX_SKB_SIZE;
452 rbd->size = (RX_SKB_SIZE | RBD_EL);
458 printk("Could not kmalloc rbd\n");
461 lp->rbd_tail->next = rfd->rbd;
467 remove_rx_bufs(struct net_device *dev) {
468 struct i596_private *lp;
469 struct i596_rfd *rfd;
471 lp = (struct i596_private *) dev->priv;
472 lp->rx_tail->pa_next = I596_NULL;
475 rfd = pa_to_va(lp->scb.pa_rfd);
476 lp->scb.pa_rfd = rfd->pa_next;
478 } while (rfd != lp->rx_tail);
488 #define PORT_RESET 0x00 /* reset 82596 */
489 #define PORT_SELFTEST 0x01 /* selftest */
490 #define PORT_ALTSCP 0x02 /* alternate SCB address */
491 #define PORT_DUMP 0x03 /* dump */
493 #define IOADDR 0xcb0 /* real constant */
494 #define IRQ 10 /* default IRQ - can be changed by ECU */
496 /* The 82596 requires two 16-bit write cycles for a port command */
498 PORT(phys_addr a, unsigned int cmd) {
500 printk("lp486e.c: PORT: address not aligned\n");
501 outw(((a & 0xffff) | cmd), IOADDR);
502 outw(((a>>16) & 0xffff), IOADDR+2);
516 #define SIZE(x) (sizeof(x)/sizeof((x)[0]))
519 /* selftest or dump */
521 i596_port_do(struct net_device *dev, int portcmd, char *cmdname) {
522 volatile struct i596_private *lp = dev->priv;
526 memset((void *)&(lp->dump), 0, sizeof(struct i596_dump));
527 outp = &(lp->dump.dump[0]);
529 PORT(va_to_pa(outp), portcmd);
530 mdelay(30); /* random, unmotivated */
532 printk("lp486e i82596 %s result:\n", cmdname);
533 for (m = SIZE(lp->dump.dump); m && lp->dump.dump[m-1] == 0; m--)
535 for (i = 0; i < m; i++) {
536 printk(" %04x", lp->dump.dump[i]);
545 i596_scp_setup(struct net_device *dev) {
546 volatile struct i596_private *lp = dev->priv;
549 /* Setup SCP, ISCP, SCB */
552 * only a single byte is significant - here 0x44
553 * 0x80: big endian mode (details depend on stepping)
555 * 0x20: interrupt pin is active low
556 * 0x10: lock function disabled
557 * 0x08: external triggering of bus throttle timers
558 * 0x06: 00: 82586 compat mode, 01: segmented mode, 10: linear mode
561 lp->scp.sysbus = 0x00440000; /* linear mode */
562 lp->scp.pad = 0; /* must be zero */
563 lp->scp.pa_iscp = va_to_pa(&(lp->iscp));
566 * The CPU sets the ISCP to 1 before it gives the first CA()
568 lp->iscp.busy = 0x0001;
569 lp->iscp.pa_scb = va_to_pa(&(lp->scb));
573 lp->scb.pa_cmd = I596_NULL;
574 /* lp->scb.pa_rfd has been initialised already */
576 lp->last_cmd = jiffies;
582 * We need to wait 10 systemclock cycles, and
583 * 5 serial clock cycles.
585 PORT(0, PORT_RESET); /* address part ignored */
589 * Before the CA signal is asserted, the default SCP address
590 * (0x00fffff4) can be changed to a 16-byte aligned value
592 PORT(va_to_pa(&lp->scp), PORT_ALTSCP); /* change the scp address */
595 * The initialization procedure begins when a
596 * Channel Attention signal is asserted after a reset.
602 * The ISCP busy is cleared by the 82596 after the SCB address is read.
605 while (lp->iscp.busy) {
606 if (--boguscnt == 0) {
607 /* No i82596 present? */
608 printk("%s: i82596 initialization timed out\n",
614 /* I find here boguscnt==100, so no delay was required. */
620 init_i596(struct net_device *dev) {
621 volatile struct i596_private *lp;
623 if (i596_scp_setup(dev))
626 lp = (struct i596_private *) dev->priv;
629 memcpy ((void *)lp->i596_config, init_setup, 14);
630 lp->set_conf.command = CmdConfigure;
631 i596_add_cmd(dev, (void *)&lp->set_conf);
633 memcpy ((void *)lp->eth_addr, dev->dev_addr, 6);
634 lp->set_add.command = CmdIASetup;
635 i596_add_cmd(dev, (struct i596_cmd *)&lp->set_add);
637 lp->tdr.command = CmdTDR;
638 i596_add_cmd(dev, (struct i596_cmd *)&lp->tdr);
640 if (lp->scb.command && i596_timeout(dev, "i82596 init", 200))
643 lp->scb.command = RX_START;
646 if (lp->scb.command && i596_timeout(dev, "Receive Unit start", 100))
652 /* Receive a single frame */
654 i596_rx_one(struct net_device *dev, volatile struct i596_private *lp,
655 struct i596_rfd *rfd, int *frames) {
657 if (rfd->stat & RFD_STAT_OK) {
659 int pkt_len = (rfd->count & 0x3fff);
660 struct sk_buff *skb = dev_alloc_skb(pkt_len);
664 if (rfd->cmd & CMD_EOL)
665 printk("Received on EOL\n");
668 printk ("%s: i596_rx Memory squeeze, "
669 "dropping packet.\n", dev->name);
670 lp->stats.rx_dropped++;
675 memcpy(skb_put(skb,pkt_len), rfd->data, pkt_len);
677 skb->protocol = eth_type_trans(skb,dev);
679 lp->stats.rx_packets++;
682 printk("Frame reception error status %04x\n",
685 lp->stats.rx_errors++;
686 if (rfd->stat & RFD_COLLISION)
687 lp->stats.collisions++;
688 if (rfd->stat & RFD_SHORT_FRAME_ERR)
689 lp->stats.rx_length_errors++;
690 if (rfd->stat & RFD_DMA_ERR)
691 lp->stats.rx_over_errors++;
692 if (rfd->stat & RFD_NOBUFS_ERR)
693 lp->stats.rx_fifo_errors++;
694 if (rfd->stat & RFD_ALIGN_ERR)
695 lp->stats.rx_frame_errors++;
696 if (rfd->stat & RFD_CRC_ERR)
697 lp->stats.rx_crc_errors++;
698 if (rfd->stat & RFD_LENGTH_ERR)
699 lp->stats.rx_length_errors++;
701 rfd->stat = rfd->count = 0;
706 i596_rx(struct net_device *dev) {
707 volatile struct i596_private *lp = (struct i596_private *) dev->priv;
708 struct i596_rfd *rfd;
712 rfd = pa_to_va(lp->scb.pa_rfd);
714 printk("i596_rx: NULL rfd?\n");
718 if (rfd->stat && !(rfd->stat & (RFD_STAT_C | RFD_STAT_B)))
719 printk("SF:%p-%04x\n", rfd, rfd->stat);
721 if (!(rfd->stat & RFD_STAT_C))
722 break; /* next one not ready */
723 if (i596_rx_one(dev, lp, rfd, &frames))
724 break; /* out of memory */
726 lp->rx_tail->cmd = 0;
728 lp->scb.pa_rfd = rfd->pa_next;
735 i596_cleanup_cmd(struct net_device *dev) {
736 volatile struct i596_private *lp;
737 struct i596_cmd *cmd;
739 lp = (struct i596_private *) dev->priv;
740 while (lp->cmd_head) {
741 cmd = (struct i596_cmd *)lp->cmd_head;
743 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
746 switch ((cmd->command) & 0x7) {
748 struct tx_cmd *tx_cmd = (struct tx_cmd *) cmd;
749 struct i596_tbd * tx_cmd_tbd;
750 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
752 dev_kfree_skb_any(tx_cmd_tbd->skb);
754 lp->stats.tx_errors++;
755 lp->stats.tx_aborted_errors++;
757 cmd->pa_next = I596_NULL;
758 kfree((unsigned char *)tx_cmd);
759 netif_wake_queue(dev);
762 case CmdMulticastList: {
763 // unsigned short count = *((unsigned short *) (ptr + 1));
765 cmd->pa_next = I596_NULL;
766 kfree((unsigned char *)cmd);
770 cmd->pa_next = I596_NULL;
776 if (lp->scb.command && i596_timeout(dev, "i596_cleanup_cmd", 100))
779 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
783 i596_reset(struct net_device *dev,
784 volatile struct i596_private *lp, int ioaddr) {
786 if (lp->scb.command && i596_timeout(dev, "i596_reset", 100))
789 netif_stop_queue(dev);
791 lp->scb.command = CUC_ABORT | RX_ABORT;
794 /* wait for shutdown */
795 if (lp->scb.command && i596_timeout(dev, "i596_reset(2)", 400))
798 i596_cleanup_cmd(dev);
801 netif_start_queue(dev);
802 /*dev_kfree_skb(skb, FREE_WRITE);*/
806 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) {
807 volatile struct i596_private *lp = dev->priv;
808 int ioaddr = dev->base_addr;
812 cmd->command |= (CMD_EOL | CMD_INTR);
813 cmd->pa_next = I596_NULL;
818 lp->cmd_tail->pa_next = va_to_pa(cmd);
821 if (lp->scb.command && i596_timeout(dev, "i596_add_cmd", 100))
823 lp->scb.pa_cmd = va_to_pa(cmd);
824 lp->scb.command = CUC_START;
830 lp->cmd_head = pa_to_va(lp->scb.pa_cmd);
831 restore_flags(flags);
833 if (lp->cmd_backlog > 16) {
834 int tickssofar = jiffies - lp->last_cmd;
835 if (tickssofar < 25) return;
837 printk("%s: command unit timed out, status resetting.\n",
839 i596_reset(dev, lp, ioaddr);
844 i596_open(struct net_device *dev) {
847 i = request_irq(dev->irq, &i596_interrupt, SA_SHIRQ, dev->name, dev);
849 printk("%s: IRQ %d not free\n", dev->name, dev->irq);
853 if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE)
854 printk("%s: only able to allocate %d receive buffers\n",
859 free_irq(dev->irq, dev);
863 netif_start_queue(dev);
867 return 0; /* Always succeed */
871 i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
872 volatile struct i596_private *lp = dev->priv;
873 struct tx_cmd *tx_cmd;
876 /* If some higher level thinks we've missed a tx-done interrupt
877 we are passed NULL. n.b. dev_tint handles the cli()/sti()
880 printk ("What about dev_tint\n");
885 /* shouldn't happen */
889 length = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
890 dev->trans_start = jiffies;
892 tx_cmd = (struct tx_cmd *)
893 kmalloc ((sizeof (struct tx_cmd)
894 + sizeof (struct i596_tbd)), GFP_ATOMIC);
895 if (tx_cmd == NULL) {
896 printk ("%s: i596_xmit Memory squeeze, dropping packet.\n",
898 lp->stats.tx_dropped++;
902 struct i596_tbd *tx_cmd_tbd;
903 tx_cmd_tbd = (struct i596_tbd *) (tx_cmd + 1);
904 tx_cmd->pa_tbd = va_to_pa (tx_cmd_tbd);
905 tx_cmd_tbd->pa_next = I596_NULL;
907 tx_cmd->cmd.command = (CMD_FLEX | CmdTx);
912 tx_cmd_tbd->size = (EOF | length);
914 tx_cmd_tbd->pa_data = va_to_pa (skb->data);
915 tx_cmd_tbd->skb = skb;
917 if (i596_debug & LOG_SRCDST)
918 print_eth (skb->data);
920 i596_add_cmd (dev, (struct i596_cmd *) tx_cmd);
922 lp->stats.tx_packets++;
929 i596_tx_timeout (struct net_device *dev) {
930 volatile struct i596_private *lp = dev->priv;
931 int ioaddr = dev->base_addr;
933 /* Transmitter timeout, serious problems. */
934 printk ("%s: transmit timed out, status resetting.\n", dev->name);
935 lp->stats.tx_errors++;
937 /* Try to restart the adaptor */
938 if (lp->last_restart == lp->stats.tx_packets) {
939 printk ("Resetting board.\n");
941 /* Shutdown and restart */
942 i596_reset (dev, lp, ioaddr);
944 /* Issue a channel attention signal */
945 printk ("Kicking board.\n");
946 lp->scb.command = (CUC_START | RX_START);
948 lp->last_restart = lp->stats.tx_packets;
950 netif_wake_queue(dev);
954 print_eth(char *add) {
958 for (i = 0; i < 6; i++)
959 printk(" %2.2X", (unsigned char) add[i]);
963 for (i = 0; i < 6; i++)
964 printk(" %2.2X", (unsigned char) add[i+6]);
967 printk ("type %2.2X%2.2X\n",
968 (unsigned char) add[12], (unsigned char) add[13]);
972 lp486e_probe(struct net_device *dev) {
973 volatile struct i596_private *lp;
974 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 };
984 if (!request_region(IOADDR, LP486E_TOTAL_SIZE, dev->name)) {
985 printk(KERN_ERR "lp486e: IO address 0x%x in use\n", IOADDR);
990 * Allocate working memory, 16-byte aligned
992 dev->mem_start = (unsigned long)
993 kmalloc(sizeof(struct i596_private) + 0x0f, GFP_KERNEL);
996 dev->priv = (void *)((dev->mem_start + 0xf) & 0xfffffff0);
997 lp = (struct i596_private *) dev->priv;
998 memset((void *)lp, 0, sizeof(struct i596_private));
1001 * Do we really have this thing?
1003 if (i596_scp_setup(dev)) {
1008 dev->base_addr = IOADDR;
1014 * How do we find the ethernet address? I don't know.
1015 * One possibility is to look at the EISA configuration area
1016 * [0xe8000-0xe9fff]. This contains the ethernet address
1017 * but not at a fixed address - things depend on setup options.
1019 * If we find no address, or the wrong address, use
1020 * ifconfig eth0 hw ether a1:a2:a3:a4:a5:a6
1021 * with the value found in the BIOS setup.
1023 bios = bus_to_virt(0xe8000);
1024 for (j = 0; j < 0x2000; j++) {
1025 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) {
1026 printk("%s: maybe address at BIOS 0x%x:",
1027 dev->name, 0xe8000+j);
1028 for (i = 0; i < 6; i++) {
1029 eth_addr[i] = bios[i+j];
1030 printk(" %2.2X", eth_addr[i]);
1036 printk("%s: lp486e 82596 at %#3lx, IRQ %d,",
1037 dev->name, dev->base_addr, dev->irq);
1038 for (i = 0; i < 6; i++)
1039 printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]);
1042 /* The LP486E-specific entries in the device structure. */
1043 dev->open = &i596_open;
1044 dev->stop = &i596_close;
1045 dev->hard_start_xmit = &i596_start_xmit;
1046 dev->get_stats = &i596_get_stats;
1047 dev->set_multicast_list = &set_multicast_list;
1048 dev->watchdog_timeo = 5*HZ;
1049 dev->tx_timeout = i596_tx_timeout;
1052 /* selftest reports 0x320925ae - don't know what that means */
1053 i596_port_do(dev, PORT_SELFTEST, "selftest");
1054 i596_port_do(dev, PORT_DUMP, "dump");
1059 kfree ((void *) dev->mem_start);
1061 release_region(IOADDR, LP486E_TOTAL_SIZE);
1066 i596_handle_CU_completion(struct net_device *dev,
1067 volatile struct i596_private *lp,
1068 unsigned short status,
1069 unsigned short *ack_cmdp) {
1070 volatile struct i596_cmd *cmd;
1072 int commands_done = 0;
1077 while (lp->cmd_head && (lp->cmd_head->status & CMD_STAT_C)) {
1080 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
1084 cmd_val = cmd->command & 0x7;
1086 printk("finished CU %s command (%d)\n",
1087 CUcmdnames[cmd_val], cmd_val);
1092 struct tx_cmd *tx_cmd;
1093 struct i596_tbd *tx_cmd_tbd;
1095 tx_cmd = (struct tx_cmd *) cmd;
1096 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
1099 if (cmd->status & CMD_STAT_OK) {
1101 print_eth(pa_to_va(tx_cmd_tbd->pa_data));
1103 lp->stats.tx_errors++;
1105 printk("transmission failure:%04x\n",
1107 if (cmd->status & 0x0020)
1108 lp->stats.collisions++;
1109 if (!(cmd->status & 0x0040))
1110 lp->stats.tx_heartbeat_errors++;
1111 if (cmd->status & 0x0400)
1112 lp->stats.tx_carrier_errors++;
1113 if (cmd->status & 0x0800)
1114 lp->stats.collisions++;
1115 if (cmd->status & 0x1000)
1116 lp->stats.tx_aborted_errors++;
1118 dev_kfree_skb_irq(tx_cmd_tbd->skb);
1120 cmd->pa_next = I596_NULL;
1121 kfree((unsigned char *)tx_cmd);
1122 netif_wake_queue(dev);
1126 case CmdMulticastList:
1127 cmd->pa_next = I596_NULL;
1128 kfree((unsigned char *)cmd);
1133 unsigned long status = *((unsigned long *) (cmd + 1));
1134 if (status & 0x8000) {
1136 printk("%s: link ok.\n", dev->name);
1138 if (status & 0x4000)
1139 printk("%s: Transceiver problem.\n",
1141 if (status & 0x2000)
1142 printk("%s: Termination problem.\n",
1144 if (status & 0x1000)
1145 printk("%s: Short circuit.\n",
1147 printk("%s: Time %ld.\n",
1148 dev->name, status & 0x07ff);
1152 cmd->pa_next = I596_NULL;
1153 lp->last_cmd = jiffies;
1159 while (cmd && (cmd != lp->cmd_tail)) {
1160 cmd->command &= 0x1fff;
1161 cmd = pa_to_va(cmd->pa_next);
1165 *ack_cmdp |= CUC_START;
1166 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
1170 i596_interrupt (int irq, void *dev_instance, struct pt_regs *regs) {
1171 struct net_device *dev = (struct net_device *) dev_instance;
1172 volatile struct i596_private *lp;
1173 unsigned short status, ack_cmd = 0;
1177 printk ("i596_interrupt(): irq %d for unknown device.\n", irq);
1181 lp = (struct i596_private *) dev->priv;
1184 * The 82596 examines the command, performs the required action,
1185 * and then clears the SCB command word.
1187 if (lp->scb.command && i596_timeout(dev, "interrupt", 40))
1191 * The status word indicates the status of the 82596.
1192 * It is modified only by the 82596.
1194 * [So, we must not clear it. I find often status 0xffff,
1195 * which is not one of the values allowed by the docs.]
1197 status = lp->scb.status;
1200 printk("%s: i596 interrupt, ", dev->name);
1201 i596_out_status(status);
1204 /* Impossible, but it happens - perhaps when we get
1205 a receive interrupt but scb.pa_rfd is I596_NULL. */
1206 if (status == 0xffff) {
1207 printk("%s: i596_interrupt: got status 0xffff\n", dev->name);
1211 ack_cmd = (status & STAT_ACK);
1213 if (status & (STAT_CX | STAT_CNA))
1214 i596_handle_CU_completion(dev, lp, status, &ack_cmd);
1216 if (status & (STAT_FR | STAT_RNR)) {
1217 /* Restart the receive unit when it got inactive somehow */
1218 if ((status & STAT_RNR) && netif_running(dev))
1219 ack_cmd |= RX_START;
1221 if (status & STAT_FR) {
1222 frames_in = i596_rx(dev);
1224 printk("receive frame reported, but no frames\n");
1228 /* acknowledge the interrupt */
1230 if ((lp->scb.pa_cmd != I596_NULL) && netif_running(dev))
1231 ack_cmd |= CUC_START;
1234 if (lp->scb.command && i596_timeout(dev, "i596 interrupt", 100))
1237 lp->scb.command = ack_cmd;
1246 static int i596_close(struct net_device *dev) {
1247 volatile struct i596_private *lp = dev->priv;
1249 netif_stop_queue(dev);
1252 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1253 dev->name, lp->scb.status);
1255 lp->scb.command = (CUC_ABORT | RX_ABORT);
1258 i596_cleanup_cmd(dev);
1260 if (lp->scb.command && i596_timeout(dev, "i596_close", 200))
1263 free_irq(dev->irq, dev);
1264 remove_rx_bufs(dev);
1269 static struct net_device_stats * i596_get_stats(struct net_device *dev) {
1270 struct i596_private *lp = dev->priv;
1276 * Set or clear the multicast filter for this adaptor.
1279 static void set_multicast_list(struct net_device *dev) {
1280 volatile struct i596_private *lp = dev->priv;
1281 struct i596_cmd *cmd;
1284 printk ("%s: set multicast list %d\n",
1285 dev->name, dev->mc_count);
1287 if (dev->mc_count > 0) {
1288 struct dev_mc_list *dmi;
1290 cmd = (struct i596_cmd *)
1291 kmalloc(sizeof(struct i596_cmd)+2+dev->mc_count*6,
1294 printk ("%s: set_multicast Memory squeeze.\n",
1298 cmd->command = CmdMulticastList;
1299 *((unsigned short *) (cmd + 1)) = dev->mc_count * 6;
1300 cp = ((char *)(cmd + 1))+2;
1301 for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) {
1305 if (i596_debug & LOG_SRCDST)
1306 print_eth (((char *)(cmd + 1)) + 2);
1307 i596_add_cmd(dev, cmd);
1309 if (lp->set_conf.pa_next != I596_NULL) {
1312 if (dev->mc_count == 0 &&
1313 !(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1314 if (dev->flags & IFF_ALLMULTI)
1315 dev->flags |= IFF_PROMISC;
1316 lp->i596_config[8] &= ~0x01;
1318 lp->i596_config[8] |= 0x01;
1321 i596_add_cmd(dev, (struct i596_cmd *) &lp->set_conf);
1325 MODULE_AUTHOR("Ard van Breemen <ard@cstmel.nl.eu.org>");
1326 MODULE_DESCRIPTION("Intel Panther onboard i82596 driver");
1327 MODULE_LICENSE("GPL");
1329 MODULE_PARM(debug, "i");
1330 //MODULE_PARM(max_interrupt_work, "i");
1331 //MODULE_PARM(reverse_probe, "i");
1332 //MODULE_PARM(rx_copybreak, "i");
1333 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
1334 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
1336 static struct net_device dev_lp486e;
1337 static int full_duplex;
1339 static int io = IOADDR;
1340 static int irq = IRQ;
1342 static int __init lp486e_init_module(void) {
1343 struct net_device *dev = &dev_lp486e;
1345 dev->base_addr = io;
1346 dev->init = lp486e_probe;
1347 if (register_netdev(dev) != 0)
1354 static void __exit lp486e_cleanup_module(void) {
1355 unregister_netdev(&dev_lp486e);
1356 kfree((void *)dev_lp486e.mem_start);
1357 dev_lp486e.priv = NULL;
1358 release_region(dev_lp486e.base_addr, LP486E_TOTAL_SIZE);
1361 module_init(lp486e_init_module);
1362 module_exit(lp486e_cleanup_module);