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 #include <linux/module.h>
60 #include <linux/init.h>
61 #include <linux/delay.h>
62 #include <linux/kernel.h>
63 #include <linux/string.h>
64 #include <linux/errno.h>
65 #include <linux/ioport.h>
66 #include <linux/slab.h>
67 #include <linux/interrupt.h>
68 #include <linux/netdevice.h>
69 #include <linux/etherdevice.h>
70 #include <linux/skbuff.h>
71 #include <linux/bitops.h>
76 #define DRV_NAME "lp486e"
78 /* debug print flags */
79 #define LOG_SRCDST 0x80000000
80 #define LOG_STATINT 0x40000000
81 #define LOG_STARTINT 0x20000000
83 #define i596_debug debug
85 static int i596_debug = 0;
87 static const char * const medianame[] = {
89 "10baseT-FD", "AUI-FD",
92 #define LP486E_TOTAL_SIZE 16
94 #define I596_NULL (0xffffffff)
96 #define CMD_EOL 0x8000 /* The last command of the list, stop. */
97 #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
98 #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
100 #define CMD_FLEX 0x0008 /* Enable flexible memory model */
106 CmdMulticastList = 3,
114 static const char *CUcmdnames[8] = { "NOP", "IASetup", "Configure", "MulticastList",
115 "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
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 struct i596_rbd *rbd_list;
347 struct i596_rbd *rbd_tail;
348 struct i596_rfd *rx_tail;
349 struct i596_cmd *cmd_tail;
350 struct i596_cmd *cmd_head;
352 unsigned long last_cmd;
353 struct net_device_stats stats;
357 static char init_setup[14] = {
358 0x8E, /* length 14 bytes, prefetch on */
359 0xC8, /* default: fifo to 8, monitor off */
360 0x40, /* default: don't save bad frames (apricot.c had 0x80) */
361 0x2E, /* (default is 0x26)
362 No source address insertion, 8 byte preamble */
363 0x00, /* default priority and backoff */
364 0x60, /* default interframe spacing */
365 0x00, /* default slot time LSB */
366 0xf2, /* default slot time and nr of retries */
367 0x00, /* default various bits
368 (0: promiscuous mode, 1: broadcast disable,
369 2: encoding mode, 3: transmit on no CRS,
370 4: no CRC insertion, 5: CRC type,
371 6: bit stuffing, 7: padding) */
372 0x00, /* default carrier sense and collision detect */
373 0x40, /* default minimum frame length */
374 0xff, /* (default is 0xff, and that is what apricot.c has;
375 elp486.c has 0xfb: Enable crc append in memory.) */
376 0x00, /* default: not full duplex */
377 0x7f /* (default is 0x3f) multi IA */
380 static int i596_open(struct net_device *dev);
381 static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
382 static irqreturn_t i596_interrupt(int irq, void *dev_id);
383 static int i596_close(struct net_device *dev);
384 static struct net_device_stats *i596_get_stats(struct net_device *dev);
385 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
386 static void print_eth(char *);
387 static void set_multicast_list(struct net_device *dev);
388 static void i596_tx_timeout(struct net_device *dev);
391 i596_timeout(struct net_device *dev, char *msg, int ct) {
392 struct i596_private *lp;
395 lp = (struct i596_private *) dev->priv;
396 while (lp->scb.command) {
397 if (--boguscnt == 0) {
398 printk("%s: %s timed out - stat %4.4x, cmd %4.4x\n",
400 lp->scb.status, lp->scb.command);
410 init_rx_bufs(struct net_device *dev, int num) {
411 struct i596_private *lp;
412 struct i596_rfd *rfd;
414 // struct i596_rbd *rbd;
416 lp = (struct i596_private *) dev->priv;
417 lp->scb.pa_rfd = I596_NULL;
419 for (i = 0; i < num; i++) {
420 rfd = kmalloc(sizeof(struct i596_rfd), GFP_KERNEL);
425 rfd->pa_rbd = I596_NULL;
434 rfd->pa_next = lp->scb.pa_rfd;
435 lp->scb.pa_rfd = va_to_pa(rfd);
436 lp->rx_tail->pa_next = lp->scb.pa_rfd;
440 for (i = 0; i<RX_RBD_SIZE; i++) {
441 rbd = kmalloc(sizeof(struct i596_rbd), GFP_KERNEL);
445 rbd->skb = dev_alloc_skb(RX_SKBSIZE);
447 printk("dev_alloc_skb failed");
449 rbd->next = rfd->rbd;
451 rfd->rbd->prev = rbd;
452 rbd->size = RX_SKBSIZE;
454 rbd->size = (RX_SKBSIZE | RBD_EL);
460 printk("Could not kmalloc rbd\n");
463 lp->rbd_tail->next = rfd->rbd;
469 remove_rx_bufs(struct net_device *dev) {
470 struct i596_private *lp;
471 struct i596_rfd *rfd;
473 lp = (struct i596_private *) dev->priv;
474 lp->rx_tail->pa_next = I596_NULL;
477 rfd = pa_to_va(lp->scb.pa_rfd);
478 lp->scb.pa_rfd = rfd->pa_next;
480 } while (rfd != lp->rx_tail);
490 #define PORT_RESET 0x00 /* reset 82596 */
491 #define PORT_SELFTEST 0x01 /* selftest */
492 #define PORT_ALTSCP 0x02 /* alternate SCB address */
493 #define PORT_DUMP 0x03 /* dump */
495 #define IOADDR 0xcb0 /* real constant */
496 #define IRQ 10 /* default IRQ - can be changed by ECU */
498 /* The 82596 requires two 16-bit write cycles for a port command */
500 PORT(phys_addr a, unsigned int cmd) {
502 printk("lp486e.c: PORT: address not aligned\n");
503 outw(((a & 0xffff) | cmd), IOADDR);
504 outw(((a>>16) & 0xffff), IOADDR+2);
518 #define SIZE(x) (sizeof(x)/sizeof((x)[0]))
521 /* selftest or dump */
523 i596_port_do(struct net_device *dev, int portcmd, char *cmdname) {
524 struct i596_private *lp = dev->priv;
528 memset((void *)&(lp->dump), 0, sizeof(struct i596_dump));
529 outp = &(lp->dump.dump[0]);
531 PORT(va_to_pa(outp), portcmd);
532 mdelay(30); /* random, unmotivated */
534 printk("lp486e i82596 %s result:\n", cmdname);
535 for (m = SIZE(lp->dump.dump); m && lp->dump.dump[m-1] == 0; m--)
537 for (i = 0; i < m; i++) {
538 printk(" %04x", lp->dump.dump[i]);
547 i596_scp_setup(struct net_device *dev) {
548 struct i596_private *lp = dev->priv;
551 /* Setup SCP, ISCP, SCB */
554 * only a single byte is significant - here 0x44
555 * 0x80: big endian mode (details depend on stepping)
557 * 0x20: interrupt pin is active low
558 * 0x10: lock function disabled
559 * 0x08: external triggering of bus throttle timers
560 * 0x06: 00: 82586 compat mode, 01: segmented mode, 10: linear mode
563 lp->scp.sysbus = 0x00440000; /* linear mode */
564 lp->scp.pad = 0; /* must be zero */
565 lp->scp.pa_iscp = va_to_pa(&(lp->iscp));
568 * The CPU sets the ISCP to 1 before it gives the first CA()
570 lp->iscp.busy = 0x0001;
571 lp->iscp.pa_scb = va_to_pa(&(lp->scb));
575 lp->scb.pa_cmd = I596_NULL;
576 /* lp->scb.pa_rfd has been initialised already */
578 lp->last_cmd = jiffies;
584 * We need to wait 10 systemclock cycles, and
585 * 5 serial clock cycles.
587 PORT(0, PORT_RESET); /* address part ignored */
591 * Before the CA signal is asserted, the default SCP address
592 * (0x00fffff4) can be changed to a 16-byte aligned value
594 PORT(va_to_pa(&lp->scp), PORT_ALTSCP); /* change the scp address */
597 * The initialization procedure begins when a
598 * Channel Attention signal is asserted after a reset.
604 * The ISCP busy is cleared by the 82596 after the SCB address is read.
607 while (lp->iscp.busy) {
608 if (--boguscnt == 0) {
609 /* No i82596 present? */
610 printk("%s: i82596 initialization timed out\n",
617 /* I find here boguscnt==100, so no delay was required. */
623 init_i596(struct net_device *dev) {
624 struct i596_private *lp;
626 if (i596_scp_setup(dev))
629 lp = (struct i596_private *) dev->priv;
632 memcpy ((void *)lp->i596_config, init_setup, 14);
633 lp->set_conf.command = CmdConfigure;
634 i596_add_cmd(dev, (void *)&lp->set_conf);
636 memcpy ((void *)lp->eth_addr, dev->dev_addr, 6);
637 lp->set_add.command = CmdIASetup;
638 i596_add_cmd(dev, (struct i596_cmd *)&lp->set_add);
640 lp->tdr.command = CmdTDR;
641 i596_add_cmd(dev, (struct i596_cmd *)&lp->tdr);
643 if (lp->scb.command && i596_timeout(dev, "i82596 init", 200))
646 lp->scb.command = RX_START;
651 if (lp->scb.command && i596_timeout(dev, "Receive Unit start", 100))
657 /* Receive a single frame */
659 i596_rx_one(struct net_device *dev, struct i596_private *lp,
660 struct i596_rfd *rfd, int *frames) {
662 if (rfd->stat & RFD_STAT_OK) {
664 int pkt_len = (rfd->count & 0x3fff);
665 struct sk_buff *skb = dev_alloc_skb(pkt_len);
669 if (rfd->cmd & CMD_EOL)
670 printk("Received on EOL\n");
673 printk ("%s: i596_rx Memory squeeze, "
674 "dropping packet.\n", dev->name);
675 lp->stats.rx_dropped++;
679 memcpy(skb_put(skb,pkt_len), rfd->data, pkt_len);
681 skb->protocol = eth_type_trans(skb,dev);
683 dev->last_rx = jiffies;
684 lp->stats.rx_packets++;
687 printk("Frame reception error status %04x\n",
690 lp->stats.rx_errors++;
691 if (rfd->stat & RFD_COLLISION)
692 lp->stats.collisions++;
693 if (rfd->stat & RFD_SHORT_FRAME_ERR)
694 lp->stats.rx_length_errors++;
695 if (rfd->stat & RFD_DMA_ERR)
696 lp->stats.rx_over_errors++;
697 if (rfd->stat & RFD_NOBUFS_ERR)
698 lp->stats.rx_fifo_errors++;
699 if (rfd->stat & RFD_ALIGN_ERR)
700 lp->stats.rx_frame_errors++;
701 if (rfd->stat & RFD_CRC_ERR)
702 lp->stats.rx_crc_errors++;
703 if (rfd->stat & RFD_LENGTH_ERR)
704 lp->stats.rx_length_errors++;
706 rfd->stat = rfd->count = 0;
711 i596_rx(struct net_device *dev) {
712 struct i596_private *lp = (struct i596_private *) dev->priv;
713 struct i596_rfd *rfd;
717 rfd = pa_to_va(lp->scb.pa_rfd);
719 printk(KERN_ERR "i596_rx: NULL rfd?\n");
723 if (rfd->stat && !(rfd->stat & (RFD_STAT_C | RFD_STAT_B)))
724 printk("SF:%p-%04x\n", rfd, rfd->stat);
726 if (!(rfd->stat & RFD_STAT_C))
727 break; /* next one not ready */
728 if (i596_rx_one(dev, lp, rfd, &frames))
729 break; /* out of memory */
731 lp->rx_tail->cmd = 0;
733 lp->scb.pa_rfd = rfd->pa_next;
741 i596_cleanup_cmd(struct net_device *dev) {
742 struct i596_private *lp;
743 struct i596_cmd *cmd;
745 lp = (struct i596_private *) dev->priv;
746 while (lp->cmd_head) {
747 cmd = (struct i596_cmd *)lp->cmd_head;
749 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
752 switch ((cmd->command) & 0x7) {
754 struct tx_cmd *tx_cmd = (struct tx_cmd *) cmd;
755 struct i596_tbd * tx_cmd_tbd;
756 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
758 dev_kfree_skb_any(tx_cmd_tbd->skb);
760 lp->stats.tx_errors++;
761 lp->stats.tx_aborted_errors++;
763 cmd->pa_next = I596_NULL;
764 kfree((unsigned char *)tx_cmd);
765 netif_wake_queue(dev);
768 case CmdMulticastList: {
769 // unsigned short count = *((unsigned short *) (ptr + 1));
771 cmd->pa_next = I596_NULL;
772 kfree((unsigned char *)cmd);
776 cmd->pa_next = I596_NULL;
783 if (lp->scb.command && i596_timeout(dev, "i596_cleanup_cmd", 100))
786 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
789 static void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr) {
791 if (lp->scb.command && i596_timeout(dev, "i596_reset", 100))
794 netif_stop_queue(dev);
796 lp->scb.command = CUC_ABORT | RX_ABORT;
800 /* wait for shutdown */
801 if (lp->scb.command && i596_timeout(dev, "i596_reset(2)", 400))
804 i596_cleanup_cmd(dev);
807 netif_start_queue(dev);
808 /*dev_kfree_skb(skb, FREE_WRITE);*/
812 static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) {
813 struct i596_private *lp = dev->priv;
814 int ioaddr = dev->base_addr;
818 cmd->command |= (CMD_EOL | CMD_INTR);
819 cmd->pa_next = I596_NULL;
821 spin_lock_irqsave(&lp->cmd_lock, flags);
824 lp->cmd_tail->pa_next = va_to_pa(cmd);
827 if (lp->scb.command && i596_timeout(dev, "i596_add_cmd", 100))
829 lp->scb.pa_cmd = va_to_pa(cmd);
830 lp->scb.command = CUC_START;
836 lp->cmd_head = pa_to_va(lp->scb.pa_cmd);
837 spin_unlock_irqrestore(&lp->cmd_lock, flags);
839 if (lp->cmd_backlog > 16) {
840 int tickssofar = jiffies - lp->last_cmd;
841 if (tickssofar < HZ/4)
844 printk(KERN_WARNING "%s: command unit timed out, status resetting.\n", dev->name);
845 i596_reset(dev, lp, ioaddr);
849 static int i596_open(struct net_device *dev)
853 i = request_irq(dev->irq, &i596_interrupt, IRQF_SHARED, dev->name, dev);
855 printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
859 if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE)
860 printk(KERN_ERR "%s: only able to allocate %d receive buffers\n", dev->name, i);
863 free_irq(dev->irq, dev);
866 netif_start_queue(dev);
868 return 0; /* Always succeed */
871 static int i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
872 struct i596_private *lp = dev->priv;
873 struct tx_cmd *tx_cmd;
878 if (length < ETH_ZLEN) {
879 if (skb_padto(skb, ETH_ZLEN))
884 dev->trans_start = jiffies;
886 tx_cmd = kmalloc((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC);
887 if (tx_cmd == NULL) {
888 printk(KERN_WARNING "%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name);
889 lp->stats.tx_dropped++;
892 struct i596_tbd *tx_cmd_tbd;
893 tx_cmd_tbd = (struct i596_tbd *) (tx_cmd + 1);
894 tx_cmd->pa_tbd = va_to_pa (tx_cmd_tbd);
895 tx_cmd_tbd->pa_next = I596_NULL;
897 tx_cmd->cmd.command = (CMD_FLEX | CmdTx);
902 tx_cmd_tbd->size = (EOF | length);
904 tx_cmd_tbd->pa_data = va_to_pa (skb->data);
905 tx_cmd_tbd->skb = skb;
907 if (i596_debug & LOG_SRCDST)
908 print_eth (skb->data);
910 i596_add_cmd (dev, (struct i596_cmd *) tx_cmd);
912 lp->stats.tx_packets++;
919 i596_tx_timeout (struct net_device *dev) {
920 struct i596_private *lp = dev->priv;
921 int ioaddr = dev->base_addr;
923 /* Transmitter timeout, serious problems. */
924 printk(KERN_WARNING "%s: transmit timed out, status resetting.\n", dev->name);
925 lp->stats.tx_errors++;
927 /* Try to restart the adaptor */
928 if (lp->last_restart == lp->stats.tx_packets) {
929 printk ("Resetting board.\n");
931 /* Shutdown and restart */
932 i596_reset (dev, lp, ioaddr);
934 /* Issue a channel attention signal */
935 printk ("Kicking board.\n");
936 lp->scb.command = (CUC_START | RX_START);
938 lp->last_restart = lp->stats.tx_packets;
940 netif_wake_queue(dev);
943 static void print_eth(char *add)
948 for (i = 0; i < 6; i++)
949 printk(" %2.2X", (unsigned char) add[i]);
953 for (i = 0; i < 6; i++)
954 printk(" %2.2X", (unsigned char) add[i+6]);
957 printk ("type %2.2X%2.2X\n",
958 (unsigned char) add[12], (unsigned char) add[13]);
961 static int __init lp486e_probe(struct net_device *dev) {
962 struct i596_private *lp;
963 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 };
973 if (!request_region(IOADDR, LP486E_TOTAL_SIZE, DRV_NAME)) {
974 printk(KERN_ERR "lp486e: IO address 0x%x in use\n", IOADDR);
978 lp = (struct i596_private *) dev->priv;
979 spin_lock_init(&lp->cmd_lock);
982 * Do we really have this thing?
984 if (i596_scp_setup(dev)) {
989 dev->base_addr = IOADDR;
994 * How do we find the ethernet address? I don't know.
995 * One possibility is to look at the EISA configuration area
996 * [0xe8000-0xe9fff]. This contains the ethernet address
997 * but not at a fixed address - things depend on setup options.
999 * If we find no address, or the wrong address, use
1000 * ifconfig eth0 hw ether a1:a2:a3:a4:a5:a6
1001 * with the value found in the BIOS setup.
1003 bios = bus_to_virt(0xe8000);
1004 for (j = 0; j < 0x2000; j++) {
1005 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) {
1006 printk("%s: maybe address at BIOS 0x%x:",
1007 dev->name, 0xe8000+j);
1008 for (i = 0; i < 6; i++) {
1009 eth_addr[i] = bios[i+j];
1010 printk(" %2.2X", eth_addr[i]);
1016 printk("%s: lp486e 82596 at %#3lx, IRQ %d,",
1017 dev->name, dev->base_addr, dev->irq);
1018 for (i = 0; i < 6; i++)
1019 printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]);
1022 /* The LP486E-specific entries in the device structure. */
1023 dev->open = &i596_open;
1024 dev->stop = &i596_close;
1025 dev->hard_start_xmit = &i596_start_xmit;
1026 dev->get_stats = &i596_get_stats;
1027 dev->set_multicast_list = &set_multicast_list;
1028 dev->watchdog_timeo = 5*HZ;
1029 dev->tx_timeout = i596_tx_timeout;
1032 /* selftest reports 0x320925ae - don't know what that means */
1033 i596_port_do(dev, PORT_SELFTEST, "selftest");
1034 i596_port_do(dev, PORT_DUMP, "dump");
1039 release_region(IOADDR, LP486E_TOTAL_SIZE);
1044 i596_handle_CU_completion(struct net_device *dev,
1045 struct i596_private *lp,
1046 unsigned short status,
1047 unsigned short *ack_cmdp) {
1048 struct i596_cmd *cmd;
1050 int commands_done = 0;
1052 unsigned long flags;
1054 spin_lock_irqsave(&lp->cmd_lock, flags);
1057 while (lp->cmd_head && (lp->cmd_head->status & CMD_STAT_C)) {
1060 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
1064 cmd_val = cmd->command & 0x7;
1066 printk("finished CU %s command (%d)\n",
1067 CUcmdnames[cmd_val], cmd_val);
1072 struct tx_cmd *tx_cmd;
1073 struct i596_tbd *tx_cmd_tbd;
1075 tx_cmd = (struct tx_cmd *) cmd;
1076 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
1079 if (cmd->status & CMD_STAT_OK) {
1081 print_eth(pa_to_va(tx_cmd_tbd->pa_data));
1083 lp->stats.tx_errors++;
1085 printk("transmission failure:%04x\n",
1087 if (cmd->status & 0x0020)
1088 lp->stats.collisions++;
1089 if (!(cmd->status & 0x0040))
1090 lp->stats.tx_heartbeat_errors++;
1091 if (cmd->status & 0x0400)
1092 lp->stats.tx_carrier_errors++;
1093 if (cmd->status & 0x0800)
1094 lp->stats.collisions++;
1095 if (cmd->status & 0x1000)
1096 lp->stats.tx_aborted_errors++;
1098 dev_kfree_skb_irq(tx_cmd_tbd->skb);
1100 cmd->pa_next = I596_NULL;
1101 kfree((unsigned char *)tx_cmd);
1102 netif_wake_queue(dev);
1106 case CmdMulticastList:
1107 cmd->pa_next = I596_NULL;
1108 kfree((unsigned char *)cmd);
1113 unsigned long status = *((unsigned long *) (cmd + 1));
1114 if (status & 0x8000) {
1116 printk("%s: link ok.\n", dev->name);
1118 if (status & 0x4000)
1119 printk("%s: Transceiver problem.\n",
1121 if (status & 0x2000)
1122 printk("%s: Termination problem.\n",
1124 if (status & 0x1000)
1125 printk("%s: Short circuit.\n",
1127 printk("%s: Time %ld.\n",
1128 dev->name, status & 0x07ff);
1132 cmd->pa_next = I596_NULL;
1133 lp->last_cmd = jiffies;
1140 while (cmd && (cmd != lp->cmd_tail)) {
1141 cmd->command &= 0x1fff;
1142 cmd = pa_to_va(cmd->pa_next);
1147 *ack_cmdp |= CUC_START;
1148 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
1149 spin_unlock_irqrestore(&lp->cmd_lock, flags);
1153 i596_interrupt (int irq, void *dev_instance) {
1154 struct net_device *dev = (struct net_device *) dev_instance;
1155 struct i596_private *lp;
1156 unsigned short status, ack_cmd = 0;
1159 lp = (struct i596_private *) dev->priv;
1162 * The 82596 examines the command, performs the required action,
1163 * and then clears the SCB command word.
1165 if (lp->scb.command && i596_timeout(dev, "interrupt", 40))
1169 * The status word indicates the status of the 82596.
1170 * It is modified only by the 82596.
1172 * [So, we must not clear it. I find often status 0xffff,
1173 * which is not one of the values allowed by the docs.]
1175 status = lp->scb.status;
1178 printk("%s: i596 interrupt, ", dev->name);
1179 i596_out_status(status);
1182 /* Impossible, but it happens - perhaps when we get
1183 a receive interrupt but scb.pa_rfd is I596_NULL. */
1184 if (status == 0xffff) {
1185 printk("%s: i596_interrupt: got status 0xffff\n", dev->name);
1189 ack_cmd = (status & STAT_ACK);
1191 if (status & (STAT_CX | STAT_CNA))
1192 i596_handle_CU_completion(dev, lp, status, &ack_cmd);
1194 if (status & (STAT_FR | STAT_RNR)) {
1195 /* Restart the receive unit when it got inactive somehow */
1196 if ((status & STAT_RNR) && netif_running(dev))
1197 ack_cmd |= RX_START;
1199 if (status & STAT_FR) {
1200 frames_in = i596_rx(dev);
1202 printk("receive frame reported, but no frames\n");
1206 /* acknowledge the interrupt */
1208 if ((lp->scb.pa_cmd != I596_NULL) && netif_running(dev))
1209 ack_cmd |= CUC_START;
1212 if (lp->scb.command && i596_timeout(dev, "i596 interrupt", 100))
1215 lp->scb.command = ack_cmd;
1224 static int i596_close(struct net_device *dev) {
1225 struct i596_private *lp = dev->priv;
1227 netif_stop_queue(dev);
1230 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1231 dev->name, lp->scb.status);
1233 lp->scb.command = (CUC_ABORT | RX_ABORT);
1236 i596_cleanup_cmd(dev);
1238 if (lp->scb.command && i596_timeout(dev, "i596_close", 200))
1241 free_irq(dev->irq, dev);
1242 remove_rx_bufs(dev);
1247 static struct net_device_stats * i596_get_stats(struct net_device *dev) {
1248 struct i596_private *lp = dev->priv;
1254 * Set or clear the multicast filter for this adaptor.
1257 static void set_multicast_list(struct net_device *dev) {
1258 struct i596_private *lp = dev->priv;
1259 struct i596_cmd *cmd;
1262 printk ("%s: set multicast list %d\n",
1263 dev->name, dev->mc_count);
1265 if (dev->mc_count > 0) {
1266 struct dev_mc_list *dmi;
1268 cmd = kmalloc(sizeof(struct i596_cmd)+2+dev->mc_count*6, GFP_ATOMIC);
1270 printk (KERN_ERR "%s: set_multicast Memory squeeze.\n", dev->name);
1273 cmd->command = CmdMulticastList;
1274 *((unsigned short *) (cmd + 1)) = dev->mc_count * 6;
1275 cp = ((char *)(cmd + 1))+2;
1276 for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) {
1280 if (i596_debug & LOG_SRCDST)
1281 print_eth (((char *)(cmd + 1)) + 2);
1282 i596_add_cmd(dev, cmd);
1284 if (lp->set_conf.pa_next != I596_NULL) {
1287 if (dev->mc_count == 0 && !(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1288 if (dev->flags & IFF_ALLMULTI)
1289 dev->flags |= IFF_PROMISC;
1290 lp->i596_config[8] &= ~0x01;
1292 lp->i596_config[8] |= 0x01;
1295 i596_add_cmd(dev, (struct i596_cmd *) &lp->set_conf);
1299 MODULE_AUTHOR("Ard van Breemen <ard@cstmel.nl.eu.org>");
1300 MODULE_DESCRIPTION("Intel Panther onboard i82596 driver");
1301 MODULE_LICENSE("GPL");
1303 static struct net_device *dev_lp486e;
1304 static int full_duplex;
1306 static int io = IOADDR;
1307 static int irq = IRQ;
1309 module_param(debug, int, 0);
1310 //module_param(max_interrupt_work, int, 0);
1311 //module_param(reverse_probe, int, 0);
1312 //module_param(rx_copybreak, int, 0);
1313 module_param(options, int, 0);
1314 module_param(full_duplex, int, 0);
1316 static int __init lp486e_init_module(void) {
1318 struct net_device *dev = alloc_etherdev(sizeof(struct i596_private));
1323 dev->base_addr = io;
1324 err = lp486e_probe(dev);
1329 err = register_netdev(dev);
1331 release_region(dev->base_addr, LP486E_TOTAL_SIZE);
1341 static void __exit lp486e_cleanup_module(void) {
1342 unregister_netdev(dev_lp486e);
1343 release_region(dev_lp486e->base_addr, LP486E_TOTAL_SIZE);
1344 free_netdev(dev_lp486e);
1347 module_init(lp486e_init_module);
1348 module_exit(lp486e_cleanup_module);