84 #define READ_DELAY 100
88 #define WRITE_DELAY 100
109 #include <linux/module.h>
110 #include <linux/kernel.h>
111 #include <linux/types.h>
112 #include <linux/fcntl.h>
113 #include <linux/string.h>
116 #include <linux/in.h>
117 #include <linux/errno.h>
120 #include <linux/netdevice.h>
138 #define DE620_IO 0x378
145 #define DATA_PORT (dev->base_addr)
146 #define STATUS_PORT (dev->base_addr + 1)
147 #define COMMAND_PORT (dev->base_addr + 2)
196 static void de620_set_multicast_list(
struct net_device *);
201 static int de620_rx_intr(
struct net_device *);
211 #define SCR_DEF NIBBLEMODE |INTON | SLEEP | AUTOTX
213 #define DE620_RX_START_PAGE 12
214 #define DEF_NIC_CMD IRQEN | ICEN | DS1
216 static volatile byte NIC_Cmd;
218 static byte first_rx_page;
219 static byte last_rx_page;
220 static byte EIPRegister;
235 #define de620_tx_buffs(dd) (inb(STATUS_PORT) & (TXBF0 | TXBF1))
236 #define de620_flip_ds(dd) NIC_Cmd ^= DS0 | DS1; outb(NIC_Cmd, COMMAND_PORT);
246 register short int cnt = 0;
286 value = de620_ready(dev);
288 value |= de620_ready(dev) >> 4;
297 byte dflip = NIC_Cmd;
310 de620_put_byte(dev,*buffer);
312 for ( count = pad ; count > 0; --
count, ++
buffer) {
313 de620_put_byte(dev, 0);
315 de620_send_command(dev,
W_DUMMY);
318 printk(
"WRITE(%d)\n", tot_cnt/((bytes?bytes:1)));
321 for ( ; count > 0; count -=2) {
327 de620_send_command(dev,
W_DUMMY);
337 byte dflip = NIC_Cmd;
348 while (count-- > 0) {
349 *data++ = de620_read_byte(dev);
354 printk(
"READ(%d)\n", tot_cnt/(2*(bytes?bytes:1)));
357 while (count-- > 0) {
397 de620_put_byte(dev, value);
405 de620_send_command(dev,reg);
406 value = de620_read_byte(dev);
407 de620_send_command(dev,
W_DUMMY);
429 if (adapter_init(dev)) {
434 netif_start_queue(dev);
448 static int de620_close(
struct net_device *dev)
450 netif_stop_queue(dev);
464 static void de620_set_multicast_list(
struct net_device *dev)
481 static void de620_timeout(
struct net_device *dev)
485 if (!adapter_init(dev))
486 netif_wake_queue(dev);
503 netif_stop_queue(dev);
514 pr_debug(
"de620_start_xmit: len=%d, bufs 0x%02x\n",
515 (
int)skb->
len, using_txbuf);
518 switch (using_txbuf) {
521 de620_send_command(dev,
W_CR |
RW0);
522 using_txbuf |=
TXBF0;
526 de620_send_command(dev,
W_CR |
RW1);
527 using_txbuf |=
TXBF1;
532 spin_unlock_irqrestore(&de620_lock, flags);
535 de620_write_block(dev, buffer, skb->
len, len-skb->
len);
538 netif_wake_queue(dev);
540 dev->
stats.tx_packets++;
541 spin_unlock_irqrestore(&de620_lock, flags);
552 de620_interrupt(
int irq_in,
void *
dev_id)
559 spin_lock(&de620_lock);
562 irq_status = de620_get_register(dev,
R_STS);
564 pr_debug(
"de620_interrupt (%2.2X)\n", irq_status);
566 if (irq_status &
RXGOOD) {
568 again = de620_rx_intr(dev);
571 while (again && (++bogus_count < 100));
575 netif_wake_queue(dev);
577 spin_unlock(&de620_lock);
588 static int de620_rx_intr(
struct net_device *dev)
593 unsigned short Rx_ByteCount;
604 de620_send_command(dev,
W_CR |
RRN);
606 de620_set_register(dev,
W_RSA0, 0);
609 de620_read_block(dev, (
byte *)&header_buf,
sizeof(
struct header_buf));
610 pr_debug(
"page status=0x%02x, nextpage=%d, packetsize=%d\n",
611 header_buf.status, header_buf.Rx_NextPage,
612 header_buf.Rx_ByteCount);
615 pagelink = header_buf.Rx_NextPage;
616 if ((pagelink < first_rx_page) || (last_rx_page < pagelink)) {
621 netif_wake_queue(dev);
622 dev->
stats.rx_over_errors++;
629 ((header_buf.Rx_ByteCount + (4 - 1 + 0x100)) >> 8);
632 if (pagelink > last_rx_page)
633 pagelink -= (last_rx_page - first_rx_page + 1);
636 if (pagelink != header_buf.Rx_NextPage) {
640 de620_send_command(dev,
W_DUMMY);
642 dev->
stats.rx_over_errors++;
647 size = header_buf.Rx_ByteCount - 4;
652 skb = netdev_alloc_skb(dev, size + 2);
655 dev->
stats.rx_dropped++;
662 de620_read_block(dev, buffer, size);
667 dev->
stats.rx_packets++;
674 curr_page = de620_get_register(dev,
R_CPR);
686 static int adapter_init(
struct net_device *dev)
691 if ((nic_data.Model == 3) || (nic_data.Model == 0)) {
693 if (nic_data.Media != 1)
696 else if (nic_data.Model == 2) {
706 de620_send_command(dev,
W_CR |
RNOP);
713 for (i = 0; i < 6; ++
i) {
717 de620_set_register(dev,
W_EIP, EIPRegister);
720 if (nic_data.RAM_Size)
721 last_rx_page = nic_data.RAM_Size - 1;
725 de620_set_register(dev,
W_SPR, first_rx_page);
726 de620_set_register(dev,
W_EPR, last_rx_page);
727 de620_set_register(dev,
W_CPR, first_rx_page);
728 de620_send_command(dev,
W_NPR | first_rx_page);
729 de620_send_command(dev,
W_DUMMY);
730 de620_set_delay(dev);
734 #define CHECK_MASK ( 0 | TXSUC | T16 | 0 | RXCRC | RXSHORT | 0 | 0 )
735 #define CHECK_OK ( 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 )
739 if (((i = de620_get_register(dev,
R_STS)) & CHECK_MASK) != CHECK_OK) {
740 printk(
KERN_ERR "%s: Something has happened to the DE-620! Please check it"
741 #ifdef SHUTDOWN_WHEN_LOST
742 " and do a new ifconfig"
744 "! (%02x)\n", dev->
name, i);
745 #ifdef SHUTDOWN_WHEN_LOST
765 .ndo_open = de620_open,
766 .ndo_stop = de620_close,
767 .ndo_start_xmit = de620_start_xmit,
768 .ndo_tx_timeout = de620_timeout,
769 .ndo_set_rx_mode = de620_set_multicast_list,
786 byte checkbyte = 0xa5;
791 dev = alloc_etherdev(0);
822 de620_set_register(dev,
W_EIP, EIPRegister);
825 de620_set_register(dev,
W_CPR, checkbyte);
826 checkbyte = de620_get_register(dev,
R_CPR);
828 if ((checkbyte != 0xa5) || (
read_eeprom(dev) != 0)) {
829 printk(
" not identified in the printer port\n");
835 dev->
dev_addr[0] = nic_data.NodeID[0];
844 (nic_data.RAM_Size) ? (nic_data.RAM_Size >> 2) : 64);
846 if (nic_data.Media == 1)
858 "RAM_Size = 0x%02X\n"
862 "SCR = 0x%02x\n", nic_data.RAM_Size, nic_data.NodeID,
863 nic_data.Model, nic_data.Media, nic_data.SCR);
884 #define sendit(dev,data) de620_set_register(dev, W_EIP, data | EIPRegister);
897 for (nbits = 9; nbits > 0; --nbits, from <<= 1) {
913 for (data = 0, nbits = 16; nbits > 0; --nbits) {
933 wrd = ReadAWord(dev, 0x1aa);
934 if (!clone && (wrd !=
htons(0x0080)))
936 nic_data.NodeID[0] = wrd & 0xff;
937 nic_data.NodeID[1] = wrd >> 8;
939 wrd = ReadAWord(dev, 0x1ab);
940 if (!clone && ((wrd & 0xff) != 0xc8))
942 nic_data.NodeID[2] = wrd & 0xff;
943 nic_data.NodeID[3] = wrd >> 8;
945 wrd = ReadAWord(dev, 0x1ac);
946 nic_data.NodeID[4] = wrd & 0xff;
947 nic_data.NodeID[5] = wrd >> 8;
949 wrd = ReadAWord(dev, 0x1ad);
950 nic_data.RAM_Size = (wrd >> 8);
952 wrd = ReadAWord(dev, 0x1ae);
953 nic_data.Model = (wrd & 0xff);
955 wrd = ReadAWord(dev, 0x1af);
956 nic_data.Media = (wrd & 0xff);
958 wrd = ReadAWord(dev, 0x1a8);
959 nic_data.SCR = (wrd >> 8);
975 if (IS_ERR(de620_dev))
976 return PTR_ERR(de620_dev);