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