43 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/string.h>
46 #include <linux/errno.h>
50 #include <linux/netdevice.h>
54 #include <linux/bitops.h>
59 #include <asm/pgtable.h>
60 #include <asm/cacheflush.h>
63 "82596.c $Revision: 1.5 $\n";
65 #define DRV_NAME "82596"
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
89 #define DEB(x,y) if (i596_debug & (x)) y
92 #if defined(CONFIG_MVME16x_NET) || defined(CONFIG_MVME16x_NET_MODULE)
93 #define ENABLE_MVME16x_NET
95 #if defined(CONFIG_BVME6000_NET) || defined(CONFIG_BVME6000_NET_MODULE)
96 #define ENABLE_BVME6000_NET
98 #if defined(CONFIG_APRICOT) || defined(CONFIG_APRICOT_MODULE)
99 #define ENABLE_APRICOT
102 #ifdef ENABLE_MVME16x_NET
105 #ifdef ENABLE_BVME6000_NET
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
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
142 #define PORT_RESET 0x00
143 #define PORT_SELFTEST 0x01
144 #define PORT_ALTSCP 0x02
145 #define PORT_ALTDUMP 0x03
160 static int rx_copybreak = 100;
162 #define PKT_BUF_SZ 1536
163 #define MAX_MC_CNT 64
165 #define I596_TOTAL_SIZE 17
167 #define I596_NULL ((void *)0xffffffff)
169 #define CMD_EOL 0x8000
170 #define CMD_SUSP 0x4000
171 #define CMD_INTR 0x2000
173 #define CMD_FLEX 0x0008
180 #define STAT_C 0x8000
181 #define STAT_B 0x4000
182 #define STAT_OK 0x2000
183 #define STAT_A 0x1000
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
194 #define TX_TIMEOUT (HZ/20)
204 #define SIZE_MASK 0x3fff
284 #define TX_RING_SIZE 64
285 #define RX_RING_SIZE 16
337 static char init_setup[] =
364 static void print_eth(
unsigned char *
buf,
char *
str);
368 static int ticks_limit = 25;
374 #ifdef ENABLE_MVME16x_NET
379 #ifdef ENABLE_BVME6000_NET
386 #ifdef ENABLE_APRICOT
394 static inline void MPU_PORT(
struct net_device *dev,
int c,
volatile void *
x)
396 #ifdef ENABLE_MVME16x_NET
403 #ifdef ENABLE_BVME6000_NET
406 v = ((
u32) (v) << 16) | ((
u32) (
v) >> 16);
417 while (--delcnt && lp->
iscp.stat)
421 dev->
name, str, lp->
scb.status, lp->
scb.command);
431 while (--delcnt && lp->
scb.command)
435 dev->
name, str, lp->
scb.status, lp->
scb.command);
458 static void i596_display_data(
struct net_device *dev)
465 printk(
KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
470 " .cmd = %p, .rfd = %p\n",
471 &lp->
scb, lp->
scb.status, lp->
scb.command,
472 lp->
scb.cmd, lp->
scb.rfd);
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);
479 printk(
KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
495 printk(
KERN_ERR " %p .count %04x, b_next %p, b_data %p, size %04x\n",
502 #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
506 #ifdef ENABLE_MVME16x_NET
508 volatile unsigned char *pcc2 = (
unsigned char *) 0xfff42000;
514 #ifdef ENABLE_BVME6000_NET
523 i596_display_data(dev);
528 static inline void remove_rx_bufs(
struct net_device *dev)
534 for (i = 0, rbd = lp->
rbds; i < rx_ring_size; i++, rbd++) {
537 dev_kfree_skb(rbd->
skb);
542 static inline int init_rx_bufs(
struct net_device *dev)
551 for (i = 0, rbd = lp->
rbds; i < rx_ring_size; i++, rbd++) {
571 rbd = lp->
rbds + rx_ring_size - 1;
577 for (i = 0, rfd = lp->
rfds; i < rx_ring_size; i++, rfd++) {
589 rfd = lp->
rfds + rx_ring_size - 1;
598 static void rebuild_rx_bufs(
struct net_device *dev)
605 for (i = 0; i < rx_ring_size; i++) {
617 static int init_i596_mem(
struct net_device *dev)
620 #if !defined(ENABLE_MVME16x_NET) && !defined(ENABLE_BVME6000_NET) || defined(ENABLE_APRICOT)
629 #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
630 #ifdef ENABLE_MVME16x_NET
632 volatile unsigned char *pcc2 = (
unsigned char *) 0xfff42000;
644 #ifdef ENABLE_BVME6000_NET
656 #elif defined(ENABLE_APRICOT)
664 outb(4, ioaddr + 0xf);
665 outw(scp | 2, ioaddr);
666 outw(scp >> 16, ioaddr);
672 #ifdef ENABLE_MVME16x_NET
674 lp->
scp.sysbus = 0x00000054;
676 #ifdef ENABLE_BVME6000_NET
678 lp->
scp.sysbus = 0x0000004c;
680 #ifdef ENABLE_APRICOT
682 lp->
scp.sysbus = 0x00440000;
692 #ifdef ENABLE_BVME6000_NET
694 lp->
scb.t_on = 7 * 25;
695 lp->
scb.t_off = 1 * 25;
701 #if defined(ENABLE_APRICOT)
703 outb(4, ioaddr + 0xf);
707 if (wait_istat(dev,lp,1000,
"initialization timed out"))
712 rebuild_rx_bufs(dev);
715 #ifdef ENABLE_MVME16x_NET
717 volatile unsigned char *pcc2 = (
unsigned char *) 0xfff42000;
724 #ifdef ENABLE_BVME6000_NET
736 i596_add_cmd(dev, &lp->
cf_cmd.cmd);
741 i596_add_cmd(dev, &lp->
sa_cmd.cmd);
745 i596_add_cmd(dev, &lp->
tdr_cmd.cmd);
749 if (wait_cmd(dev,lp,1000,
"timed out waiting to issue RX_START")) {
750 spin_unlock_irqrestore (&lp->
lock, flags);
757 spin_unlock_irqrestore (&lp->
lock, flags);
759 if (wait_cmd(dev,lp,1000,
"RX_START not processed"))
770 static inline int i596_rx(
struct net_device *dev)
808 if (pkt_len > rx_copybreak) {
813 if (newskb ==
NULL) {
828 skb = netdev_alloc_skb(dev, pkt_len + 2);
833 dev->
stats.rx_dropped++;
848 dev->
stats.rx_packets++;
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++;
912 switch ((ptr->
command) & 0x7) {
920 dev->
stats.tx_errors++;
921 dev->
stats.tx_aborted_errors++;
924 tx_cmd->
cmd.command = 0;
932 wait_cmd(dev,lp,100,
"i596_cleanup_cmd timed out");
945 wait_cmd(dev,lp,100,
"i596_reset timed out");
947 netif_stop_queue(dev);
953 wait_cmd(dev,lp,1000,
"i596_reset 2 timed out");
954 spin_unlock_irqrestore (&lp->
lock, flags);
956 i596_cleanup_cmd(dev,lp);
959 netif_start_queue(dev);
982 wait_cmd(dev,lp,100,
"i596_add_cmd timed out");
990 spin_unlock_irqrestore (&lp->
lock, flags);
995 if (tickssofar < ticks_limit)
1000 i596_reset(dev, lp, ioaddr);
1014 #ifdef ENABLE_MVME16x_NET
1016 if (
request_irq(0x56, i596_error, 0,
"i82596_error", dev)) {
1022 res = init_rx_bufs(dev);
1026 netif_start_queue(dev);
1028 if (init_i596_mem(dev)) {
1036 netif_stop_queue(dev);
1037 remove_rx_bufs(dev);
1039 #ifdef ENABLE_MVME16x_NET
1048 static void i596_tx_timeout (
struct net_device *dev)
1057 dev->
stats.tx_errors++;
1063 i596_reset (dev, lp, ioaddr);
1073 netif_wake_queue (dev);
1091 netif_stop_queue(dev);
1096 if (tx_cmd->
cmd.command) {
1099 dev->
stats.tx_dropped++;
1122 i596_add_cmd(dev, &tx_cmd->
cmd);
1124 dev->
stats.tx_packets++;
1128 netif_start_queue(dev);
1133 static void print_eth(
unsigned char *
add,
char *str)
1136 add, add + 6, add, add[12], add[13], str);
1139 static int io = 0x300;
1140 static int irq = 10;
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,
1166 dev = alloc_etherdev(0);
1178 #ifdef ENABLE_MVME16x_NET
1185 memcpy(eth_addr, (
void *) 0xfffc1f2c, 6);
1191 #ifdef ENABLE_BVME6000_NET
1194 unsigned char msr = rtc[3];
1198 for (i = 0; i < 6; i++)
1199 eth_addr[i] = rtc[i * 4 + 7];
1206 #ifdef ENABLE_APRICOT
1222 for (i = 0; i < 8; i++) {
1223 eth_addr[
i] =
inb(ioaddr + 8 + i);
1224 checksum += eth_addr[
i];
1233 if ((checksum % 0x100) ||
1234 (
memcmp(eth_addr,
"\x00\x00\x49", 3) != 0)) {
1255 for (i = 0; i < 6; i++)
1270 "lp->scb at 0x%08lx\n",
1271 dev->
name, (
unsigned long)lp,
1280 lp->scb.command = 0;
1295 IOMAP_FULL_CACHING);
1299 #ifdef ENABLE_APRICOT
1304 return ERR_PTR(err);
1307 static irqreturn_t i596_interrupt(
int irq,
void *dev_id)
1312 unsigned short status, ack_cmd = 0;
1315 #ifdef ENABLE_BVME6000_NET
1318 i596_error(irq, dev_id);
1324 printk(
KERN_ERR "i596_interrupt(): irq %d for unknown device.\n", irq);
1331 spin_lock (&lp->
lock);
1333 wait_cmd(dev,lp,100,
"i596 interrupt, timeout");
1334 status = lp->
scb.status;
1337 dev->
name, irq, status));
1339 ack_cmd = status & 0xf000;
1341 if ((status & 0x8000) || (status & 0x2000)) {
1345 if ((status & 0x8000))
1347 if ((status & 0x2000))
1358 switch ((ptr->
command) & 0x7) {
1361 struct tx_cmd *tx_cmd = (
struct tx_cmd *) ptr;
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++;
1382 tx_cmd->
cmd.command = 0;
1387 unsigned short status = ((
struct tdr_cmd *)ptr)->status;
1389 if (status & 0x8000) {
1392 if (status & 0x4000)
1394 if (status & 0x2000)
1396 if (status & 0x1000)
1423 if ((status & 0x1000) || (status & 0x4000)) {
1424 if ((status & 0x4000))
1428 if (status & 0x1000) {
1429 if (netif_running(dev)) {
1432 dev->
stats.rx_errors++;
1433 dev->
stats.rx_fifo_errors++;
1434 rebuild_rx_bufs(dev);
1438 wait_cmd(dev,lp,100,
"i596 interrupt, timeout");
1439 lp->
scb.command = ack_cmd;
1441 #ifdef ENABLE_MVME16x_NET
1445 volatile unsigned char *pcc2 = (
unsigned char *) 0xfff42000;
1450 #ifdef ENABLE_BVME6000_NET
1458 #ifdef ENABLE_APRICOT
1460 outb(4, ioaddr + 0xf);
1466 spin_unlock (&lp->
lock);
1470 static int i596_close(
struct net_device *dev)
1473 unsigned long flags;
1475 netif_stop_queue(dev);
1482 wait_cmd(dev,lp,100,
"close1 timed out");
1486 wait_cmd(dev,lp,100,
"close2 timed out");
1488 spin_unlock_irqrestore(&lp->
lock, flags);
1490 i596_cleanup_cmd(dev,lp);
1492 #ifdef ENABLE_MVME16x_NET
1494 volatile unsigned char *pcc2 = (
unsigned char *) 0xfff42000;
1502 #ifdef ENABLE_BVME6000_NET
1510 #ifdef ENABLE_MVME16x_NET
1514 remove_rx_bufs(dev);
1523 static void set_multicast_list(
struct net_device *dev)
1533 if (wait_cfg(dev, &lp->
cf_cmd.cmd, 1000,
"config change request timed out"))
1537 lp->
cf_cmd.i596_config[8] |= 0x01;
1541 lp->
cf_cmd.i596_config[8] &= ~0x01;
1545 lp->
cf_cmd.i596_config[11] &= ~0x20;
1549 lp->
cf_cmd.i596_config[11] |= 0x20;
1554 i596_add_cmd(dev, &lp->
cf_cmd.cmd);
1570 if (wait_cfg(dev, &lp->
mc_cmd.cmd, 1000,
"multicast list change request timed out"))
1585 i596_add_cmd(dev, &cmd->
cmd);
1592 #ifdef ENABLE_APRICOT
1597 static int debug = -1;
1606 if (IS_ERR(dev_82596))
1607 return PTR_ERR(dev_82596);
1620 IOMAP_FULL_CACHING);
1623 #ifdef ENABLE_APRICOT