28 #define DRV_NAME "3c507"
29 #define DRV_VERSION "1.10a"
30 #define DRV_RELDATE "11/17/2001"
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/types.h>
49 #include <linux/fcntl.h>
53 #include <linux/string.h>
55 #include <linux/ethtool.h>
56 #include <linux/errno.h>
57 #include <linux/netdevice.h>
59 #include <linux/if_ether.h>
62 #include <linux/bitops.h>
66 #include <asm/uaccess.h>
73 #define debug net_debug
91 #define CUC_START 0x0100
92 #define CUC_RESUME 0x0200
93 #define CUC_SUSPEND 0x0300
94 #define RX_START 0x0010
95 #define RX_RESUME 0x0020
96 #define RX_SUSPEND 0x0030
110 #define CMD_EOL 0x8000
111 #define CMD_SUSP 0x4000
112 #define CMD_INTR 0x2000
143 #define ROM_CONFIG 13
144 #define MEM_CONFIG 14
145 #define IRQ_CONFIG 15
146 #define EL16_IO_EXTENT 16
149 #define ID_PORT 0x100
152 #define iSCB_STATUS 0x8
166 #define SCB_BASE ((unsigned)64*1024 - (dev->mem_end - dev->mem_start))
184 #define CONFIG_CMD 0x0018
185 #define SET_SA_CMD 0x0024
186 #define SA_OFFSET 0x002A
187 #define IDLELOOP 0x30
189 #define TDR_TIME 0x3C
190 #define DUMP_CMD 0x40
191 #define DIAG_CMD 0x48
192 #define SET_MC_CMD 0x4E
193 #define DUMP_DATA 0x56
195 #define TX_BUF_START 0x0100
196 #define NUM_TX_BUFS 5
197 #define TX_BUF_SIZE (1518+14+20+16)
199 #define RX_BUF_START 0x2000
200 #define RX_BUF_SIZE (1518+14+18)
201 #define RX_BUF_END (dev->mem_end - dev->mem_start)
203 #define TX_TIMEOUT (HZ/20)
238 static unsigned short init_words[] = {
264 0xaa00,0xb000,0x0bad,
295 static const struct ethtool_ops netdev_ethtool_ops;
296 static void init_rx_bufs(
struct net_device *);
298 static int io = 0x300;
313 static const unsigned ports[] = { 0x300, 0x320, 0x340, 0x280, 0};
314 const unsigned *
port;
329 err = el16_probe1(dev,
io);
333 for (port = ports; *
port; port++) {
334 err = el16_probe1(dev, *port);
356 .ndo_open = el16_open,
357 .ndo_stop = el16_close,
358 .ndo_start_xmit = el16_send_packet,
359 .ndo_tx_timeout = el16_tx_timeout,
367 static unsigned char init_ID_done;
371 if (init_ID_done == 0) {
375 for(i = 0; i < 255; i++) {
378 if (lrs_state & 0x100)
388 if ((
inb(ioaddr) !=
'*') || (
inb(ioaddr + 1) !=
'3') ||
389 (
inb(ioaddr + 2) !=
'C') || (
inb(ioaddr + 3) !=
'O')) {
404 pr_err(
"3c507: unable to get IRQ %d (irqval=%d).\n", irq, irqval);
413 for (i = 0; i < 6; i++)
428 if (mem_config & 0x20) {
430 base = 0xf00000 + (mem_config & 0x08 ? 0x080000
431 : ((mem_config & 3) << 17));
433 size = ((mem_config & 3) + 1) << 14;
434 base = 0x0c0000 + ( (mem_config & 0x18) << 12);
444 pr_cont(
", IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->
irq,
450 lp = netdev_priv(dev);
454 pr_err(
"3c507: unable to remap memory\n");
476 netif_start_queue(dev);
481 static void el16_tx_timeout (
struct net_device *dev)
490 "network cable problem");
496 init_82586_mem (dev);
507 netif_wake_queue (dev);
518 unsigned char *
buf = skb->
data;
520 netif_stop_queue (dev);
528 hardware_send_packet (dev, buf, skb->
len, length - skb->
len);
533 spin_unlock_irqrestore (&lp->
lock, flags);
548 int ioaddr,
status, boguscount = 0;
553 pr_err(
"net_interrupt(): irq %d for unknown device.\n", irq);
558 lp = netdev_priv(dev);
561 spin_lock(&lp->
lock);
566 pr_debug(
"%s: 3c507 interrupt, status %4.4x.\n", dev->
name, status);
575 if (!(tx_status & 0x8000)) {
581 if (!(tx_status & 0x2000) || (tx_status & 0x0f3f)) {
582 dev->
stats.tx_errors++;
583 if (tx_status & 0x0600) dev->
stats.tx_carrier_errors++;
584 if (tx_status & 0x0100) dev->
stats.tx_fifo_errors++;
585 if (!(tx_status & 0x0040)) dev->
stats.tx_heartbeat_errors++;
586 if (tx_status & 0x0020) dev->
stats.tx_aborted_errors++;
587 dev->
stats.collisions += tx_status & 0xf;
589 dev->
stats.tx_packets++;
598 netif_wake_queue(dev);
600 if (++boguscount > 10)
604 if (status & 0x4000) {
611 ack_cmd = status & 0xf000;
613 if ((status & 0x0700) != 0x0200 && netif_running(dev)) {
615 pr_debug(
"%s: Command unit stopped, status %04x, restarting.\n",
623 if ((status & 0x0070) != 0x0040 && netif_running(dev)) {
627 pr_debug(
"%s: Rx unit stopped, status %04x, restarting.\n",
642 spin_unlock(&lp->
lock);
652 netif_stop_queue(dev);
669 static void init_rx_bufs(
struct net_device *dev)
680 write_ptr = lp->
base + cur_rxbuf;
683 writew(0x0000,write_ptr+=2);
685 writew(cur_rxbuf + 22,write_ptr+=2);
686 writew(0x0000,write_ptr+=2);
687 writew(0x0000,write_ptr+=2);
688 writew(0x0000,write_ptr+=2);
689 writew(0x0000,write_ptr+=2);
690 writew(0x0000,write_ptr+=2);
691 writew(0x0000,write_ptr+=2);
692 writew(0x0000,write_ptr+=2);
694 writew(0x0000,write_ptr+=2);
696 writew(cur_rxbuf + 0x20 + SCB_base,write_ptr+=2);
697 writew(0x0000,write_ptr+=2);
712 static void init_82586_mem(
struct net_device *dev)
751 if (--boguscnt == 0) {
752 pr_warning(
"%s: i82586 initialization timed out with status %04x, cmd %04x.\n",
763 pr_debug(
"%s: Initialized 82586, status %04x.\n", dev->
name,
778 writew(tx_block+16,write_ptr+=2);
779 writew(tx_block+8,write_ptr+=2);
782 writew((pad + length) | 0x8000,write_ptr+=2);
785 writew(0x0000,write_ptr+=2);
788 writew(0x0000,write_ptr+=2);
790 writew(tx_block+16,write_ptr+=2);
807 pr_debug(
"%s: 3c507 @%x send length = %d, tx_block %3x, next %3x.\n",
813 netif_wake_queue(dev);
825 while ((frame_status =
readw(shmem+rx_head)) < 0) {
830 void __iomem *data_frame = lp->
base + data_buffer_addr;
833 if (rfd_cmd != 0 || data_buffer_addr != rx_head + 22 ||
834 (pkt_len & 0xC000) != 0xC000) {
835 pr_err(
"%s: Rx frame at %#x corrupted, "
836 "status %04x cmd %04x next %04x "
837 "data-buf @%04x %04x.\n",
838 dev->
name, rx_head, frame_status, rfd_cmd,
839 next_rx_frame, data_buffer_addr, pkt_len);
840 }
else if ((frame_status & 0x2000) == 0) {
842 dev->
stats.rx_errors++;
843 if (frame_status & 0x0800) dev->
stats.rx_crc_errors++;
844 if (frame_status & 0x0400) dev->
stats.rx_frame_errors++;
845 if (frame_status & 0x0200) dev->
stats.rx_fifo_errors++;
846 if (frame_status & 0x0100) dev->
stats.rx_over_errors++;
847 if (frame_status & 0x0080) dev->
stats.rx_length_errors++;
853 skb = netdev_alloc_skb(dev, pkt_len + 2);
855 pr_err(
"%s: Memory squeeze, dropping packet.\n",
857 dev->
stats.rx_dropped++;
868 dev->
stats.rx_packets++;
874 writew(0xC000,read_frame+2);
879 rx_head = next_rx_frame;
880 if (--boguscount == 0)
888 static void netdev_get_drvinfo(
struct net_device *dev,
906 static const struct ethtool_ops netdev_ethtool_ops = {
907 .get_drvinfo = netdev_get_drvinfo,
908 .get_msglevel = netdev_get_msglevel,
909 .set_msglevel = netdev_set_msglevel,
922 pr_notice(
"3c507: You should not use auto-probing with insmod!\n");
924 return IS_ERR(dev_3c507) ? PTR_ERR(dev_3c507) : 0;