59 #include <linux/module.h>
62 #include <linux/kernel.h>
63 #include <linux/string.h>
64 #include <linux/errno.h>
66 #include <linux/slab.h>
68 #include <linux/netdevice.h>
71 #include <linux/bitops.h>
76 #define DRV_NAME "lp486e"
79 #define LOG_SRCDST 0x80000000
80 #define LOG_STATINT 0x40000000
81 #define LOG_STARTINT 0x20000000
83 #define i596_debug debug
89 "10baseT-FD",
"AUI-FD",
92 #define LP486E_TOTAL_SIZE 16
94 #define I596_NULL (0xffffffff)
96 #define CMD_EOL 0x8000
97 #define CMD_SUSP 0x4000
98 #define CMD_INTR 0x2000
100 #define CMD_FLEX 0x0008
114 static const char *CUcmdnames[8] = {
"NOP",
"IASetup",
"Configure",
"MulticastList",
115 "Tx",
"TDR",
"Dump",
"Diagnose" };
119 #define STAT_CX 0x8000
121 #define STAT_FR 0x4000
122 #define STAT_CNA 0x2000
123 #define STAT_RNR 0x1000
124 #define STAT_ACK (STAT_CX | STAT_FR | STAT_CNA | STAT_RNR)
125 #define STAT_CUS 0x0700
127 #define STAT_RUS 0x00f0
131 #define STAT_T 0x0008
132 #define STAT_ZERO 0x0807
135 static char *CUstates[8] = {
136 "idle",
"suspended",
"active", 0, 0, 0, 0, 0
138 static char *RUstates[16] = {
139 "idle",
"suspended",
"no resources", 0,
"ready", 0, 0, 0,
140 0, 0,
"no RBDs", 0,
"out of RBDs", 0, 0, 0
144 i596_out_status(
int status) {
148 printk(
"status %4.4x:", status);
149 if (status == 0xffff)
164 s = CUstates[(status &
STAT_CUS) >> 8];
169 s = RUstates[(status &
STAT_RUS) >> 4];
182 #define ACK_CX 0x8000
183 #define ACK_FR 0x4000
184 #define ACK_CNA 0x2000
185 #define ACK_RNR 0x1000
187 #define CUC_START 0x0100
188 #define CUC_RESUME 0x0200
189 #define CUC_SUSPEND 0x0300
190 #define CUC_ABORT 0x0400
192 #define RX_START 0x0010
193 #define RX_RESUME 0x0020
194 #define RX_SUSPEND 0x0030
195 #define RX_ABORT 0x0040
199 static inline phys_addr
205 pa_to_va(phys_addr
x) {
210 #define CMD_STAT_C 0x8000
211 #define CMD_STAT_B 0x4000
212 #define CMD_STAT_OK 0x2000
213 #define CMD_STAT_A 0x1000
222 #define SIZE_MASK 0x3fff
240 #define RFD_STAT_C 0x8000
241 #define RFD_STAT_B 0x4000
242 #define RFD_STAT_OK 0x2000
243 #define RFD_STATUS 0x1fff
244 #define RFD_LENGTH_ERR 0x1000
245 #define RFD_CRC_ERR 0x0800
246 #define RFD_ALIGN_ERR 0x0400
247 #define RFD_NOBUFS_ERR 0x0200
248 #define RFD_DMA_ERR 0x0100
249 #define RFD_SHORT_FRAME_ERR 0x0080
250 #define RFD_NOEOP_ERR 0x0040
251 #define RFD_TRUNC_ERR 0x0020
252 #define RFD_MULTICAST 0x0002
254 #define RFD_COLLISION 0x0001
267 #define RBD_EL 0x8000
269 #define RBD_SIZEMASK 0x3fff
270 #define RBD_EOF 0x8000
285 #define RX_RING_SIZE 64
286 #define RX_SKBSIZE (ETH_FRAME_LEN+10)
287 #define RX_RBD_SIZE 32
356 static char init_setup[14] = {
384 static void print_eth(
char *);
393 lp = netdev_priv(dev);
394 while (lp->
scb.command) {
395 if (--boguscnt == 0) {
396 printk(
"%s: %s timed out - stat %4.4x, cmd %4.4x\n",
398 lp->
scb.status, lp->
scb.command);
408 init_rx_bufs(
struct net_device *dev,
int num) {
414 lp = netdev_priv(dev);
417 for (i = 0; i < num; i++) {
433 lp->
scb.pa_rfd = va_to_pa(rfd);
445 printk(
"dev_alloc_skb failed");
469 lp = netdev_priv(dev);
473 rfd = pa_to_va(lp->
scb.pa_rfd);
486 #define PORT_RESET 0x00
487 #define PORT_SELFTEST 0x01
488 #define PORT_ALTSCP 0x02
489 #define PORT_DUMP 0x03
496 PORT(phys_addr
a,
unsigned int cmd) {
498 printk(
"lp486e.c: PORT: address not aligned\n");
517 i596_port_do(
struct net_device *dev,
int portcmd,
char *cmdname) {
523 outp = &(lp->
dump.dump[0]);
525 PORT(va_to_pa(outp), portcmd);
528 printk(
"lp486e i82596 %s result:\n", cmdname);
531 for (i = 0; i <
m; i++) {
557 lp->
scp.sysbus = 0x00440000;
559 lp->
scp.pa_iscp = va_to_pa(&(lp->
iscp));
564 lp->
iscp.busy = 0x0001;
565 lp->
iscp.pa_scb = va_to_pa(&(lp->
scb));
601 while (lp->
iscp.busy) {
602 if (--boguscnt == 0) {
604 printk(
"%s: i82596 initialization timed out\n",
620 if (i596_scp_setup(dev))
623 lp = netdev_priv(dev);
628 i596_add_cmd(dev, (
void *)&lp->
set_conf);
632 i596_add_cmd(dev, &lp->
set_add);
635 i596_add_cmd(dev, &lp->
tdr);
637 if (lp->
scb.command && i596_timeout(dev,
"i82596 init", 200))
645 if (lp->
scb.command && i596_timeout(dev,
"Receive Unit start", 100))
654 struct i596_rfd *rfd,
int *frames) {
659 struct sk_buff *
skb = netdev_alloc_skb(dev, pkt_len);
664 printk(
"Received on EOL\n");
667 printk (
"%s: i596_rx Memory squeeze, "
668 "dropping packet.\n", dev->
name);
669 dev->
stats.rx_dropped++;
677 dev->
stats.rx_packets++;
680 printk(
"Frame reception error status %04x\n",
683 dev->
stats.rx_errors++;
685 dev->
stats.collisions++;
687 dev->
stats.rx_length_errors++;
689 dev->
stats.rx_over_errors++;
691 dev->
stats.rx_fifo_errors++;
693 dev->
stats.rx_frame_errors++;
695 dev->
stats.rx_crc_errors++;
697 dev->
stats.rx_length_errors++;
710 rfd = pa_to_va(lp->
scb.pa_rfd);
721 if (i596_rx_one(dev, lp, rfd, &frames))
738 lp = netdev_priv(dev);
745 switch ((cmd->
command) & 0x7) {
749 tx_cmd_tbd = pa_to_va(tx_cmd->
pa_tbd);
753 dev->
stats.tx_errors++;
754 dev->
stats.tx_aborted_errors++;
757 kfree((
unsigned char *)tx_cmd);
758 netif_wake_queue(dev);
765 kfree((
unsigned char *)cmd);
776 if (lp->
scb.command && i596_timeout(dev,
"i596_cleanup_cmd", 100))
784 if (lp->
scb.command && i596_timeout(dev,
"i596_reset", 100))
787 netif_stop_queue(dev);
794 if (lp->
scb.command && i596_timeout(dev,
"i596_reset(2)", 400))
797 i596_cleanup_cmd(dev);
800 netif_start_queue(dev);
817 lp->
cmd_tail->pa_next = va_to_pa(cmd);
820 if (lp->
scb.command && i596_timeout(dev,
"i596_add_cmd", 100))
822 lp->
scb.pa_cmd = va_to_pa(cmd);
830 spin_unlock_irqrestore(&lp->
cmd_lock, flags);
834 if (tickssofar <
HZ/4)
838 i596_reset(dev, lp, ioaddr);
859 netif_start_queue(dev);
877 if (tx_cmd ==
NULL) {
879 dev->
stats.tx_dropped++;
883 tx_cmd_tbd = (
struct i596_tbd *) (tx_cmd + 1);
884 tx_cmd->
pa_tbd = va_to_pa (tx_cmd_tbd);
898 print_eth (skb->
data);
900 i596_add_cmd (dev, (
struct i596_cmd *) tx_cmd);
902 dev->
stats.tx_packets++;
915 dev->
stats.tx_errors++;
919 printk (
"Resetting board.\n");
922 i596_reset (dev, lp, ioaddr);
925 printk (
"Kicking board.\n");
930 netif_wake_queue(dev);
933 static void print_eth(
char *
add)
938 for (i = 0; i < 6; i++)
939 printk(
" %2.2X", (
unsigned char) add[i]);
943 for (i = 0; i < 6; i++)
944 printk(
" %2.2X", (
unsigned char) add[i+6]);
947 printk (
"type %2.2X%2.2X\n",
948 (
unsigned char) add[12], (
unsigned char) add[13]);
952 .ndo_open = i596_open,
953 .ndo_stop = i596_close,
954 .ndo_start_xmit = i596_start_xmit,
955 .ndo_set_rx_mode = set_multicast_list,
956 .ndo_tx_timeout = i596_tx_timeout,
964 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 };
979 lp = netdev_priv(dev);
985 if (i596_scp_setup(dev)) {
1005 for (j = 0; j < 0x2000; j++) {
1006 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) {
1007 printk(
"%s: maybe address at BIOS 0x%x:",
1008 dev->
name, 0xe8000+j);
1009 for (i = 0; i < 6; i++) {
1010 eth_addr[
i] = bios[i+
j];
1011 printk(
" %2.2X", eth_addr[i]);
1017 printk(
"%s: lp486e 82596 at %#3lx, IRQ %d,",
1019 for (i = 0; i < 6; i++)
1040 i596_handle_CU_completion(
struct net_device *dev,
1042 unsigned short status,
1043 unsigned short *ack_cmdp) {
1046 int commands_done = 0;
1048 unsigned long flags;
1062 printk(
"finished CU %s command (%d)\n",
1063 CUcmdnames[cmd_val], cmd_val);
1071 tx_cmd = (
struct tx_cmd *) cmd;
1072 tx_cmd_tbd = pa_to_va(tx_cmd->
pa_tbd);
1077 print_eth(pa_to_va(tx_cmd_tbd->
pa_data));
1079 dev->
stats.tx_errors++;
1081 printk(
"transmission failure:%04x\n",
1083 if (cmd->
status & 0x0020)
1084 dev->
stats.collisions++;
1085 if (!(cmd->
status & 0x0040))
1086 dev->
stats.tx_heartbeat_errors++;
1087 if (cmd->
status & 0x0400)
1088 dev->
stats.tx_carrier_errors++;
1089 if (cmd->
status & 0x0800)
1090 dev->
stats.collisions++;
1091 if (cmd->
status & 0x1000)
1092 dev->
stats.tx_aborted_errors++;
1097 kfree((
unsigned char *)tx_cmd);
1098 netif_wake_queue(dev);
1104 kfree((
unsigned char *)cmd);
1109 unsigned long status = *((
unsigned long *) (cmd + 1));
1110 if (status & 0x8000) {
1114 if (status & 0x4000)
1115 printk(
"%s: Transceiver problem.\n",
1117 if (status & 0x2000)
1118 printk(
"%s: Termination problem.\n",
1120 if (status & 0x1000)
1121 printk(
"%s: Short circuit.\n",
1123 printk(
"%s: Time %ld.\n",
1124 dev->
name, status & 0x07ff);
1136 while (cmd && (cmd != lp->
cmd_tail)) {
1145 spin_unlock_irqrestore(&lp->
cmd_lock, flags);
1149 i596_interrupt(
int irq,
void *dev_instance)
1153 unsigned short status, ack_cmd = 0;
1160 if (lp->
scb.command && i596_timeout(dev,
"interrupt", 40))
1170 status = lp->
scb.status;
1174 i596_out_status(status);
1179 if (status == 0xffff) {
1180 printk(
"%s: i596_interrupt: got status 0xffff\n", dev->
name);
1186 if (status & (STAT_CX | STAT_CNA))
1187 i596_handle_CU_completion(dev, lp, status, &ack_cmd);
1189 if (status & (STAT_FR | STAT_RNR)) {
1191 if ((status & STAT_RNR) && netif_running(dev))
1194 if (status & STAT_FR) {
1195 frames_in = i596_rx(dev);
1197 printk(
"receive frame reported, but no frames\n");
1207 if (lp->
scb.command && i596_timeout(dev,
"i596 interrupt", 100))
1210 lp->
scb.command = ack_cmd;
1219 static int i596_close(
struct net_device *dev) {
1222 netif_stop_queue(dev);
1225 printk(
"%s: Shutting down ethercard, status was %4.4x.\n",
1231 i596_cleanup_cmd(dev);
1233 if (lp->
scb.command && i596_timeout(dev,
"i596_close", 200))
1237 remove_rx_bufs(dev);
1246 static void set_multicast_list(
struct net_device *dev) {
1251 printk (
"%s: set multicast list %d\n",
1265 cp = ((
char *)(cmd + 1))+2;
1271 print_eth (((
char *)(cmd + 1)) + 2);
1272 i596_add_cmd(dev, cmd);
1293 static int full_duplex;
1296 static int irq =
IRQ;
1305 static int __init lp486e_init_module(
void) {
1313 err = lp486e_probe(dev);
1330 static void __exit lp486e_cleanup_module(
void) {