aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/lasi_82596.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/lasi_82596.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/lasi_82596.c')
-rw-r--r--drivers/net/lasi_82596.c1607
1 files changed, 1607 insertions, 0 deletions
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
new file mode 100644
index 000000000000..5e263fcba669
--- /dev/null
+++ b/drivers/net/lasi_82596.c
@@ -0,0 +1,1607 @@
1/* lasi_82596.c -- driver for the intel 82596 ethernet controller, as
2 munged into HPPA boxen .
3
4 This driver is based upon 82596.c, original credits are below...
5 but there were too many hoops which HP wants jumped through to
6 keep this code in there in a sane manner.
7
8 3 primary sources of the mess --
9 1) hppa needs *lots* of cacheline flushing to keep this kind of
10 MMIO running.
11
12 2) The 82596 needs to see all of its pointers as their physical
13 address. Thus virt_to_bus/bus_to_virt are *everywhere*.
14
15 3) The implementation HP is using seems to be significantly pickier
16 about when and how the command and RX units are started. some
17 command ordering was changed.
18
19 Examination of the mach driver leads one to believe that there
20 might be a saner way to pull this off... anyone who feels like a
21 full rewrite can be my guest.
22
23 Split 02/13/2000 Sam Creasey (sammy@oh.verio.com)
24
25 02/01/2000 Initial modifications for parisc by Helge Deller (deller@gmx.de)
26 03/02/2000 changes for better/correct(?) cache-flushing (deller)
27*/
28
29/* 82596.c: A generic 82596 ethernet driver for linux. */
30/*
31 Based on Apricot.c
32 Written 1994 by Mark Evans.
33 This driver is for the Apricot 82596 bus-master interface
34
35 Modularised 12/94 Mark Evans
36
37
38 Modified to support the 82596 ethernet chips on 680x0 VME boards.
39 by Richard Hirst <richard@sleepie.demon.co.uk>
40 Renamed to be 82596.c
41
42 980825: Changed to receive directly in to sk_buffs which are
43 allocated at open() time. Eliminates copy on incoming frames
44 (small ones are still copied). Shared data now held in a
45 non-cached page, so we can run on 68060 in copyback mode.
46
47 TBD:
48 * look at deferring rx frames rather than discarding (as per tulip)
49 * handle tx ring full as per tulip
50 * performace test to tune rx_copybreak
51
52 Most of my modifications relate to the braindead big-endian
53 implementation by Intel. When the i596 is operating in
54 'big-endian' mode, it thinks a 32 bit value of 0x12345678
55 should be stored as 0x56781234. This is a real pain, when
56 you have linked lists which are shared by the 680x0 and the
57 i596.
58
59 Driver skeleton
60 Written 1993 by Donald Becker.
61 Copyright 1993 United States Government as represented by the Director,
62 National Security Agency. This software may only be used and distributed
63 according to the terms of the GNU General Public License as modified by SRC,
64 incorporated herein by reference.
65
66 The author may be reached as becker@scyld.com, or C/O
67 Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
68
69 */
70
71#include <linux/module.h>
72#include <linux/kernel.h>
73#include <linux/string.h>
74#include <linux/ptrace.h>
75#include <linux/errno.h>
76#include <linux/ioport.h>
77#include <linux/slab.h>
78#include <linux/interrupt.h>
79#include <linux/delay.h>
80#include <linux/netdevice.h>
81#include <linux/etherdevice.h>
82#include <linux/skbuff.h>
83#include <linux/init.h>
84#include <linux/pci.h>
85#include <linux/types.h>
86#include <linux/bitops.h>
87
88#include <asm/io.h>
89#include <asm/pgtable.h>
90#include <asm/irq.h>
91#include <asm/pdc.h>
92#include <asm/cache.h>
93#include <asm/parisc-device.h>
94
95#define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30"
96
97/* DEBUG flags
98 */
99
100#define DEB_INIT 0x0001
101#define DEB_PROBE 0x0002
102#define DEB_SERIOUS 0x0004
103#define DEB_ERRORS 0x0008
104#define DEB_MULTI 0x0010
105#define DEB_TDR 0x0020
106#define DEB_OPEN 0x0040
107#define DEB_RESET 0x0080
108#define DEB_ADDCMD 0x0100
109#define DEB_STATUS 0x0200
110#define DEB_STARTTX 0x0400
111#define DEB_RXADDR 0x0800
112#define DEB_TXADDR 0x1000
113#define DEB_RXFRAME 0x2000
114#define DEB_INTS 0x4000
115#define DEB_STRUCT 0x8000
116#define DEB_ANY 0xffff
117
118
119#define DEB(x,y) if (i596_debug & (x)) { y; }
120
121
122#define CHECK_WBACK(addr,len) \
123 do { dma_cache_sync((void *)addr, len, DMA_TO_DEVICE); } while (0)
124
125#define CHECK_INV(addr,len) \
126 do { dma_cache_sync((void *)addr, len, DMA_FROM_DEVICE); } while(0)
127
128#define CHECK_WBACK_INV(addr,len) \
129 do { dma_cache_sync((void *)addr, len, DMA_BIDIRECTIONAL); } while (0)
130
131
132#define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
133#define PA_CPU_PORT_L_ACCESS 4
134#define PA_CHANNEL_ATTENTION 8
135
136
137/*
138 * Define various macros for Channel Attention, word swapping etc., dependent
139 * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
140 */
141
142#ifdef __BIG_ENDIAN
143#define WSWAPrfd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
144#define WSWAPrbd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
145#define WSWAPiscp(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
146#define WSWAPscb(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
147#define WSWAPcmd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
148#define WSWAPtbd(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
149#define WSWAPchar(x) (((u32)(x)<<16) | ((((u32)(x)))>>16))
150#define ISCP_BUSY 0x00010000
151#define MACH_IS_APRICOT 0
152#else
153#define WSWAPrfd(x) ((struct i596_rfd *)(x))
154#define WSWAPrbd(x) ((struct i596_rbd *)(x))
155#define WSWAPiscp(x) ((struct i596_iscp *)(x))
156#define WSWAPscb(x) ((struct i596_scb *)(x))
157#define WSWAPcmd(x) ((struct i596_cmd *)(x))
158#define WSWAPtbd(x) ((struct i596_tbd *)(x))
159#define WSWAPchar(x) ((char *)(x))
160#define ISCP_BUSY 0x0001
161#define MACH_IS_APRICOT 1
162#endif
163
164/*
165 * The MPU_PORT command allows direct access to the 82596. With PORT access
166 * the following commands are available (p5-18). The 32-bit port command
167 * must be word-swapped with the most significant word written first.
168 * This only applies to VME boards.
169 */
170#define PORT_RESET 0x00 /* reset 82596 */
171#define PORT_SELFTEST 0x01 /* selftest */
172#define PORT_ALTSCP 0x02 /* alternate SCB address */
173#define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
174
175static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
176
177MODULE_AUTHOR("Richard Hirst");
178MODULE_DESCRIPTION("i82596 driver");
179MODULE_LICENSE("GPL");
180MODULE_PARM(i596_debug, "i");
181MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
182
183/* Copy frames shorter than rx_copybreak, otherwise pass on up in
184 * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
185 */
186static int rx_copybreak = 100;
187
188#define MAX_DRIVERS 4 /* max count of drivers */
189
190#define PKT_BUF_SZ 1536
191#define MAX_MC_CNT 64
192
193#define I596_NULL ((u32)0xffffffff)
194
195#define CMD_EOL 0x8000 /* The last command of the list, stop. */
196#define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
197#define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
198
199#define CMD_FLEX 0x0008 /* Enable flexible memory model */
200
201enum commands {
202 CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
203 CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
204};
205
206#define STAT_C 0x8000 /* Set to 0 after execution */
207#define STAT_B 0x4000 /* Command being executed */
208#define STAT_OK 0x2000 /* Command executed ok */
209#define STAT_A 0x1000 /* Command aborted */
210
211#define CUC_START 0x0100
212#define CUC_RESUME 0x0200
213#define CUC_SUSPEND 0x0300
214#define CUC_ABORT 0x0400
215#define RX_START 0x0010
216#define RX_RESUME 0x0020
217#define RX_SUSPEND 0x0030
218#define RX_ABORT 0x0040
219
220#define TX_TIMEOUT 5
221
222#define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */
223
224
225struct i596_reg {
226 unsigned short porthi;
227 unsigned short portlo;
228 u32 ca;
229};
230
231#define EOF 0x8000
232#define SIZE_MASK 0x3fff
233
234struct i596_tbd {
235 unsigned short size;
236 unsigned short pad;
237 dma_addr_t next;
238 dma_addr_t data;
239 u32 cache_pad[5]; /* Total 32 bytes... */
240};
241
242/* The command structure has two 'next' pointers; v_next is the address of
243 * the next command as seen by the CPU, b_next is the address of the next
244 * command as seen by the 82596. The b_next pointer, as used by the 82596
245 * always references the status field of the next command, rather than the
246 * v_next field, because the 82596 is unaware of v_next. It may seem more
247 * logical to put v_next at the end of the structure, but we cannot do that
248 * because the 82596 expects other fields to be there, depending on command
249 * type.
250 */
251
252struct i596_cmd {
253 struct i596_cmd *v_next; /* Address from CPUs viewpoint */
254 unsigned short status;
255 unsigned short command;
256 dma_addr_t b_next; /* Address from i596 viewpoint */
257};
258
259struct tx_cmd {
260 struct i596_cmd cmd;
261 dma_addr_t tbd;
262 unsigned short size;
263 unsigned short pad;
264 struct sk_buff *skb; /* So we can free it after tx */
265 dma_addr_t dma_addr;
266#ifdef __LP64__
267 u32 cache_pad[6]; /* Total 64 bytes... */
268#else
269 u32 cache_pad[1]; /* Total 32 bytes... */
270#endif
271};
272
273struct tdr_cmd {
274 struct i596_cmd cmd;
275 unsigned short status;
276 unsigned short pad;
277};
278
279struct mc_cmd {
280 struct i596_cmd cmd;
281 short mc_cnt;
282 char mc_addrs[MAX_MC_CNT*6];
283};
284
285struct sa_cmd {
286 struct i596_cmd cmd;
287 char eth_addr[8];
288};
289
290struct cf_cmd {
291 struct i596_cmd cmd;
292 char i596_config[16];
293};
294
295struct i596_rfd {
296 unsigned short stat;
297 unsigned short cmd;
298 dma_addr_t b_next; /* Address from i596 viewpoint */
299 dma_addr_t rbd;
300 unsigned short count;
301 unsigned short size;
302 struct i596_rfd *v_next; /* Address from CPUs viewpoint */
303 struct i596_rfd *v_prev;
304#ifndef __LP64__
305 u32 cache_pad[2]; /* Total 32 bytes... */
306#endif
307};
308
309struct i596_rbd {
310 /* hardware data */
311 unsigned short count;
312 unsigned short zero1;
313 dma_addr_t b_next;
314 dma_addr_t b_data; /* Address from i596 viewpoint */
315 unsigned short size;
316 unsigned short zero2;
317 /* driver data */
318 struct sk_buff *skb;
319 struct i596_rbd *v_next;
320 dma_addr_t b_addr; /* This rbd addr from i596 view */
321 unsigned char *v_data; /* Address from CPUs viewpoint */
322 /* Total 32 bytes... */
323#ifdef __LP64__
324 u32 cache_pad[4];
325#endif
326};
327
328/* These values as chosen so struct i596_private fits in one page... */
329
330#define TX_RING_SIZE 32
331#define RX_RING_SIZE 16
332
333struct i596_scb {
334 unsigned short status;
335 unsigned short command;
336 dma_addr_t cmd;
337 dma_addr_t rfd;
338 u32 crc_err;
339 u32 align_err;
340 u32 resource_err;
341 u32 over_err;
342 u32 rcvdt_err;
343 u32 short_err;
344 unsigned short t_on;
345 unsigned short t_off;
346};
347
348struct i596_iscp {
349 u32 stat;
350 dma_addr_t scb;
351};
352
353struct i596_scp {
354 u32 sysbus;
355 u32 pad;
356 dma_addr_t iscp;
357};
358
359struct i596_private {
360 volatile struct i596_scp scp __attribute__((aligned(32)));
361 volatile struct i596_iscp iscp __attribute__((aligned(32)));
362 volatile struct i596_scb scb __attribute__((aligned(32)));
363 struct sa_cmd sa_cmd __attribute__((aligned(32)));
364 struct cf_cmd cf_cmd __attribute__((aligned(32)));
365 struct tdr_cmd tdr_cmd __attribute__((aligned(32)));
366 struct mc_cmd mc_cmd __attribute__((aligned(32)));
367 struct i596_rfd rfds[RX_RING_SIZE] __attribute__((aligned(32)));
368 struct i596_rbd rbds[RX_RING_SIZE] __attribute__((aligned(32)));
369 struct tx_cmd tx_cmds[TX_RING_SIZE] __attribute__((aligned(32)));
370 struct i596_tbd tbds[TX_RING_SIZE] __attribute__((aligned(32)));
371 u32 stat;
372 int last_restart;
373 struct i596_rfd *rfd_head;
374 struct i596_rbd *rbd_head;
375 struct i596_cmd *cmd_tail;
376 struct i596_cmd *cmd_head;
377 int cmd_backlog;
378 u32 last_cmd;
379 struct net_device_stats stats;
380 int next_tx_cmd;
381 int options;
382 spinlock_t lock;
383 dma_addr_t dma_addr;
384 struct device *dev;
385};
386
387static char init_setup[] =
388{
389 0x8E, /* length, prefetch on */
390 0xC8, /* fifo to 8, monitor off */
391 0x80, /* don't save bad frames */
392 0x2E, /* No source address insertion, 8 byte preamble */
393 0x00, /* priority and backoff defaults */
394 0x60, /* interframe spacing */
395 0x00, /* slot time LSB */
396 0xf2, /* slot time and retries */
397 0x00, /* promiscuous mode */
398 0x00, /* collision detect */
399 0x40, /* minimum frame length */
400 0xff,
401 0x00,
402 0x7f /* *multi IA */ };
403
404static int i596_open(struct net_device *dev);
405static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
406static irqreturn_t i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);
407static int i596_close(struct net_device *dev);
408static struct net_device_stats *i596_get_stats(struct net_device *dev);
409static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
410static void i596_tx_timeout (struct net_device *dev);
411static void print_eth(unsigned char *buf, char *str);
412static void set_multicast_list(struct net_device *dev);
413
414static int rx_ring_size = RX_RING_SIZE;
415static int ticks_limit = 100;
416static int max_cmd_backlog = TX_RING_SIZE-1;
417
418
419static inline void CA(struct net_device *dev)
420{
421 gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION);
422}
423
424
425static inline void MPU_PORT(struct net_device *dev, int c, dma_addr_t x)
426{
427 struct i596_private *lp = dev->priv;
428
429 u32 v = (u32) (c) | (u32) (x);
430 u16 a, b;
431
432 if (lp->options & OPT_SWAP_PORT) {
433 a = v >> 16;
434 b = v & 0xffff;
435 } else {
436 a = v & 0xffff;
437 b = v >> 16;
438 }
439
440 gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS);
441 udelay(1);
442 gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
443}
444
445
446static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
447{
448 CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
449 while (--delcnt && lp->iscp.stat) {
450 udelay(10);
451 CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
452 }
453 if (!delcnt) {
454 printk("%s: %s, iscp.stat %04x, didn't clear\n",
455 dev->name, str, lp->iscp.stat);
456 return -1;
457 }
458 else
459 return 0;
460}
461
462
463static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
464{
465 CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
466 while (--delcnt && lp->scb.command) {
467 udelay(10);
468 CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
469 }
470 if (!delcnt) {
471 printk("%s: %s, status %4.4x, cmd %4.4x.\n",
472 dev->name, str, lp->scb.status, lp->scb.command);
473 return -1;
474 }
475 else
476 return 0;
477}
478
479
480static void i596_display_data(struct net_device *dev)
481{
482 struct i596_private *lp = dev->priv;
483 struct i596_cmd *cmd;
484 struct i596_rfd *rfd;
485 struct i596_rbd *rbd;
486
487 printk("lp and scp at %p, .sysbus = %08x, .iscp = %08x\n",
488 &lp->scp, lp->scp.sysbus, lp->scp.iscp);
489 printk("iscp at %p, iscp.stat = %08x, .scb = %08x\n",
490 &lp->iscp, lp->iscp.stat, lp->iscp.scb);
491 printk("scb at %p, scb.status = %04x, .command = %04x,"
492 " .cmd = %08x, .rfd = %08x\n",
493 &lp->scb, lp->scb.status, lp->scb.command,
494 lp->scb.cmd, lp->scb.rfd);
495 printk(" errors: crc %x, align %x, resource %x,"
496 " over %x, rcvdt %x, short %x\n",
497 lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
498 lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
499 cmd = lp->cmd_head;
500 while (cmd != NULL) {
501 printk("cmd at %p, .status = %04x, .command = %04x, .b_next = %08x\n",
502 cmd, cmd->status, cmd->command, cmd->b_next);
503 cmd = cmd->v_next;
504 }
505 rfd = lp->rfd_head;
506 printk("rfd_head = %p\n", rfd);
507 do {
508 printk(" %p .stat %04x, .cmd %04x, b_next %08x, rbd %08x,"
509 " count %04x\n",
510 rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
511 rfd->count);
512 rfd = rfd->v_next;
513 } while (rfd != lp->rfd_head);
514 rbd = lp->rbd_head;
515 printk("rbd_head = %p\n", rbd);
516 do {
517 printk(" %p .count %04x, b_next %08x, b_data %08x, size %04x\n",
518 rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
519 rbd = rbd->v_next;
520 } while (rbd != lp->rbd_head);
521 CHECK_INV(lp, sizeof(struct i596_private));
522}
523
524
525#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
526static void i596_error(int irq, void *dev_id, struct pt_regs *regs)
527{
528 struct net_device *dev = dev_id;
529 volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
530
531 pcc2[0x28] = 1;
532 pcc2[0x2b] = 0x1d;
533 printk("%s: Error interrupt\n", dev->name);
534 i596_display_data(dev);
535}
536#endif
537
538#define virt_to_dma(lp,v) ((lp)->dma_addr + (dma_addr_t)((unsigned long)(v)-(unsigned long)(lp)))
539
540static inline void init_rx_bufs(struct net_device *dev)
541{
542 struct i596_private *lp = dev->priv;
543 int i;
544 struct i596_rfd *rfd;
545 struct i596_rbd *rbd;
546
547 /* First build the Receive Buffer Descriptor List */
548
549 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
550 dma_addr_t dma_addr;
551 struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ + 4);
552
553 if (skb == NULL)
554 panic("%s: alloc_skb() failed", __FILE__);
555 skb_reserve(skb, 2);
556 dma_addr = dma_map_single(lp->dev, skb->tail,PKT_BUF_SZ,
557 DMA_FROM_DEVICE);
558 skb->dev = dev;
559 rbd->v_next = rbd+1;
560 rbd->b_next = WSWAPrbd(virt_to_dma(lp,rbd+1));
561 rbd->b_addr = WSWAPrbd(virt_to_dma(lp,rbd));
562 rbd->skb = skb;
563 rbd->v_data = skb->tail;
564 rbd->b_data = WSWAPchar(dma_addr);
565 rbd->size = PKT_BUF_SZ;
566 }
567 lp->rbd_head = lp->rbds;
568 rbd = lp->rbds + rx_ring_size - 1;
569 rbd->v_next = lp->rbds;
570 rbd->b_next = WSWAPrbd(virt_to_dma(lp,lp->rbds));
571
572 /* Now build the Receive Frame Descriptor List */
573
574 for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
575 rfd->rbd = I596_NULL;
576 rfd->v_next = rfd+1;
577 rfd->v_prev = rfd-1;
578 rfd->b_next = WSWAPrfd(virt_to_dma(lp,rfd+1));
579 rfd->cmd = CMD_FLEX;
580 }
581 lp->rfd_head = lp->rfds;
582 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
583 rfd = lp->rfds;
584 rfd->rbd = WSWAPrbd(virt_to_dma(lp,lp->rbd_head));
585 rfd->v_prev = lp->rfds + rx_ring_size - 1;
586 rfd = lp->rfds + rx_ring_size - 1;
587 rfd->v_next = lp->rfds;
588 rfd->b_next = WSWAPrfd(virt_to_dma(lp,lp->rfds));
589 rfd->cmd = CMD_EOL|CMD_FLEX;
590
591 CHECK_WBACK_INV(lp, sizeof(struct i596_private));
592}
593
594static inline void remove_rx_bufs(struct net_device *dev)
595{
596 struct i596_private *lp = dev->priv;
597 struct i596_rbd *rbd;
598 int i;
599
600 for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
601 if (rbd->skb == NULL)
602 break;
603 dma_unmap_single(lp->dev,
604 (dma_addr_t)WSWAPchar(rbd->b_data),
605 PKT_BUF_SZ, DMA_FROM_DEVICE);
606 dev_kfree_skb(rbd->skb);
607 }
608}
609
610
611static void rebuild_rx_bufs(struct net_device *dev)
612{
613 struct i596_private *lp = dev->priv;
614 int i;
615
616 /* Ensure rx frame/buffer descriptors are tidy */
617
618 for (i = 0; i < rx_ring_size; i++) {
619 lp->rfds[i].rbd = I596_NULL;
620 lp->rfds[i].cmd = CMD_FLEX;
621 }
622 lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
623 lp->rfd_head = lp->rfds;
624 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
625 lp->rbd_head = lp->rbds;
626 lp->rfds[0].rbd = WSWAPrbd(virt_to_dma(lp,lp->rbds));
627
628 CHECK_WBACK_INV(lp, sizeof(struct i596_private));
629}
630
631
632static int init_i596_mem(struct net_device *dev)
633{
634 struct i596_private *lp = dev->priv;
635 unsigned long flags;
636
637 disable_irq(dev->irq); /* disable IRQs from LAN */
638 DEB(DEB_INIT,
639 printk("RESET 82596 port: %p (with IRQ %d disabled)\n",
640 (void*)(dev->base_addr + PA_I82596_RESET),
641 dev->irq));
642
643 gsc_writel(0, (void*)(dev->base_addr + PA_I82596_RESET)); /* Hard Reset */
644 udelay(100); /* Wait 100us - seems to help */
645
646 /* change the scp address */
647
648 lp->last_cmd = jiffies;
649
650
651 lp->scp.sysbus = 0x0000006c;
652 lp->scp.iscp = WSWAPiscp(virt_to_dma(lp,&(lp->iscp)));
653 lp->iscp.scb = WSWAPscb(virt_to_dma(lp,&(lp->scb)));
654 lp->iscp.stat = ISCP_BUSY;
655 lp->cmd_backlog = 0;
656
657 lp->cmd_head = NULL;
658 lp->scb.cmd = I596_NULL;
659
660 DEB(DEB_INIT, printk("%s: starting i82596.\n", dev->name));
661
662 CHECK_WBACK(&(lp->scp), sizeof(struct i596_scp));
663 CHECK_WBACK(&(lp->iscp), sizeof(struct i596_iscp));
664
665 MPU_PORT(dev, PORT_ALTSCP, virt_to_dma(lp,&lp->scp));
666
667 CA(dev);
668
669 if (wait_istat(dev, lp, 1000, "initialization timed out"))
670 goto failed;
671 DEB(DEB_INIT, printk("%s: i82596 initialization successful\n", dev->name));
672
673 /* Ensure rx frame/buffer descriptors are tidy */
674 rebuild_rx_bufs(dev);
675
676 lp->scb.command = 0;
677 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
678
679 enable_irq(dev->irq); /* enable IRQs from LAN */
680
681 DEB(DEB_INIT, printk("%s: queuing CmdConfigure\n", dev->name));
682 memcpy(lp->cf_cmd.i596_config, init_setup, 14);
683 lp->cf_cmd.cmd.command = CmdConfigure;
684 CHECK_WBACK(&(lp->cf_cmd), sizeof(struct cf_cmd));
685 i596_add_cmd(dev, &lp->cf_cmd.cmd);
686
687 DEB(DEB_INIT, printk("%s: queuing CmdSASetup\n", dev->name));
688 memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
689 lp->sa_cmd.cmd.command = CmdSASetup;
690 CHECK_WBACK(&(lp->sa_cmd), sizeof(struct sa_cmd));
691 i596_add_cmd(dev, &lp->sa_cmd.cmd);
692
693 DEB(DEB_INIT, printk("%s: queuing CmdTDR\n", dev->name));
694 lp->tdr_cmd.cmd.command = CmdTDR;
695 CHECK_WBACK(&(lp->tdr_cmd), sizeof(struct tdr_cmd));
696 i596_add_cmd(dev, &lp->tdr_cmd.cmd);
697
698 spin_lock_irqsave (&lp->lock, flags);
699
700 if (wait_cmd(dev, lp, 1000, "timed out waiting to issue RX_START")) {
701 spin_unlock_irqrestore (&lp->lock, flags);
702 goto failed;
703 }
704 DEB(DEB_INIT, printk("%s: Issuing RX_START\n", dev->name));
705 lp->scb.command = RX_START;
706 lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
707 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
708
709 CA(dev);
710
711 spin_unlock_irqrestore (&lp->lock, flags);
712
713 if (wait_cmd(dev, lp, 1000, "RX_START not processed"))
714 goto failed;
715 DEB(DEB_INIT, printk("%s: Receive unit started OK\n", dev->name));
716
717 return 0;
718
719failed:
720 printk("%s: Failed to initialise 82596\n", dev->name);
721 MPU_PORT(dev, PORT_RESET, 0);
722 return -1;
723}
724
725
726static inline int i596_rx(struct net_device *dev)
727{
728 struct i596_private *lp = dev->priv;
729 struct i596_rfd *rfd;
730 struct i596_rbd *rbd;
731 int frames = 0;
732
733 DEB(DEB_RXFRAME, printk("i596_rx(), rfd_head %p, rbd_head %p\n",
734 lp->rfd_head, lp->rbd_head));
735
736
737 rfd = lp->rfd_head; /* Ref next frame to check */
738
739 CHECK_INV(rfd, sizeof(struct i596_rfd));
740 while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
741 if (rfd->rbd == I596_NULL)
742 rbd = NULL;
743 else if (rfd->rbd == lp->rbd_head->b_addr) {
744 rbd = lp->rbd_head;
745 CHECK_INV(rbd, sizeof(struct i596_rbd));
746 }
747 else {
748 printk("%s: rbd chain broken!\n", dev->name);
749 /* XXX Now what? */
750 rbd = NULL;
751 }
752 DEB(DEB_RXFRAME, printk(" rfd %p, rfd.rbd %08x, rfd.stat %04x\n",
753 rfd, rfd->rbd, rfd->stat));
754
755 if (rbd != NULL && ((rfd->stat) & STAT_OK)) {
756 /* a good frame */
757 int pkt_len = rbd->count & 0x3fff;
758 struct sk_buff *skb = rbd->skb;
759 int rx_in_place = 0;
760
761 DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
762 frames++;
763
764 /* Check if the packet is long enough to just accept
765 * without copying to a properly sized skbuff.
766 */
767
768 if (pkt_len > rx_copybreak) {
769 struct sk_buff *newskb;
770 dma_addr_t dma_addr;
771
772 dma_unmap_single(lp->dev,(dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
773 /* Get fresh skbuff to replace filled one. */
774 newskb = dev_alloc_skb(PKT_BUF_SZ + 4);
775 if (newskb == NULL) {
776 skb = NULL; /* drop pkt */
777 goto memory_squeeze;
778 }
779 skb_reserve(newskb, 2);
780
781 /* Pass up the skb already on the Rx ring. */
782 skb_put(skb, pkt_len);
783 rx_in_place = 1;
784 rbd->skb = newskb;
785 newskb->dev = dev;
786 dma_addr = dma_map_single(lp->dev, newskb->tail, PKT_BUF_SZ, DMA_FROM_DEVICE);
787 rbd->v_data = newskb->tail;
788 rbd->b_data = WSWAPchar(dma_addr);
789 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
790 }
791 else
792 skb = dev_alloc_skb(pkt_len + 2);
793memory_squeeze:
794 if (skb == NULL) {
795 /* XXX tulip.c can defer packets here!! */
796 printk("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
797 lp->stats.rx_dropped++;
798 }
799 else {
800 skb->dev = dev;
801 if (!rx_in_place) {
802 /* 16 byte align the data fields */
803 dma_sync_single_for_cpu(lp->dev, (dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
804 skb_reserve(skb, 2);
805 memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
806 dma_sync_single_for_device(lp->dev, (dma_addr_t)WSWAPchar(rbd->b_data), PKT_BUF_SZ, DMA_FROM_DEVICE);
807 }
808 skb->len = pkt_len;
809 skb->protocol=eth_type_trans(skb,dev);
810 netif_rx(skb);
811 dev->last_rx = jiffies;
812 lp->stats.rx_packets++;
813 lp->stats.rx_bytes+=pkt_len;
814 }
815 }
816 else {
817 DEB(DEB_ERRORS, printk("%s: Error, rfd.stat = 0x%04x\n",
818 dev->name, rfd->stat));
819 lp->stats.rx_errors++;
820 if ((rfd->stat) & 0x0001)
821 lp->stats.collisions++;
822 if ((rfd->stat) & 0x0080)
823 lp->stats.rx_length_errors++;
824 if ((rfd->stat) & 0x0100)
825 lp->stats.rx_over_errors++;
826 if ((rfd->stat) & 0x0200)
827 lp->stats.rx_fifo_errors++;
828 if ((rfd->stat) & 0x0400)
829 lp->stats.rx_frame_errors++;
830 if ((rfd->stat) & 0x0800)
831 lp->stats.rx_crc_errors++;
832 if ((rfd->stat) & 0x1000)
833 lp->stats.rx_length_errors++;
834 }
835
836 /* Clear the buffer descriptor count and EOF + F flags */
837
838 if (rbd != NULL && (rbd->count & 0x4000)) {
839 rbd->count = 0;
840 lp->rbd_head = rbd->v_next;
841 CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
842 }
843
844 /* Tidy the frame descriptor, marking it as end of list */
845
846 rfd->rbd = I596_NULL;
847 rfd->stat = 0;
848 rfd->cmd = CMD_EOL|CMD_FLEX;
849 rfd->count = 0;
850
851 /* Remove end-of-list from old end descriptor */
852
853 rfd->v_prev->cmd = CMD_FLEX;
854
855 /* Update record of next frame descriptor to process */
856
857 lp->scb.rfd = rfd->b_next;
858 lp->rfd_head = rfd->v_next;
859 CHECK_WBACK_INV(rfd->v_prev, sizeof(struct i596_rfd));
860 CHECK_WBACK_INV(rfd, sizeof(struct i596_rfd));
861 rfd = lp->rfd_head;
862 CHECK_INV(rfd, sizeof(struct i596_rfd));
863 }
864
865 DEB(DEB_RXFRAME, printk("frames %d\n", frames));
866
867 return 0;
868}
869
870
871static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
872{
873 struct i596_cmd *ptr;
874
875 while (lp->cmd_head != NULL) {
876 ptr = lp->cmd_head;
877 lp->cmd_head = ptr->v_next;
878 lp->cmd_backlog--;
879
880 switch ((ptr->command) & 0x7) {
881 case CmdTx:
882 {
883 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
884 struct sk_buff *skb = tx_cmd->skb;
885 dma_unmap_single(lp->dev, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE);
886
887 dev_kfree_skb(skb);
888
889 lp->stats.tx_errors++;
890 lp->stats.tx_aborted_errors++;
891
892 ptr->v_next = NULL;
893 ptr->b_next = I596_NULL;
894 tx_cmd->cmd.command = 0; /* Mark as free */
895 break;
896 }
897 default:
898 ptr->v_next = NULL;
899 ptr->b_next = I596_NULL;
900 }
901 CHECK_WBACK_INV(ptr, sizeof(struct i596_cmd));
902 }
903
904 wait_cmd(dev, lp, 100, "i596_cleanup_cmd timed out");
905 lp->scb.cmd = I596_NULL;
906 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
907}
908
909
910static inline void i596_reset(struct net_device *dev, struct i596_private *lp)
911{
912 unsigned long flags;
913
914 DEB(DEB_RESET, printk("i596_reset\n"));
915
916 spin_lock_irqsave (&lp->lock, flags);
917
918 wait_cmd(dev, lp, 100, "i596_reset timed out");
919
920 netif_stop_queue(dev);
921
922 /* FIXME: this command might cause an lpmc */
923 lp->scb.command = CUC_ABORT | RX_ABORT;
924 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
925 CA(dev);
926
927 /* wait for shutdown */
928 wait_cmd(dev, lp, 1000, "i596_reset 2 timed out");
929 spin_unlock_irqrestore (&lp->lock, flags);
930
931 i596_cleanup_cmd(dev,lp);
932 i596_rx(dev);
933
934 netif_start_queue(dev);
935 init_i596_mem(dev);
936}
937
938
939static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
940{
941 struct i596_private *lp = dev->priv;
942 unsigned long flags;
943
944 DEB(DEB_ADDCMD, printk("i596_add_cmd cmd_head %p\n", lp->cmd_head));
945
946 cmd->status = 0;
947 cmd->command |= (CMD_EOL | CMD_INTR);
948 cmd->v_next = NULL;
949 cmd->b_next = I596_NULL;
950 CHECK_WBACK(cmd, sizeof(struct i596_cmd));
951
952 spin_lock_irqsave (&lp->lock, flags);
953
954 if (lp->cmd_head != NULL) {
955 lp->cmd_tail->v_next = cmd;
956 lp->cmd_tail->b_next = WSWAPcmd(virt_to_dma(lp,&cmd->status));
957 CHECK_WBACK(lp->cmd_tail, sizeof(struct i596_cmd));
958 } else {
959 lp->cmd_head = cmd;
960 wait_cmd(dev, lp, 100, "i596_add_cmd timed out");
961 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&cmd->status));
962 lp->scb.command = CUC_START;
963 CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
964 CA(dev);
965 }
966 lp->cmd_tail = cmd;
967 lp->cmd_backlog++;
968
969 spin_unlock_irqrestore (&lp->lock, flags);
970
971 if (lp->cmd_backlog > max_cmd_backlog) {
972 unsigned long tickssofar = jiffies - lp->last_cmd;
973
974 if (tickssofar < ticks_limit)
975 return;
976
977 printk("%s: command unit timed out, status resetting.\n", dev->name);
978#if 1
979 i596_reset(dev, lp);
980#endif
981 }
982}
983
984#if 0
985/* this function makes a perfectly adequate probe... but we have a
986 device list */
987static int i596_test(struct net_device *dev)
988{
989 struct i596_private *lp = dev->priv;
990 volatile int *tint;
991 u32 data;
992
993 tint = (volatile int *)(&(lp->scp));
994 data = virt_to_dma(lp,tint);
995
996 tint[1] = -1;
997 CHECK_WBACK(tint,PAGE_SIZE);
998
999 MPU_PORT(dev, 1, data);
1000
1001 for(data = 1000000; data; data--) {
1002 CHECK_INV(tint,PAGE_SIZE);
1003 if(tint[1] != -1)
1004 break;
1005
1006 }
1007
1008 printk("i596_test result %d\n", tint[1]);
1009
1010}
1011#endif
1012
1013
1014static int i596_open(struct net_device *dev)
1015{
1016 DEB(DEB_OPEN, printk("%s: i596_open() irq %d.\n", dev->name, dev->irq));
1017
1018 if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
1019 printk("%s: IRQ %d not free\n", dev->name, dev->irq);
1020 goto out;
1021 }
1022
1023 init_rx_bufs(dev);
1024
1025 if (init_i596_mem(dev)) {
1026 printk("%s: Failed to init memory\n", dev->name);
1027 goto out_remove_rx_bufs;
1028 }
1029
1030 netif_start_queue(dev);
1031
1032 return 0;
1033
1034out_remove_rx_bufs:
1035 remove_rx_bufs(dev);
1036 free_irq(dev->irq, dev);
1037out:
1038 return -EAGAIN;
1039}
1040
1041static void i596_tx_timeout (struct net_device *dev)
1042{
1043 struct i596_private *lp = dev->priv;
1044
1045 /* Transmitter timeout, serious problems. */
1046 DEB(DEB_ERRORS, printk("%s: transmit timed out, status resetting.\n",
1047 dev->name));
1048
1049 lp->stats.tx_errors++;
1050
1051 /* Try to restart the adaptor */
1052 if (lp->last_restart == lp->stats.tx_packets) {
1053 DEB(DEB_ERRORS, printk("Resetting board.\n"));
1054 /* Shutdown and restart */
1055 i596_reset (dev, lp);
1056 } else {
1057 /* Issue a channel attention signal */
1058 DEB(DEB_ERRORS, printk("Kicking board.\n"));
1059 lp->scb.command = CUC_START | RX_START;
1060 CHECK_WBACK_INV(&(lp->scb), sizeof(struct i596_scb));
1061 CA (dev);
1062 lp->last_restart = lp->stats.tx_packets;
1063 }
1064
1065 dev->trans_start = jiffies;
1066 netif_wake_queue (dev);
1067}
1068
1069
1070static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1071{
1072 struct i596_private *lp = dev->priv;
1073 struct tx_cmd *tx_cmd;
1074 struct i596_tbd *tbd;
1075 short length = skb->len;
1076 dev->trans_start = jiffies;
1077
1078 DEB(DEB_STARTTX, printk("%s: i596_start_xmit(%x,%p) called\n", dev->name,
1079 skb->len, skb->data));
1080
1081 if (length < ETH_ZLEN) {
1082 skb = skb_padto(skb, ETH_ZLEN);
1083 if (skb == NULL)
1084 return 0;
1085 length = ETH_ZLEN;
1086 }
1087
1088 netif_stop_queue(dev);
1089
1090 tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
1091 tbd = lp->tbds + lp->next_tx_cmd;
1092
1093 if (tx_cmd->cmd.command) {
1094 DEB(DEB_ERRORS, printk("%s: xmit ring full, dropping packet.\n",
1095 dev->name));
1096 lp->stats.tx_dropped++;
1097
1098 dev_kfree_skb(skb);
1099 } else {
1100 if (++lp->next_tx_cmd == TX_RING_SIZE)
1101 lp->next_tx_cmd = 0;
1102 tx_cmd->tbd = WSWAPtbd(virt_to_dma(lp,tbd));
1103 tbd->next = I596_NULL;
1104
1105 tx_cmd->cmd.command = CMD_FLEX | CmdTx;
1106 tx_cmd->skb = skb;
1107
1108 tx_cmd->pad = 0;
1109 tx_cmd->size = 0;
1110 tbd->pad = 0;
1111 tbd->size = EOF | length;
1112
1113 tx_cmd->dma_addr = dma_map_single(lp->dev, skb->data, skb->len,
1114 DMA_TO_DEVICE);
1115 tbd->data = WSWAPchar(tx_cmd->dma_addr);
1116
1117 DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
1118 CHECK_WBACK_INV(tx_cmd, sizeof(struct tx_cmd));
1119 CHECK_WBACK_INV(tbd, sizeof(struct i596_tbd));
1120 i596_add_cmd(dev, &tx_cmd->cmd);
1121
1122 lp->stats.tx_packets++;
1123 lp->stats.tx_bytes += length;
1124 }
1125
1126 netif_start_queue(dev);
1127
1128 return 0;
1129}
1130
1131static void print_eth(unsigned char *add, char *str)
1132{
1133 int i;
1134
1135 printk("i596 0x%p, ", add);
1136 for (i = 0; i < 6; i++)
1137 printk(" %02X", add[i + 6]);
1138 printk(" -->");
1139 for (i = 0; i < 6; i++)
1140 printk(" %02X", add[i]);
1141 printk(" %02X%02X, %s\n", add[12], add[13], str);
1142}
1143
1144
1145#define LAN_PROM_ADDR 0xF0810000
1146
1147static int __devinit i82596_probe(struct net_device *dev,
1148 struct device *gen_dev)
1149{
1150 int i;
1151 struct i596_private *lp;
1152 char eth_addr[6];
1153 dma_addr_t dma_addr;
1154
1155 /* This lot is ensure things have been cache line aligned. */
1156 if (sizeof(struct i596_rfd) != 32) {
1157 printk("82596: sizeof(struct i596_rfd) = %d\n",
1158 (int)sizeof(struct i596_rfd));
1159 return -ENODEV;
1160 }
1161 if ((sizeof(struct i596_rbd) % 32) != 0) {
1162 printk("82596: sizeof(struct i596_rbd) = %d\n",
1163 (int)sizeof(struct i596_rbd));
1164 return -ENODEV;
1165 }
1166 if ((sizeof(struct tx_cmd) % 32) != 0) {
1167 printk("82596: sizeof(struct tx_cmd) = %d\n",
1168 (int)sizeof(struct tx_cmd));
1169 return -ENODEV;
1170 }
1171 if (sizeof(struct i596_tbd) != 32) {
1172 printk("82596: sizeof(struct i596_tbd) = %d\n",
1173 (int)sizeof(struct i596_tbd));
1174 return -ENODEV;
1175 }
1176#ifndef __LP64__
1177 if (sizeof(struct i596_private) > 4096) {
1178 printk("82596: sizeof(struct i596_private) = %d\n",
1179 (int)sizeof(struct i596_private));
1180 return -ENODEV;
1181 }
1182#endif
1183
1184 if (!dev->base_addr || !dev->irq)
1185 return -ENODEV;
1186
1187 if (pdc_lan_station_id(eth_addr, dev->base_addr)) {
1188 for (i=0; i < 6; i++) {
1189 eth_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
1190 }
1191 printk(KERN_INFO "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
1192 }
1193
1194 dev->mem_start = (unsigned long) dma_alloc_noncoherent(gen_dev,
1195 sizeof(struct i596_private), &dma_addr, GFP_KERNEL);
1196 if (!dev->mem_start) {
1197 printk(KERN_ERR "%s: Couldn't get shared memory\n", __FILE__);
1198 return -ENOMEM;
1199 }
1200
1201 for (i = 0; i < 6; i++)
1202 dev->dev_addr[i] = eth_addr[i];
1203
1204 /* The 82596-specific entries in the device structure. */
1205 dev->open = i596_open;
1206 dev->stop = i596_close;
1207 dev->hard_start_xmit = i596_start_xmit;
1208 dev->get_stats = i596_get_stats;
1209 dev->set_multicast_list = set_multicast_list;
1210 dev->tx_timeout = i596_tx_timeout;
1211 dev->watchdog_timeo = TX_TIMEOUT;
1212
1213 dev->priv = (void *)(dev->mem_start);
1214
1215 lp = dev->priv;
1216 memset(lp, 0, sizeof(struct i596_private));
1217
1218 lp->scb.command = 0;
1219 lp->scb.cmd = I596_NULL;
1220 lp->scb.rfd = I596_NULL;
1221 spin_lock_init(&lp->lock);
1222 lp->dma_addr = dma_addr;
1223 lp->dev = gen_dev;
1224
1225 CHECK_WBACK_INV(dev->mem_start, sizeof(struct i596_private));
1226
1227 i = register_netdev(dev);
1228 if (i) {
1229 lp = dev->priv;
1230 dma_free_noncoherent(lp->dev, sizeof(struct i596_private),
1231 (void *)dev->mem_start, lp->dma_addr);
1232 return i;
1233 };
1234
1235 DEB(DEB_PROBE, printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));
1236 for (i = 0; i < 6; i++)
1237 DEB(DEB_PROBE, printk(" %2.2X", dev->dev_addr[i]));
1238 DEB(DEB_PROBE, printk(" IRQ %d.\n", dev->irq));
1239 DEB(DEB_INIT, printk(KERN_INFO "%s: lp at 0x%p (%d bytes), lp->scb at 0x%p\n",
1240 dev->name, lp, (int)sizeof(struct i596_private), &lp->scb));
1241
1242 return 0;
1243}
1244
1245
1246static irqreturn_t i596_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1247{
1248 struct net_device *dev = dev_id;
1249 struct i596_private *lp;
1250 unsigned short status, ack_cmd = 0;
1251
1252 if (dev == NULL) {
1253 printk("%s: irq %d for unknown device.\n", __FUNCTION__, irq);
1254 return IRQ_NONE;
1255 }
1256
1257 lp = dev->priv;
1258
1259 spin_lock (&lp->lock);
1260
1261 wait_cmd(dev, lp, 100, "i596 interrupt, timeout");
1262 status = lp->scb.status;
1263
1264 DEB(DEB_INTS, printk("%s: i596 interrupt, IRQ %d, status %4.4x.\n",
1265 dev->name, irq, status));
1266
1267 ack_cmd = status & 0xf000;
1268
1269 if (!ack_cmd) {
1270 DEB(DEB_ERRORS, printk("%s: interrupt with no events\n", dev->name));
1271 spin_unlock (&lp->lock);
1272 return IRQ_NONE;
1273 }
1274
1275 if ((status & 0x8000) || (status & 0x2000)) {
1276 struct i596_cmd *ptr;
1277
1278 if ((status & 0x8000))
1279 DEB(DEB_INTS, printk("%s: i596 interrupt completed command.\n", dev->name));
1280 if ((status & 0x2000))
1281 DEB(DEB_INTS, printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));
1282
1283 while (lp->cmd_head != NULL) {
1284 CHECK_INV(lp->cmd_head, sizeof(struct i596_cmd));
1285 if (!(lp->cmd_head->status & STAT_C))
1286 break;
1287
1288 ptr = lp->cmd_head;
1289
1290 DEB(DEB_STATUS, printk("cmd_head->status = %04x, ->command = %04x\n",
1291 lp->cmd_head->status, lp->cmd_head->command));
1292 lp->cmd_head = ptr->v_next;
1293 lp->cmd_backlog--;
1294
1295 switch ((ptr->command) & 0x7) {
1296 case CmdTx:
1297 {
1298 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
1299 struct sk_buff *skb = tx_cmd->skb;
1300
1301 if ((ptr->status) & STAT_OK) {
1302 DEB(DEB_TXADDR, print_eth(skb->data, "tx-done"));
1303 } else {
1304 lp->stats.tx_errors++;
1305 if ((ptr->status) & 0x0020)
1306 lp->stats.collisions++;
1307 if (!((ptr->status) & 0x0040))
1308 lp->stats.tx_heartbeat_errors++;
1309 if ((ptr->status) & 0x0400)
1310 lp->stats.tx_carrier_errors++;
1311 if ((ptr->status) & 0x0800)
1312 lp->stats.collisions++;
1313 if ((ptr->status) & 0x1000)
1314 lp->stats.tx_aborted_errors++;
1315 }
1316 dma_unmap_single(lp->dev, tx_cmd->dma_addr, skb->len, DMA_TO_DEVICE);
1317 dev_kfree_skb_irq(skb);
1318
1319 tx_cmd->cmd.command = 0; /* Mark free */
1320 break;
1321 }
1322 case CmdTDR:
1323 {
1324 unsigned short status = ((struct tdr_cmd *)ptr)->status;
1325
1326 if (status & 0x8000) {
1327 DEB(DEB_ANY, printk("%s: link ok.\n", dev->name));
1328 } else {
1329 if (status & 0x4000)
1330 printk("%s: Transceiver problem.\n", dev->name);
1331 if (status & 0x2000)
1332 printk("%s: Termination problem.\n", dev->name);
1333 if (status & 0x1000)
1334 printk("%s: Short circuit.\n", dev->name);
1335
1336 DEB(DEB_TDR, printk("%s: Time %d.\n", dev->name, status & 0x07ff));
1337 }
1338 break;
1339 }
1340 case CmdConfigure:
1341 /* Zap command so set_multicast_list() knows it is free */
1342 ptr->command = 0;
1343 break;
1344 }
1345 ptr->v_next = NULL;
1346 ptr->b_next = I596_NULL;
1347 CHECK_WBACK(ptr, sizeof(struct i596_cmd));
1348 lp->last_cmd = jiffies;
1349 }
1350
1351 /* This mess is arranging that only the last of any outstanding
1352 * commands has the interrupt bit set. Should probably really
1353 * only add to the cmd queue when the CU is stopped.
1354 */
1355 ptr = lp->cmd_head;
1356 while ((ptr != NULL) && (ptr != lp->cmd_tail)) {
1357 struct i596_cmd *prev = ptr;
1358
1359 ptr->command &= 0x1fff;
1360 ptr = ptr->v_next;
1361 CHECK_WBACK_INV(prev, sizeof(struct i596_cmd));
1362 }
1363
1364 if ((lp->cmd_head != NULL))
1365 ack_cmd |= CUC_START;
1366 lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status));
1367 CHECK_WBACK_INV(&lp->scb, sizeof(struct i596_scb));
1368 }
1369 if ((status & 0x1000) || (status & 0x4000)) {
1370 if ((status & 0x4000))
1371 DEB(DEB_INTS, printk("%s: i596 interrupt received a frame.\n", dev->name));
1372 i596_rx(dev);
1373 /* Only RX_START if stopped - RGH 07-07-96 */
1374 if (status & 0x1000) {
1375 if (netif_running(dev)) {
1376 DEB(DEB_ERRORS, printk("%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
1377 ack_cmd |= RX_START;
1378 lp->stats.rx_errors++;
1379 lp->stats.rx_fifo_errors++;
1380 rebuild_rx_bufs(dev);
1381 }
1382 }
1383 }
1384 wait_cmd(dev, lp, 100, "i596 interrupt, timeout");
1385 lp->scb.command = ack_cmd;
1386 CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
1387
1388 /* DANGER: I suspect that some kind of interrupt
1389 acknowledgement aside from acking the 82596 might be needed
1390 here... but it's running acceptably without */
1391
1392 CA(dev);
1393
1394 wait_cmd(dev, lp, 100, "i596 interrupt, exit timeout");
1395 DEB(DEB_INTS, printk("%s: exiting interrupt.\n", dev->name));
1396
1397 spin_unlock (&lp->lock);
1398 return IRQ_HANDLED;
1399}
1400
1401static int i596_close(struct net_device *dev)
1402{
1403 struct i596_private *lp = dev->priv;
1404 unsigned long flags;
1405
1406 netif_stop_queue(dev);
1407
1408 DEB(DEB_INIT, printk("%s: Shutting down ethercard, status was %4.4x.\n",
1409 dev->name, lp->scb.status));
1410
1411 spin_lock_irqsave(&lp->lock, flags);
1412
1413 wait_cmd(dev, lp, 100, "close1 timed out");
1414 lp->scb.command = CUC_ABORT | RX_ABORT;
1415 CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
1416
1417 CA(dev);
1418
1419 wait_cmd(dev, lp, 100, "close2 timed out");
1420 spin_unlock_irqrestore(&lp->lock, flags);
1421 DEB(DEB_STRUCT,i596_display_data(dev));
1422 i596_cleanup_cmd(dev,lp);
1423
1424 disable_irq(dev->irq);
1425
1426 free_irq(dev->irq, dev);
1427 remove_rx_bufs(dev);
1428
1429 return 0;
1430}
1431
1432static struct net_device_stats *
1433 i596_get_stats(struct net_device *dev)
1434{
1435 struct i596_private *lp = dev->priv;
1436
1437 return &lp->stats;
1438}
1439
1440/*
1441 * Set or clear the multicast filter for this adaptor.
1442 */
1443
1444static void set_multicast_list(struct net_device *dev)
1445{
1446 struct i596_private *lp = dev->priv;
1447 int config = 0, cnt;
1448
1449 DEB(DEB_MULTI, printk("%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
1450 dev->name, dev->mc_count, dev->flags & IFF_PROMISC ? "ON" : "OFF",
1451 dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));
1452
1453 if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
1454 lp->cf_cmd.i596_config[8] |= 0x01;
1455 config = 1;
1456 }
1457 if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
1458 lp->cf_cmd.i596_config[8] &= ~0x01;
1459 config = 1;
1460 }
1461 if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
1462 lp->cf_cmd.i596_config[11] &= ~0x20;
1463 config = 1;
1464 }
1465 if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
1466 lp->cf_cmd.i596_config[11] |= 0x20;
1467 config = 1;
1468 }
1469 if (config) {
1470 if (lp->cf_cmd.cmd.command)
1471 printk("%s: config change request already queued\n",
1472 dev->name);
1473 else {
1474 lp->cf_cmd.cmd.command = CmdConfigure;
1475 CHECK_WBACK_INV(&lp->cf_cmd, sizeof(struct cf_cmd));
1476 i596_add_cmd(dev, &lp->cf_cmd.cmd);
1477 }
1478 }
1479
1480 cnt = dev->mc_count;
1481 if (cnt > MAX_MC_CNT)
1482 {
1483 cnt = MAX_MC_CNT;
1484 printk("%s: Only %d multicast addresses supported",
1485 dev->name, cnt);
1486 }
1487
1488 if (dev->mc_count > 0) {
1489 struct dev_mc_list *dmi;
1490 unsigned char *cp;
1491 struct mc_cmd *cmd;
1492
1493 cmd = &lp->mc_cmd;
1494 cmd->cmd.command = CmdMulticastList;
1495 cmd->mc_cnt = dev->mc_count * 6;
1496 cp = cmd->mc_addrs;
1497 for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {
1498 memcpy(cp, dmi->dmi_addr, 6);
1499 if (i596_debug > 1)
1500 DEB(DEB_MULTI, printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
1501 dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));
1502 }
1503 CHECK_WBACK_INV(&lp->mc_cmd, sizeof(struct mc_cmd));
1504 i596_add_cmd(dev, &cmd->cmd);
1505 }
1506}
1507
1508MODULE_PARM(debug, "i");
1509MODULE_PARM_DESC(debug, "lasi_82596 debug mask");
1510static int debug = -1;
1511
1512static int num_drivers;
1513static struct net_device *netdevs[MAX_DRIVERS];
1514
1515static int __devinit
1516lan_init_chip(struct parisc_device *dev)
1517{
1518 struct net_device *netdevice;
1519 int retval;
1520
1521 if (num_drivers >= MAX_DRIVERS) {
1522 /* max count of possible i82596 drivers reached */
1523 return -ENOMEM;
1524 }
1525
1526 if (num_drivers == 0)
1527 printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
1528
1529 if (!dev->irq) {
1530 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
1531 __FILE__, dev->hpa);
1532 return -ENODEV;
1533 }
1534
1535 printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", dev->hpa, dev->irq);
1536
1537 netdevice = alloc_etherdev(0);
1538 if (!netdevice)
1539 return -ENOMEM;
1540
1541 netdevice->base_addr = dev->hpa;
1542 netdevice->irq = dev->irq;
1543
1544 retval = i82596_probe(netdevice, &dev->dev);
1545 if (retval) {
1546 free_netdev(netdevice);
1547 return -ENODEV;
1548 }
1549
1550 if (dev->id.sversion == 0x72) {
1551 ((struct i596_private *)netdevice->priv)->options = OPT_SWAP_PORT;
1552 }
1553
1554 netdevs[num_drivers++] = netdevice;
1555
1556 return retval;
1557}
1558
1559
1560static struct parisc_device_id lan_tbl[] = {
1561 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
1562 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
1563 { 0, }
1564};
1565
1566MODULE_DEVICE_TABLE(parisc, lan_tbl);
1567
1568static struct parisc_driver lan_driver = {
1569 .name = "Apricot",
1570 .id_table = lan_tbl,
1571 .probe = lan_init_chip,
1572};
1573
1574static int __devinit lasi_82596_init(void)
1575{
1576 if (debug >= 0)
1577 i596_debug = debug;
1578 return register_parisc_driver(&lan_driver);
1579}
1580
1581module_init(lasi_82596_init);
1582
1583static void __exit lasi_82596_exit(void)
1584{
1585 int i;
1586
1587 for (i=0; i<MAX_DRIVERS; i++) {
1588 struct i596_private *lp;
1589 struct net_device *netdevice;
1590
1591 netdevice = netdevs[i];
1592 if (!netdevice)
1593 continue;
1594
1595 unregister_netdev(netdevice);
1596
1597 lp = netdevice->priv;
1598 dma_free_noncoherent(lp->dev, sizeof(struct i596_private),
1599 (void *)netdevice->mem_start, lp->dma_addr);
1600 free_netdev(netdevice);
1601 }
1602 num_drivers = 0;
1603
1604 unregister_parisc_driver(&lan_driver);
1605}
1606
1607module_exit(lasi_82596_exit);