71 #include <linux/module.h>
72 #include <linux/kernel.h>
73 #include <linux/string.h>
74 #include <linux/errno.h>
78 #include <linux/netdevice.h>
82 #include <linux/types.h>
83 #include <linux/bitops.h>
92 #define DEB_INIT 0x0001
93 #define DEB_PROBE 0x0002
94 #define DEB_SERIOUS 0x0004
95 #define DEB_ERRORS 0x0008
96 #define DEB_MULTI 0x0010
97 #define DEB_TDR 0x0020
98 #define DEB_OPEN 0x0040
99 #define DEB_RESET 0x0080
100 #define DEB_ADDCMD 0x0100
101 #define DEB_STATUS 0x0200
102 #define DEB_STARTTX 0x0400
103 #define DEB_RXADDR 0x0800
104 #define DEB_TXADDR 0x1000
105 #define DEB_RXFRAME 0x2000
106 #define DEB_INTS 0x4000
107 #define DEB_STRUCT 0x8000
108 #define DEB_ANY 0xffff
111 #define DEB(x, y) if (i596_debug & (x)) { y; }
120 #define PORT_RESET 0x00
121 #define PORT_SELFTEST 0x01
122 #define PORT_ALTSCP 0x02
123 #define PORT_ALTDUMP 0x03
130 static int rx_copybreak = 100;
132 #define PKT_BUF_SZ 1536
133 #define MAX_MC_CNT 64
135 #define ISCP_BUSY 0x0001
137 #define I596_NULL ((u32)0xffffffff)
139 #define CMD_EOL 0x8000
140 #define CMD_SUSP 0x4000
141 #define CMD_INTR 0x2000
143 #define CMD_FLEX 0x0008
150 #define STAT_C 0x8000
151 #define STAT_B 0x4000
152 #define STAT_OK 0x2000
153 #define STAT_A 0x1000
155 #define CUC_START 0x0100
156 #define CUC_RESUME 0x0200
157 #define CUC_SUSPEND 0x0300
158 #define CUC_ABORT 0x0400
159 #define RX_START 0x0010
160 #define RX_RESUME 0x0020
161 #define RX_SUSPEND 0x0030
162 #define RX_ABORT 0x0040
164 #define TX_TIMEOUT (HZ/20)
174 #define SIZE_MASK 0x3fff
242 unsigned short count;
253 unsigned short count;
254 unsigned short zero1;
258 unsigned short zero2;
272 #define TX_RING_SIZE 32
273 #define RX_RING_SIZE 16
287 unsigned short t_off;
302 struct i596_scp scp __attribute__((aligned(32)));
303 volatile struct i596_iscp iscp __attribute__((aligned(32)));
304 volatile struct i596_scb scb __attribute__((aligned(32)));
305 struct sa_cmd sa_cmd __attribute__((aligned(32)));
306 struct cf_cmd cf_cmd __attribute__((aligned(32)));
307 struct tdr_cmd tdr_cmd __attribute__((aligned(32)));
308 struct mc_cmd mc_cmd __attribute__((aligned(32)));
309 struct i596_rfd rfds[RX_RING_SIZE] __attribute__((aligned(32)));
310 struct i596_rbd rbds[RX_RING_SIZE] __attribute__((aligned(32)));
311 struct tx_cmd tx_cmds[TX_RING_SIZE] __attribute__((aligned(32)));
312 struct i596_tbd tbds[TX_RING_SIZE] __attribute__((aligned(32)));
333 static const char init_setup[] =
356 static void print_eth(
unsigned char *
buf,
char *
str);
362 static int ticks_limit = 100;
365 #ifdef CONFIG_NET_POLL_CONTROLLER
373 while (--delcnt && dma->iscp.stat) {
386 static inline int wait_cmd(
struct net_device *dev,
struct i596_dma *dma,
int delcnt,
char *str)
389 while (--delcnt && dma->scb.command) {
397 SWAP16(dma->scb.command));
404 static void i596_display_data(
struct net_device *dev)
413 &dma->scp, dma->scp.sysbus,
SWAP32(dma->scp.iscp));
415 &dma->iscp,
SWAP32(dma->iscp.stat),
SWAP32(dma->iscp.scb));
417 " .cmd = %08x, .rfd = %08x\n",
418 &dma->scb,
SWAP16(dma->scb.status),
SWAP16(dma->scb.command),
421 " over %x, rcvdt %x, short %x\n",
423 SWAP32(dma->scb.resource_err),
SWAP32(dma->scb.over_err),
424 SWAP32(dma->scb.rcvdt_err),
SWAP32(dma->scb.short_err));
426 while (cmd !=
NULL) {
428 "cmd at %p, .status = %04x, .command = %04x,"
438 " %p .stat %04x, .cmd %04x, b_next %08x, rbd %08x,"
449 " %p .count %04x, b_next %08x, b_data %08x,"
459 #define virt_to_dma(lp, v) ((lp)->dma_addr + (dma_addr_t)((unsigned long)(v)-(unsigned long)((lp)->dma)))
461 static inline int init_rx_bufs(
struct net_device *dev)
471 for (i = 0, rbd = dma->rbds; i < rx_ring_size; i++, rbd++) {
475 skb = netdev_alloc_skb_ip_align(dev,
PKT_BUF_SZ);
489 rbd = dma->rbds + rx_ring_size - 1;
495 for (i = 0, rfd = dma->rfds; i < rx_ring_size; i++, rfd++) {
506 rfd->
v_prev = dma->rfds + rx_ring_size - 1;
507 rfd = dma->rfds + rx_ring_size - 1;
516 static inline void remove_rx_bufs(
struct net_device *dev)
522 for (i = 0, rbd = lp->
dma->rbds; i < rx_ring_size; i++, rbd++) {
528 dev_kfree_skb(rbd->
skb);
533 static void rebuild_rx_bufs(
struct net_device *dev)
541 for (i = 0; i < rx_ring_size; i++) {
555 static int init_i596_mem(
struct net_device *dev)
585 if (wait_istat(dev, dma, 1000,
"initialization timed out"))
588 "%s: i82596 initialization successful\n",
597 rebuild_rx_bufs(dev);
599 dma->scb.command = 0;
603 "%s: queuing CmdConfigure\n", dev->
name));
604 memcpy(dma->cf_cmd.i596_config, init_setup, 14);
607 i596_add_cmd(dev, &dma->cf_cmd.cmd);
613 i596_add_cmd(dev, &dma->sa_cmd.cmd);
618 i596_add_cmd(dev, &dma->tdr_cmd.cmd);
622 if (wait_cmd(dev, dma, 1000,
"timed out waiting to issue RX_START")) {
623 spin_unlock_irqrestore (&lp->
lock, flags);
624 goto failed_free_irq;
633 spin_unlock_irqrestore (&lp->
lock, flags);
634 if (wait_cmd(dev, dma, 1000,
"RX_START not processed"))
635 goto failed_free_irq;
637 "%s: Receive unit started OK\n", dev->
name));
649 static inline int i596_rx(
struct net_device *dev)
657 "i596_rx(), rfd_head %p, rbd_head %p\n",
676 " rfd %p, rfd.rbd %08x, rfd.stat %04x\n",
692 if (pkt_len > rx_copybreak) {
700 newskb = netdev_alloc_skb_ip_align(dev,
702 if (newskb ==
NULL) {
719 skb = netdev_alloc_skb_ip_align(dev, pkt_len);
724 "%s: i596_rx Memory squeeze, dropping packet.\n",
726 dev->
stats.rx_dropped++;
741 dev->
stats.rx_packets++;
746 "%s: Error, rfd.stat = 0x%04x\n",
748 dev->
stats.rx_errors++;
750 dev->
stats.collisions++;
752 dev->
stats.rx_length_errors++;
754 dev->
stats.rx_over_errors++;
756 dev->
stats.rx_fifo_errors++;
758 dev->
stats.rx_frame_errors++;
760 dev->
stats.rx_crc_errors++;
762 dev->
stats.rx_length_errors++;
820 dev->
stats.tx_errors++;
821 dev->
stats.tx_aborted_errors++;
825 tx_cmd->
cmd.command = 0;
835 wait_cmd(dev, lp->
dma, 100,
"i596_cleanup_cmd timed out");
849 wait_cmd(dev, lp->
dma, 100,
"i596_reset timed out");
851 netif_stop_queue(dev);
859 wait_cmd(dev, lp->
dma, 1000,
"i596_reset 2 timed out");
860 spin_unlock_irqrestore (&lp->
lock, flags);
862 i596_cleanup_cmd(dev, lp);
865 netif_start_queue(dev);
893 wait_cmd(dev, dma, 100,
"i596_add_cmd timed out");
902 spin_unlock_irqrestore (&lp->
lock, flags);
907 if (tickssofar < ticks_limit)
911 "%s: command unit timed out, status resetting.\n",
922 "%s: i596_open() irq %d.\n", dev->
name, dev->
irq));
924 if (init_rx_bufs(dev)) {
928 if (init_i596_mem(dev)) {
930 goto out_remove_rx_bufs;
932 netif_start_queue(dev);
941 static void i596_tx_timeout (
struct net_device *dev)
947 "%s: transmit timed out, status resetting.\n",
950 dev->
stats.tx_errors++;
956 i596_reset (dev, lp);
967 netif_wake_queue (dev);
979 "%s: i596_start_xmit(%x,%p) called\n",
988 netif_stop_queue(dev);
993 if (tx_cmd->
cmd.command) {
995 "%s: xmit ring full, dropping packet.\n",
997 dev->
stats.tx_dropped++;
1021 i596_add_cmd(dev, &tx_cmd->
cmd);
1023 dev->
stats.tx_packets++;
1027 netif_start_queue(dev);
1032 static void print_eth(
unsigned char *
add,
char *str)
1035 add, add + 6, add, add[12], add[13], str);
1038 .ndo_open = i596_open,
1039 .ndo_stop = i596_close,
1040 .ndo_start_xmit = i596_start_xmit,
1041 .ndo_set_rx_mode = set_multicast_list,
1042 .ndo_tx_timeout = i596_tx_timeout,
1046 #ifdef CONFIG_NET_POLL_CONTROLLER
1047 .ndo_poll_controller = i596_poll_controller,
1082 dma->scb.command = 0;
1100 "%s: dma at 0x%p (%d bytes), lp->scb at 0x%p\n",
1107 #ifdef CONFIG_NET_POLL_CONTROLLER
1108 static void i596_poll_controller(
struct net_device *dev)
1111 i596_interrupt(dev->
irq, dev);
1121 unsigned short status, ack_cmd = 0;
1123 lp = netdev_priv(dev);
1126 spin_lock (&lp->
lock);
1128 wait_cmd(dev, dma, 100,
"i596 interrupt, timeout");
1129 status =
SWAP16(dma->scb.status);
1132 "%s: i596 interrupt, IRQ %d, status %4.4x.\n",
1133 dev->
name, dev->
irq, status));
1135 ack_cmd = status & 0xf000;
1139 "%s: interrupt with no events\n",
1141 spin_unlock (&lp->
lock);
1145 if ((status & 0x8000) || (status & 0x2000)) {
1148 if ((status & 0x8000))
1151 "%s: i596 interrupt completed command.\n",
1153 if ((status & 0x2000))
1156 "%s: i596 interrupt command unit inactive %x.\n",
1157 dev->
name, status & 0x0700));
1168 "cmd_head->status = %04x, ->command = %04x\n",
1177 struct tx_cmd *tx_cmd = (
struct tx_cmd *) ptr;
1182 print_eth(skb->
data,
"tx-done"));
1184 dev->
stats.tx_errors++;
1186 dev->
stats.collisions++;
1188 dev->
stats.tx_heartbeat_errors++;
1190 dev->
stats.tx_carrier_errors++;
1192 dev->
stats.collisions++;
1194 dev->
stats.tx_aborted_errors++;
1201 tx_cmd->
cmd.command = 0;
1206 unsigned short status =
SWAP16(((
struct tdr_cmd *)ptr)->status);
1208 if (status & 0x8000) {
1213 if (status & 0x4000)
1215 "%s: Transceiver problem.\n",
1217 if (status & 0x2000)
1219 "%s: Termination problem.\n",
1221 if (status & 0x1000)
1223 "%s: Short circuit.\n",
1228 dev->
name, status & 0x07ff));
1264 if ((status & 0x1000) || (status & 0x4000)) {
1265 if ((status & 0x4000))
1268 "%s: i596 interrupt received a frame.\n",
1272 if (status & 0x1000) {
1273 if (netif_running(dev)) {
1276 "%s: i596 interrupt receive unit inactive, status 0x%x\n",
1277 dev->
name, status));
1279 dev->
stats.rx_errors++;
1280 dev->
stats.rx_fifo_errors++;
1281 rebuild_rx_bufs(dev);
1285 wait_cmd(dev, dma, 100,
"i596 interrupt, timeout");
1286 dma->scb.command =
SWAP16(ack_cmd);
1295 wait_cmd(dev, dma, 100,
"i596 interrupt, exit timeout");
1298 spin_unlock (&lp->
lock);
1302 static int i596_close(
struct net_device *dev)
1305 unsigned long flags;
1307 netif_stop_queue(dev);
1311 "%s: Shutting down ethercard, status was %4.4x.\n",
1316 wait_cmd(dev, lp->
dma, 100,
"close1 timed out");
1322 wait_cmd(dev, lp->
dma, 100,
"close2 timed out");
1323 spin_unlock_irqrestore(&lp->
lock, flags);
1325 i596_cleanup_cmd(dev, lp);
1328 remove_rx_bufs(dev);
1337 static void set_multicast_list(
struct net_device *dev)
1345 "%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
1351 !(dma->cf_cmd.i596_config[8] & 0x01)) {
1352 dma->cf_cmd.i596_config[8] |= 0x01;
1356 (dma->cf_cmd.i596_config[8] & 0x01)) {
1357 dma->cf_cmd.i596_config[8] &= ~0x01;
1361 (dma->cf_cmd.i596_config[11] & 0x20)) {
1362 dma->cf_cmd.i596_config[11] &= ~0x20;
1366 !(dma->cf_cmd.i596_config[11] & 0x20)) {
1367 dma->cf_cmd.i596_config[11] |= 0x20;
1371 if (dma->cf_cmd.cmd.command)
1373 "%s: config change request already queued\n",
1378 i596_add_cmd(dev, &dma->cf_cmd.cmd);
1405 "%s: Adding address %pM\n",
1410 i596_add_cmd(dev, &cmd->
cmd);