blob: 4d1a059921c6413d419257327cc382207298a9e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Intel Professional Workstation/panther ethernet driver */
2/* lp486e.c: A panther 82596 ethernet driver for linux. */
3/*
4 History and copyrights:
5
6 Driver skeleton
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.
12
13 The author may be reached as becker@scyld.com, or C/O
14 Scyld Computing Corporation
15 410 Severn Ave., Suite 210
16 Annapolis MD 21403
17
18 Apricot
19 Written 1994 by Mark Evans.
20 This driver is for the Apricot 82596 bus-master interface
21
22 Modularised 12/94 Mark Evans
23
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>
27
28 Credits:
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)
33
34 Present version
35 aeb@cwi.nl
36*/
37/*
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
41*/
42/*
43The pws is equipped with an intel 82596. This is a very intelligent controller
44which runs its own micro-code. Communication with the hostprocessor is done
45through linked lists of commands and buffers in the hostprocessors memory.
46A complete description of the 82596 is available from intel. Search for
47a file called "29021806.pdf". It is a complete description of the chip itself.
48To use it for the pws some additions are needed regarding generation of
49the PORT and CA signal, and the interrupt glue needed for a pc.
50I/O map:
51PORT SIZE ACTION MEANING
520xCB0 2 WRITE Lower 16 bits for PORT command
530xCB2 2 WRITE Upper 16 bits for PORT command, and issue of PORT command
540xCB4 1 WRITE Generation of CA signal
550xCB8 1 WRITE Clear interrupt glue
56All other communication is through memory!
57*/
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#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>
72
73#include <asm/io.h>
74#include <asm/dma.h>
75
76#define DRV_NAME "lp486e"
77
78/* debug print flags */
79#define LOG_SRCDST 0x80000000
80#define LOG_STATINT 0x40000000
81#define LOG_STARTINT 0x20000000
82
83#define i596_debug debug
84
85static int i596_debug = 0;
86
87static const char * const medianame[] = {
88 "10baseT", "AUI",
89 "10baseT-FD", "AUI-FD",
90};
91
92#define LP486E_TOTAL_SIZE 16
93
94#define I596_NULL (0xffffffff)
95
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. */
99
100#define CMD_FLEX 0x0008 /* Enable flexible memory model */
101
102enum commands {
103 CmdNOP = 0,
104 CmdIASetup = 1,
105 CmdConfigure = 2,
106 CmdMulticastList = 3,
107 CmdTx = 4,
108 CmdTDR = 5,
109 CmdDump = 6,
110 CmdDiagnose = 7
111};
112
113#if 0
114static const char *CUcmdnames[8] = { "NOP", "IASetup", "Configure", "MulticastList",
115 "Tx", "TDR", "Dump", "Diagnose" };
116#endif
117
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 */
133
134#if 0
135static char *CUstates[8] = {
136 "idle", "suspended", "active", 0, 0, 0, 0, 0
137};
138static 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
141};
142
143static void
144i596_out_status(int status) {
145 int bad = 0;
146 char *s;
147
148 printk("status %4.4x:", status);
149 if (status == 0xffff)
150 printk(" strange..\n");
151 else {
152 if (status & STAT_CX)
153 printk(" CU done");
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");
160 if (status & STAT_T)
161 printk(" throttled");
162 if (status & STAT_ZERO)
163 bad = 1;
164 s = CUstates[(status & STAT_CUS) >> 8];
165 if (!s)
166 bad = 1;
167 else
168 printk(" CU(%s)", s);
169 s = RUstates[(status & STAT_RUS) >> 4];
170 if (!s)
171 bad = 1;
172 else
173 printk(" RU(%s)", s);
174 if (bad)
175 printk(" bad status");
176 printk("\n");
177 }
178}
179#endif
180
181/* Command word bits */
182#define ACK_CX 0x8000
183#define ACK_FR 0x4000
184#define ACK_CNA 0x2000
185#define ACK_RNR 0x1000
186
187#define CUC_START 0x0100
188#define CUC_RESUME 0x0200
189#define CUC_SUSPEND 0x0300
190#define CUC_ABORT 0x0400
191
192#define RX_START 0x0010
193#define RX_RESUME 0x0020
194#define RX_SUSPEND 0x0030
195#define RX_ABORT 0x0040
196
197typedef u32 phys_addr;
198
199static inline phys_addr
200va_to_pa(void *x) {
201 return x ? virt_to_bus(x) : I596_NULL;
202}
203
204static inline void *
205pa_to_va(phys_addr x) {
206 return (x == I596_NULL) ? NULL : bus_to_virt(x);
207}
208
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 */
214
215struct i596_cmd { /* 8 bytes */
216 unsigned short status;
217 unsigned short command;
218 phys_addr pa_next; /* va_to_pa(struct i596_cmd *next) */
219};
220
221#define EOF 0x8000
222#define SIZE_MASK 0x3fff
223
224struct i596_tbd {
225 unsigned short size;
226 unsigned short pad;
227 phys_addr pa_next; /* va_to_pa(struct i596_tbd *next) */
228 phys_addr pa_data; /* va_to_pa(char *data) */
229 struct sk_buff *skb;
230};
231
232struct tx_cmd {
233 struct i596_cmd cmd;
234 phys_addr pa_tbd; /* va_to_pa(struct i596_tbd *tbd) */
235 unsigned short size;
236 unsigned short pad;
237};
238
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
255
256/* receive frame descriptor */
257struct i596_rfd {
258 unsigned short stat;
259 unsigned short cmd;
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;
263 unsigned short size;
264 char data[1532];
265};
266
267#define RBD_EL 0x8000
268#define RBD_P 0x4000
269#define RBD_SIZEMASK 0x3fff
270#define RBD_EOF 0x8000
271#define RBD_F 0x4000
272
273/* receive buffer descriptor */
274struct i596_rbd {
275 unsigned short size;
276 unsigned short pad;
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) */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* Driver private part */
282 struct sk_buff *skb;
283};
284
285#define RX_RING_SIZE 64
286#define RX_SKBSIZE (ETH_FRAME_LEN+10)
287#define RX_RBD_SIZE 32
288
289/* System Control Block - 40 bytes */
290struct i596_scb {
291 u16 status; /* 0 */
292 u16 command; /* 2 */
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 */
301 u16 t_on; /* 36 */
302 u16 t_off; /* 38 */
303};
304
305/* Intermediate System Configuration Pointer - 8 bytes */
306struct i596_iscp {
307 u32 busy; /* 0 */
308 phys_addr pa_scb; /* 4 - va_to_pa(struct i596_scb *scb) */
309};
310
311/* System Configuration Pointer - 12 bytes */
312struct i596_scp {
313 u32 sysbus; /* 0 */
314 u32 pad; /* 4 */
315 phys_addr pa_iscp; /* 8 - va_to_pa(struct i596_iscp *iscp) */
316};
317
318/* Selftest and dump results - needs 16-byte alignment */
319/*
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]
324 */
325struct i596_dump {
326 u16 dump[153]; /* (304 = 130h) + 2 bytes */
327};
328
329struct 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 */
333 u32 dummy; /* 60 */
334 struct i596_dump dump; /* 64 - needs 16-byte alignment */
335
336 struct i596_cmd set_add;
337 char eth_addr[8]; /* directly follows set_add */
338
339 struct i596_cmd set_conf;
340 char i596_config[16]; /* directly follows set_conf */
341
342 struct i596_cmd tdr;
343 unsigned long tdr_stat; /* directly follows tdr */
344
345 int last_restart;
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;
351 int cmd_backlog;
352 unsigned long last_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 spinlock_t cmd_lock;
354};
355
356static 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 */
377};
378
379static int i596_open(struct net_device *dev);
380static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100381static irqreturn_t i596_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382static int i596_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
384static void print_eth(char *);
385static void set_multicast_list(struct net_device *dev);
386static void i596_tx_timeout(struct net_device *dev);
387
388static int
389i596_timeout(struct net_device *dev, char *msg, int ct) {
390 struct i596_private *lp;
391 int boguscnt = ct;
392
Wang Chen454d7c92008-11-12 23:37:49 -0800393 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 while (lp->scb.command) {
395 if (--boguscnt == 0) {
396 printk("%s: %s timed out - stat %4.4x, cmd %4.4x\n",
397 dev->name, msg,
398 lp->scb.status, lp->scb.command);
399 return 1;
400 }
401 udelay(5);
402 barrier();
403 }
404 return 0;
405}
406
407static inline int
408init_rx_bufs(struct net_device *dev, int num) {
409 struct i596_private *lp;
410 struct i596_rfd *rfd;
411 int i;
412 // struct i596_rbd *rbd;
413
Wang Chen454d7c92008-11-12 23:37:49 -0800414 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 lp->scb.pa_rfd = I596_NULL;
416
417 for (i = 0; i < num; i++) {
418 rfd = kmalloc(sizeof(struct i596_rfd), GFP_KERNEL);
419 if (rfd == NULL)
420 break;
421
422 rfd->stat = 0;
423 rfd->pa_rbd = I596_NULL;
424 rfd->count = 0;
425 rfd->size = 1532;
426 if (i == 0) {
427 rfd->cmd = CMD_EOL;
428 lp->rx_tail = rfd;
429 } else {
430 rfd->cmd = 0;
431 }
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;
435 }
436
437#if 0
438 for (i = 0; i<RX_RBD_SIZE; i++) {
439 rbd = kmalloc(sizeof(struct i596_rbd), GFP_KERNEL);
440 if (rbd) {
441 rbd->pad = 0;
442 rbd->count = 0;
Jeff Garzik8ce90902006-09-21 00:06:21 -0400443 rbd->skb = dev_alloc_skb(RX_SKBSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (!rbd->skb) {
445 printk("dev_alloc_skb failed");
446 }
447 rbd->next = rfd->rbd;
448 if (i) {
449 rfd->rbd->prev = rbd;
Jeff Garzik8ce90902006-09-21 00:06:21 -0400450 rbd->size = RX_SKBSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 } else {
Jeff Garzik8ce90902006-09-21 00:06:21 -0400452 rbd->size = (RX_SKBSIZE | RBD_EL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 lp->rbd_tail = rbd;
454 }
455
456 rfd->rbd = rbd;
457 } else {
458 printk("Could not kmalloc rbd\n");
459 }
460 }
461 lp->rbd_tail->next = rfd->rbd;
462#endif
463 return (i);
464}
465
466static inline void
467remove_rx_bufs(struct net_device *dev) {
468 struct i596_private *lp;
469 struct i596_rfd *rfd;
470
Wang Chen454d7c92008-11-12 23:37:49 -0800471 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 lp->rx_tail->pa_next = I596_NULL;
473
474 do {
475 rfd = pa_to_va(lp->scb.pa_rfd);
476 lp->scb.pa_rfd = rfd->pa_next;
477 kfree(rfd);
478 } while (rfd != lp->rx_tail);
479
480 lp->rx_tail = NULL;
481
482#if 0
483 for (lp->rbd_list) {
484 }
485#endif
486}
487
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 */
492
493#define IOADDR 0xcb0 /* real constant */
494#define IRQ 10 /* default IRQ - can be changed by ECU */
495
496/* The 82596 requires two 16-bit write cycles for a port command */
497static inline void
498PORT(phys_addr a, unsigned int cmd) {
499 if (a & 0xf)
500 printk("lp486e.c: PORT: address not aligned\n");
501 outw(((a & 0xffff) | cmd), IOADDR);
502 outw(((a>>16) & 0xffff), IOADDR+2);
503}
504
505static inline void
506CA(void) {
507 outb(0, IOADDR+4);
508 udelay(8);
509}
510
511static inline void
512CLEAR_INT(void) {
513 outb(0, IOADDR+8);
514}
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#if 0
517/* selftest or dump */
518static void
519i596_port_do(struct net_device *dev, int portcmd, char *cmdname) {
Wang Chen454d7c92008-11-12 23:37:49 -0800520 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 u16 *outp;
522 int i, m;
523
524 memset((void *)&(lp->dump), 0, sizeof(struct i596_dump));
525 outp = &(lp->dump.dump[0]);
526
527 PORT(va_to_pa(outp), portcmd);
528 mdelay(30); /* random, unmotivated */
529
530 printk("lp486e i82596 %s result:\n", cmdname);
Denis Chengff8ac602007-09-02 18:30:18 +0800531 for (m = ARRAY_SIZE(lp->dump.dump); m && lp->dump.dump[m-1] == 0; m--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 ;
533 for (i = 0; i < m; i++) {
534 printk(" %04x", lp->dump.dump[i]);
535 if (i%8 == 7)
536 printk("\n");
537 }
538 printk("\n");
539}
540#endif
541
542static int
543i596_scp_setup(struct net_device *dev) {
Wang Chen454d7c92008-11-12 23:37:49 -0800544 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 int boguscnt;
546
547 /* Setup SCP, ISCP, SCB */
548 /*
549 * sysbus bits:
550 * only a single byte is significant - here 0x44
551 * 0x80: big endian mode (details depend on stepping)
552 * 0x40: 1
553 * 0x20: interrupt pin is active low
554 * 0x10: lock function disabled
555 * 0x08: external triggering of bus throttle timers
556 * 0x06: 00: 82586 compat mode, 01: segmented mode, 10: linear mode
557 * 0x01: unused
558 */
559 lp->scp.sysbus = 0x00440000; /* linear mode */
560 lp->scp.pad = 0; /* must be zero */
561 lp->scp.pa_iscp = va_to_pa(&(lp->iscp));
562
563 /*
564 * The CPU sets the ISCP to 1 before it gives the first CA()
565 */
566 lp->iscp.busy = 0x0001;
567 lp->iscp.pa_scb = va_to_pa(&(lp->scb));
568
569 lp->scb.command = 0;
570 lp->scb.status = 0;
571 lp->scb.pa_cmd = I596_NULL;
572 /* lp->scb.pa_rfd has been initialised already */
573
574 lp->last_cmd = jiffies;
575 lp->cmd_backlog = 0;
576 lp->cmd_head = NULL;
577
578 /*
579 * Reset the 82596.
580 * We need to wait 10 systemclock cycles, and
581 * 5 serial clock cycles.
582 */
583 PORT(0, PORT_RESET); /* address part ignored */
584 udelay(100);
585
586 /*
587 * Before the CA signal is asserted, the default SCP address
588 * (0x00fffff4) can be changed to a 16-byte aligned value
589 */
590 PORT(va_to_pa(&lp->scp), PORT_ALTSCP); /* change the scp address */
591
592 /*
593 * The initialization procedure begins when a
594 * Channel Attention signal is asserted after a reset.
595 */
596
597 CA();
598
599 /*
600 * The ISCP busy is cleared by the 82596 after the SCB address is read.
601 */
602 boguscnt = 100;
603 while (lp->iscp.busy) {
604 if (--boguscnt == 0) {
605 /* No i82596 present? */
606 printk("%s: i82596 initialization timed out\n",
607 dev->name);
608 return 1;
609 }
610 udelay(5);
611 barrier();
612 }
613 /* I find here boguscnt==100, so no delay was required. */
614
615 return 0;
616}
617
618static int
619init_i596(struct net_device *dev) {
620 struct i596_private *lp;
621
622 if (i596_scp_setup(dev))
623 return 1;
624
Wang Chen454d7c92008-11-12 23:37:49 -0800625 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 lp->scb.command = 0;
627
628 memcpy ((void *)lp->i596_config, init_setup, 14);
629 lp->set_conf.command = CmdConfigure;
630 i596_add_cmd(dev, (void *)&lp->set_conf);
631
632 memcpy ((void *)lp->eth_addr, dev->dev_addr, 6);
633 lp->set_add.command = CmdIASetup;
634 i596_add_cmd(dev, (struct i596_cmd *)&lp->set_add);
635
636 lp->tdr.command = CmdTDR;
637 i596_add_cmd(dev, (struct i596_cmd *)&lp->tdr);
638
639 if (lp->scb.command && i596_timeout(dev, "i82596 init", 200))
640 return 1;
641
642 lp->scb.command = RX_START;
643 CA();
644
645 barrier();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (lp->scb.command && i596_timeout(dev, "Receive Unit start", 100))
648 return 1;
649
650 return 0;
651}
652
653/* Receive a single frame */
654static inline int
655i596_rx_one(struct net_device *dev, struct i596_private *lp,
656 struct i596_rfd *rfd, int *frames) {
657
658 if (rfd->stat & RFD_STAT_OK) {
659 /* a good frame */
660 int pkt_len = (rfd->count & 0x3fff);
661 struct sk_buff *skb = dev_alloc_skb(pkt_len);
662
663 (*frames)++;
664
665 if (rfd->cmd & CMD_EOL)
666 printk("Received on EOL\n");
667
668 if (skb == NULL) {
669 printk ("%s: i596_rx Memory squeeze, "
670 "dropping packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700671 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return 1;
673 }
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 memcpy(skb_put(skb,pkt_len), rfd->data, pkt_len);
676
677 skb->protocol = eth_type_trans(skb,dev);
678 netif_rx(skb);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700679 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 } else {
681#if 0
682 printk("Frame reception error status %04x\n",
683 rfd->stat);
684#endif
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700685 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (rfd->stat & RFD_COLLISION)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700687 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (rfd->stat & RFD_SHORT_FRAME_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700689 dev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if (rfd->stat & RFD_DMA_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700691 dev->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (rfd->stat & RFD_NOBUFS_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700693 dev->stats.rx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 if (rfd->stat & RFD_ALIGN_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700695 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (rfd->stat & RFD_CRC_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700697 dev->stats.rx_crc_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (rfd->stat & RFD_LENGTH_ERR)
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700699 dev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 rfd->stat = rfd->count = 0;
702 return 0;
703}
704
705static int
706i596_rx(struct net_device *dev) {
Wang Chen454d7c92008-11-12 23:37:49 -0800707 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 struct i596_rfd *rfd;
709 int frames = 0;
710
711 while (1) {
712 rfd = pa_to_va(lp->scb.pa_rfd);
713 if (!rfd) {
714 printk(KERN_ERR "i596_rx: NULL rfd?\n");
715 return 0;
716 }
717#if 1
718 if (rfd->stat && !(rfd->stat & (RFD_STAT_C | RFD_STAT_B)))
719 printk("SF:%p-%04x\n", rfd, rfd->stat);
720#endif
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 */
725 rfd->cmd = CMD_EOL;
726 lp->rx_tail->cmd = 0;
727 lp->rx_tail = rfd;
728 lp->scb.pa_rfd = rfd->pa_next;
729 barrier();
730 }
731
732 return frames;
733}
734
735static void
736i596_cleanup_cmd(struct net_device *dev) {
737 struct i596_private *lp;
738 struct i596_cmd *cmd;
739
Wang Chen454d7c92008-11-12 23:37:49 -0800740 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 while (lp->cmd_head) {
742 cmd = (struct i596_cmd *)lp->cmd_head;
743
744 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
745 lp->cmd_backlog--;
746
747 switch ((cmd->command) & 0x7) {
748 case CmdTx: {
749 struct tx_cmd *tx_cmd = (struct tx_cmd *) cmd;
750 struct i596_tbd * tx_cmd_tbd;
751 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
752
753 dev_kfree_skb_any(tx_cmd_tbd->skb);
754
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700755 dev->stats.tx_errors++;
756 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 cmd->pa_next = I596_NULL;
759 kfree((unsigned char *)tx_cmd);
760 netif_wake_queue(dev);
761 break;
762 }
763 case CmdMulticastList: {
764 // unsigned short count = *((unsigned short *) (ptr + 1));
765
766 cmd->pa_next = I596_NULL;
767 kfree((unsigned char *)cmd);
768 break;
769 }
770 default: {
771 cmd->pa_next = I596_NULL;
772 break;
773 }
774 }
775 barrier();
776 }
777
778 if (lp->scb.command && i596_timeout(dev, "i596_cleanup_cmd", 100))
779 ;
780
781 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
782}
783
784static void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr) {
785
786 if (lp->scb.command && i596_timeout(dev, "i596_reset", 100))
787 ;
788
789 netif_stop_queue(dev);
790
791 lp->scb.command = CUC_ABORT | RX_ABORT;
792 CA();
793 barrier();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 /* wait for shutdown */
796 if (lp->scb.command && i596_timeout(dev, "i596_reset(2)", 400))
797 ;
798
799 i596_cleanup_cmd(dev);
800 i596_rx(dev);
801
802 netif_start_queue(dev);
803 /*dev_kfree_skb(skb, FREE_WRITE);*/
804 init_i596(dev);
805}
806
807static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) {
Wang Chen454d7c92008-11-12 23:37:49 -0800808 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 int ioaddr = dev->base_addr;
810 unsigned long flags;
811
812 cmd->status = 0;
813 cmd->command |= (CMD_EOL | CMD_INTR);
814 cmd->pa_next = I596_NULL;
815
816 spin_lock_irqsave(&lp->cmd_lock, flags);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (lp->cmd_head) {
819 lp->cmd_tail->pa_next = va_to_pa(cmd);
820 } else {
821 lp->cmd_head = cmd;
822 if (lp->scb.command && i596_timeout(dev, "i596_add_cmd", 100))
823 ;
824 lp->scb.pa_cmd = va_to_pa(cmd);
825 lp->scb.command = CUC_START;
826 CA();
827 }
828 lp->cmd_tail = cmd;
829 lp->cmd_backlog++;
830
831 lp->cmd_head = pa_to_va(lp->scb.pa_cmd);
832 spin_unlock_irqrestore(&lp->cmd_lock, flags);
833
834 if (lp->cmd_backlog > 16) {
835 int tickssofar = jiffies - lp->last_cmd;
836 if (tickssofar < HZ/4)
837 return;
838
839 printk(KERN_WARNING "%s: command unit timed out, status resetting.\n", dev->name);
840 i596_reset(dev, lp, ioaddr);
841 }
842}
843
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400844static int i596_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
846 int i;
847
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700848 i = request_irq(dev->irq, &i596_interrupt, IRQF_SHARED, dev->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (i) {
850 printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
851 return i;
852 }
853
854 if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE)
855 printk(KERN_ERR "%s: only able to allocate %d receive buffers\n", dev->name, i);
856
857 if (i < 4) {
858 free_irq(dev->irq, dev);
859 return -EAGAIN;
860 }
861 netif_start_queue(dev);
862 init_i596(dev);
863 return 0; /* Always succeed */
864}
865
866static int i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 struct tx_cmd *tx_cmd;
868 short length;
869
870 length = skb->len;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (length < ETH_ZLEN) {
Herbert Xu5b057c62006-06-23 02:06:41 -0700873 if (skb_padto(skb, ETH_ZLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return 0;
875 length = ETH_ZLEN;
876 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 dev->trans_start = jiffies;
879
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800880 tx_cmd = kmalloc((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (tx_cmd == NULL) {
882 printk(KERN_WARNING "%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700883 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 dev_kfree_skb (skb);
885 } else {
886 struct i596_tbd *tx_cmd_tbd;
887 tx_cmd_tbd = (struct i596_tbd *) (tx_cmd + 1);
888 tx_cmd->pa_tbd = va_to_pa (tx_cmd_tbd);
889 tx_cmd_tbd->pa_next = I596_NULL;
890
891 tx_cmd->cmd.command = (CMD_FLEX | CmdTx);
892
893 tx_cmd->pad = 0;
894 tx_cmd->size = 0;
895 tx_cmd_tbd->pad = 0;
896 tx_cmd_tbd->size = (EOF | length);
897
898 tx_cmd_tbd->pa_data = va_to_pa (skb->data);
899 tx_cmd_tbd->skb = skb;
900
901 if (i596_debug & LOG_SRCDST)
902 print_eth (skb->data);
903
904 i596_add_cmd (dev, (struct i596_cmd *) tx_cmd);
905
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700906 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 }
908
909 return 0;
910}
911
912static void
913i596_tx_timeout (struct net_device *dev) {
Wang Chen454d7c92008-11-12 23:37:49 -0800914 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 int ioaddr = dev->base_addr;
916
917 /* Transmitter timeout, serious problems. */
918 printk(KERN_WARNING "%s: transmit timed out, status resetting.\n", dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700919 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 /* Try to restart the adaptor */
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700922 if (lp->last_restart == dev->stats.tx_packets) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 printk ("Resetting board.\n");
924
925 /* Shutdown and restart */
926 i596_reset (dev, lp, ioaddr);
927 } else {
928 /* Issue a channel attention signal */
929 printk ("Kicking board.\n");
930 lp->scb.command = (CUC_START | RX_START);
931 CA();
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700932 lp->last_restart = dev->stats.tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934 netif_wake_queue(dev);
935}
936
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400937static void print_eth(char *add)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
939 int i;
940
941 printk ("Dest ");
942 for (i = 0; i < 6; i++)
943 printk(" %2.2X", (unsigned char) add[i]);
944 printk ("\n");
945
946 printk ("Source");
947 for (i = 0; i < 6; i++)
948 printk(" %2.2X", (unsigned char) add[i+6]);
949 printk ("\n");
950
951 printk ("type %2.2X%2.2X\n",
952 (unsigned char) add[12], (unsigned char) add[13]);
953}
954
955static int __init lp486e_probe(struct net_device *dev) {
956 struct i596_private *lp;
957 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 };
958 unsigned char *bios;
959 int i, j;
960 int ret = -ENOMEM;
961 static int probed;
962
963 if (probed)
964 return -ENODEV;
965 probed++;
966
967 if (!request_region(IOADDR, LP486E_TOTAL_SIZE, DRV_NAME)) {
968 printk(KERN_ERR "lp486e: IO address 0x%x in use\n", IOADDR);
969 return -EBUSY;
970 }
971
Wang Chen454d7c92008-11-12 23:37:49 -0800972 lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 spin_lock_init(&lp->cmd_lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 /*
976 * Do we really have this thing?
977 */
978 if (i596_scp_setup(dev)) {
979 ret = -ENODEV;
980 goto err_out_kfree;
981 }
982
983 dev->base_addr = IOADDR;
984 dev->irq = IRQ;
985
986
987 /*
988 * How do we find the ethernet address? I don't know.
989 * One possibility is to look at the EISA configuration area
990 * [0xe8000-0xe9fff]. This contains the ethernet address
991 * but not at a fixed address - things depend on setup options.
992 *
993 * If we find no address, or the wrong address, use
994 * ifconfig eth0 hw ether a1:a2:a3:a4:a5:a6
995 * with the value found in the BIOS setup.
996 */
997 bios = bus_to_virt(0xe8000);
998 for (j = 0; j < 0x2000; j++) {
999 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) {
1000 printk("%s: maybe address at BIOS 0x%x:",
1001 dev->name, 0xe8000+j);
1002 for (i = 0; i < 6; i++) {
1003 eth_addr[i] = bios[i+j];
1004 printk(" %2.2X", eth_addr[i]);
1005 }
1006 printk("\n");
1007 }
1008 }
1009
1010 printk("%s: lp486e 82596 at %#3lx, IRQ %d,",
1011 dev->name, dev->base_addr, dev->irq);
1012 for (i = 0; i < 6; i++)
1013 printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]);
1014 printk("\n");
1015
1016 /* The LP486E-specific entries in the device structure. */
1017 dev->open = &i596_open;
1018 dev->stop = &i596_close;
1019 dev->hard_start_xmit = &i596_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 dev->set_multicast_list = &set_multicast_list;
1021 dev->watchdog_timeo = 5*HZ;
1022 dev->tx_timeout = i596_tx_timeout;
1023
1024#if 0
1025 /* selftest reports 0x320925ae - don't know what that means */
1026 i596_port_do(dev, PORT_SELFTEST, "selftest");
1027 i596_port_do(dev, PORT_DUMP, "dump");
1028#endif
1029 return 0;
1030
1031err_out_kfree:
1032 release_region(IOADDR, LP486E_TOTAL_SIZE);
1033 return ret;
1034}
1035
1036static inline void
1037i596_handle_CU_completion(struct net_device *dev,
1038 struct i596_private *lp,
1039 unsigned short status,
1040 unsigned short *ack_cmdp) {
1041 struct i596_cmd *cmd;
1042 int frames_out = 0;
1043 int commands_done = 0;
1044 int cmd_val;
1045 unsigned long flags;
1046
1047 spin_lock_irqsave(&lp->cmd_lock, flags);
1048 cmd = lp->cmd_head;
1049
1050 while (lp->cmd_head && (lp->cmd_head->status & CMD_STAT_C)) {
1051 cmd = lp->cmd_head;
1052
1053 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next);
1054 lp->cmd_backlog--;
1055
1056 commands_done++;
1057 cmd_val = cmd->command & 0x7;
1058#if 0
1059 printk("finished CU %s command (%d)\n",
1060 CUcmdnames[cmd_val], cmd_val);
1061#endif
1062 switch (cmd_val) {
1063 case CmdTx:
1064 {
1065 struct tx_cmd *tx_cmd;
1066 struct i596_tbd *tx_cmd_tbd;
1067
1068 tx_cmd = (struct tx_cmd *) cmd;
1069 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd);
1070
1071 frames_out++;
1072 if (cmd->status & CMD_STAT_OK) {
1073 if (i596_debug)
1074 print_eth(pa_to_va(tx_cmd_tbd->pa_data));
1075 } else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001076 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 if (i596_debug)
1078 printk("transmission failure:%04x\n",
1079 cmd->status);
1080 if (cmd->status & 0x0020)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001081 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 if (!(cmd->status & 0x0040))
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001083 dev->stats.tx_heartbeat_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (cmd->status & 0x0400)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001085 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (cmd->status & 0x0800)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001087 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (cmd->status & 0x1000)
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001089 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 dev_kfree_skb_irq(tx_cmd_tbd->skb);
1092
1093 cmd->pa_next = I596_NULL;
1094 kfree((unsigned char *)tx_cmd);
1095 netif_wake_queue(dev);
1096 break;
1097 }
1098
1099 case CmdMulticastList:
1100 cmd->pa_next = I596_NULL;
1101 kfree((unsigned char *)cmd);
1102 break;
1103
1104 case CmdTDR:
1105 {
1106 unsigned long status = *((unsigned long *) (cmd + 1));
1107 if (status & 0x8000) {
1108 if (i596_debug)
1109 printk("%s: link ok.\n", dev->name);
1110 } else {
1111 if (status & 0x4000)
1112 printk("%s: Transceiver problem.\n",
1113 dev->name);
1114 if (status & 0x2000)
1115 printk("%s: Termination problem.\n",
1116 dev->name);
1117 if (status & 0x1000)
1118 printk("%s: Short circuit.\n",
1119 dev->name);
1120 printk("%s: Time %ld.\n",
1121 dev->name, status & 0x07ff);
1122 }
1123 }
1124 default:
1125 cmd->pa_next = I596_NULL;
1126 lp->last_cmd = jiffies;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
1129 barrier();
1130 }
1131
1132 cmd = lp->cmd_head;
1133 while (cmd && (cmd != lp->cmd_tail)) {
1134 cmd->command &= 0x1fff;
1135 cmd = pa_to_va(cmd->pa_next);
1136 barrier();
1137 }
1138
1139 if (lp->cmd_head)
1140 *ack_cmdp |= CUC_START;
1141 lp->scb.pa_cmd = va_to_pa(lp->cmd_head);
1142 spin_unlock_irqrestore(&lp->cmd_lock, flags);
1143}
1144
1145static irqreturn_t
Jeff Garzikcba05162007-11-23 21:50:34 -05001146i596_interrupt(int irq, void *dev_instance)
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001147{
1148 struct net_device *dev = dev_instance;
Wang Chen454d7c92008-11-12 23:37:49 -08001149 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 unsigned short status, ack_cmd = 0;
1151 int frames_in = 0;
1152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 /*
1154 * The 82596 examines the command, performs the required action,
1155 * and then clears the SCB command word.
1156 */
1157 if (lp->scb.command && i596_timeout(dev, "interrupt", 40))
1158 ;
1159
1160 /*
1161 * The status word indicates the status of the 82596.
1162 * It is modified only by the 82596.
1163 *
1164 * [So, we must not clear it. I find often status 0xffff,
1165 * which is not one of the values allowed by the docs.]
1166 */
1167 status = lp->scb.status;
1168#if 0
1169 if (i596_debug) {
1170 printk("%s: i596 interrupt, ", dev->name);
1171 i596_out_status(status);
1172 }
1173#endif
1174 /* Impossible, but it happens - perhaps when we get
1175 a receive interrupt but scb.pa_rfd is I596_NULL. */
1176 if (status == 0xffff) {
1177 printk("%s: i596_interrupt: got status 0xffff\n", dev->name);
1178 goto out;
1179 }
1180
1181 ack_cmd = (status & STAT_ACK);
1182
1183 if (status & (STAT_CX | STAT_CNA))
1184 i596_handle_CU_completion(dev, lp, status, &ack_cmd);
1185
1186 if (status & (STAT_FR | STAT_RNR)) {
1187 /* Restart the receive unit when it got inactive somehow */
1188 if ((status & STAT_RNR) && netif_running(dev))
1189 ack_cmd |= RX_START;
1190
1191 if (status & STAT_FR) {
1192 frames_in = i596_rx(dev);
1193 if (!frames_in)
1194 printk("receive frame reported, but no frames\n");
1195 }
1196 }
1197
1198 /* acknowledge the interrupt */
1199 /*
1200 if ((lp->scb.pa_cmd != I596_NULL) && netif_running(dev))
1201 ack_cmd |= CUC_START;
1202 */
1203
1204 if (lp->scb.command && i596_timeout(dev, "i596 interrupt", 100))
1205 ;
1206
1207 lp->scb.command = ack_cmd;
1208
1209 CLEAR_INT();
1210 CA();
1211
1212 out:
1213 return IRQ_HANDLED;
1214}
1215
1216static int i596_close(struct net_device *dev) {
Wang Chen454d7c92008-11-12 23:37:49 -08001217 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 netif_stop_queue(dev);
1220
1221 if (i596_debug)
1222 printk("%s: Shutting down ethercard, status was %4.4x.\n",
1223 dev->name, lp->scb.status);
1224
1225 lp->scb.command = (CUC_ABORT | RX_ABORT);
1226 CA();
1227
1228 i596_cleanup_cmd(dev);
1229
1230 if (lp->scb.command && i596_timeout(dev, "i596_close", 200))
1231 ;
1232
1233 free_irq(dev->irq, dev);
1234 remove_rx_bufs(dev);
1235
1236 return 0;
1237}
1238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239/*
1240* Set or clear the multicast filter for this adaptor.
1241*/
1242
1243static void set_multicast_list(struct net_device *dev) {
Wang Chen454d7c92008-11-12 23:37:49 -08001244 struct i596_private *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 struct i596_cmd *cmd;
1246
1247 if (i596_debug > 1)
1248 printk ("%s: set multicast list %d\n",
1249 dev->name, dev->mc_count);
1250
1251 if (dev->mc_count > 0) {
1252 struct dev_mc_list *dmi;
1253 char *cp;
Robert P. J. Day5cbded52006-12-13 00:35:56 -08001254 cmd = kmalloc(sizeof(struct i596_cmd)+2+dev->mc_count*6, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 if (cmd == NULL) {
1256 printk (KERN_ERR "%s: set_multicast Memory squeeze.\n", dev->name);
1257 return;
1258 }
1259 cmd->command = CmdMulticastList;
1260 *((unsigned short *) (cmd + 1)) = dev->mc_count * 6;
1261 cp = ((char *)(cmd + 1))+2;
1262 for (dmi = dev->mc_list; dmi != NULL; dmi = dmi->next) {
1263 memcpy(cp, dmi,6);
1264 cp += 6;
1265 }
1266 if (i596_debug & LOG_SRCDST)
1267 print_eth (((char *)(cmd + 1)) + 2);
1268 i596_add_cmd(dev, cmd);
1269 } else {
1270 if (lp->set_conf.pa_next != I596_NULL) {
1271 return;
1272 }
1273 if (dev->mc_count == 0 && !(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 lp->i596_config[8] &= ~0x01;
1275 } else {
1276 lp->i596_config[8] |= 0x01;
1277 }
1278
1279 i596_add_cmd(dev, (struct i596_cmd *) &lp->set_conf);
1280 }
1281}
1282
1283MODULE_AUTHOR("Ard van Breemen <ard@cstmel.nl.eu.org>");
1284MODULE_DESCRIPTION("Intel Panther onboard i82596 driver");
1285MODULE_LICENSE("GPL");
1286
1287static struct net_device *dev_lp486e;
1288static int full_duplex;
1289static int options;
1290static int io = IOADDR;
1291static int irq = IRQ;
1292
1293module_param(debug, int, 0);
1294//module_param(max_interrupt_work, int, 0);
1295//module_param(reverse_probe, int, 0);
1296//module_param(rx_copybreak, int, 0);
1297module_param(options, int, 0);
1298module_param(full_duplex, int, 0);
1299
1300static int __init lp486e_init_module(void) {
1301 int err;
1302 struct net_device *dev = alloc_etherdev(sizeof(struct i596_private));
1303 if (!dev)
1304 return -ENOMEM;
1305
1306 dev->irq = irq;
1307 dev->base_addr = io;
1308 err = lp486e_probe(dev);
1309 if (err) {
1310 free_netdev(dev);
1311 return err;
1312 }
1313 err = register_netdev(dev);
1314 if (err) {
1315 release_region(dev->base_addr, LP486E_TOTAL_SIZE);
1316 free_netdev(dev);
1317 return err;
1318 }
1319 dev_lp486e = dev;
1320 full_duplex = 0;
1321 options = 0;
1322 return 0;
1323}
1324
1325static void __exit lp486e_cleanup_module(void) {
1326 unregister_netdev(dev_lp486e);
1327 release_region(dev_lp486e->base_addr, LP486E_TOTAL_SIZE);
1328 free_netdev(dev_lp486e);
1329}
1330
1331module_init(lp486e_init_module);
1332module_exit(lp486e_cleanup_module);