This source file includes following definitions.
- de620_ready
 
- de620_send_command
 
- de620_put_byte
 
- de620_read_byte
 
- de620_write_block
 
- de620_read_block
 
- de620_set_delay
 
- de620_set_register
 
- de620_get_register
 
- de620_open
 
- de620_close
 
- get_stats
 
- de620_set_multicast_list
 
- de620_start_xmit
 
- de620_interrupt
 
- de620_rx_intr
 
- adapter_init
 
- de620_probe
 
- ReadAWord
 
- read_eeprom
 
- init_module
 
- cleanup_module
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 
  30 
  31 
  32 
  33 
  34 
  35 
  36 
  37 
  38 
  39 
  40 
  41 static const char *version =
  42         "de620.c: $Revision: 1.31 $,  Bjorn Ekwall <bj0rn@blox.se>\n";
  43 
  44 
  45 
  46 
  47 
  48 
  49 
  50 
  51 
  52 
  53 
  54 
  55 
  56 
  57 
  58 
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 
  68 #ifndef READ_DELAY
  69 #define READ_DELAY 100  
  70 #endif
  71 
  72 #ifndef WRITE_DELAY
  73 #define WRITE_DELAY 100 
  74 #endif
  75 
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 
  87 
  88 
  89 
  90 
  91 
  92 
  93 
  94 
  95 #ifdef LOWSPEED
  96 
  97 
  98 
  99 
 100 
 101 
 102 #endif
 103 static int bnc, utp;
 104 
 105 
 106 
 107 
 108 
 109 
 110 
 111 #ifdef MODULE
 112 #include <linux/module.h>
 113 #include <linux/version.h>
 114 #endif
 115 
 116 #include <linux/kernel.h>
 117 #include <linux/sched.h>
 118 #include <linux/types.h>
 119 #include <linux/fcntl.h>
 120 #include <linux/string.h>
 121 #include <linux/interrupt.h>
 122 #include <linux/ioport.h>
 123 #include <asm/io.h>
 124 #include <linux/in.h>
 125 #include <linux/ptrace.h>
 126 #include <asm/system.h>
 127 #include <linux/errno.h>
 128 
 129 #include <linux/inet.h>
 130 #include <linux/netdevice.h>
 131 #include <linux/etherdevice.h>
 132 #include <linux/skbuff.h>
 133 
 134 
 135 #include "de620.h"
 136 
 137 #define netstats enet_statistics
 138 typedef unsigned char byte;
 139 
 140 
 141 
 142 
 143 
 144 
 145 
 146 #ifndef DE620_IO 
 147 #define DE620_IO 0x378
 148 #endif
 149 
 150 #ifndef DE620_IRQ 
 151 #define DE620_IRQ       7
 152 #endif
 153 
 154 #define DATA_PORT       (DE620_IO)
 155 #define STATUS_PORT     (DE620_IO + 1)
 156 #define COMMAND_PORT    (DE620_IO + 2)
 157 
 158 #define RUNT 60         
 159 #define GIANT 1514      
 160 
 161 #ifdef DE620_DEBUG 
 162 #define PRINTK(x) if (de620_debug >= 2) printk x
 163 #else
 164 #define DE620_DEBUG 0
 165 #define PRINTK(x) 
 166 #endif
 167 
 168 
 169 
 170 
 171 
 172 
 173 
 174 
 175 
 176 
 177 
 178 
 179 static int      de620_open(struct device *);
 180 static int      de620_close(struct device *);
 181 static struct netstats *get_stats(struct device *);
 182 static void     de620_set_multicast_list(struct device *, int, void *);
 183 static int      de620_start_xmit(struct sk_buff *, struct device *);
 184 
 185 
 186 static void     de620_interrupt(int, struct pt_regs *);
 187 static int      de620_rx_intr(struct device *);
 188 
 189 
 190 static int      adapter_init(struct device *);
 191 int             de620_probe(struct device *);
 192 static int      read_eeprom(void);
 193 
 194 
 195 
 196 
 197 
 198 #define SCR_DEF NIBBLEMODE |INTON | SLEEP | AUTOTX
 199 #define TCR_DEF RXPB                    
 200 #define DE620_RX_START_PAGE 12          
 201 #define DEF_NIC_CMD IRQEN | ICEN | DS1
 202 
 203 unsigned int de620_debug = DE620_DEBUG;
 204 
 205 static volatile byte    NIC_Cmd;
 206 static volatile byte    next_rx_page;
 207 static byte             first_rx_page;
 208 static byte             last_rx_page;
 209 static byte             EIPRegister;
 210 
 211 static struct nic {
 212         byte    NodeID[6];
 213         byte    RAM_Size;
 214         byte    Model;
 215         byte    Media;
 216         byte    SCR;
 217 } nic_data;
 218 
 219 
 220 
 221 
 222 
 223 
 224 #define de620_tx_buffs() (inb(STATUS_PORT) & (TXBF0 | TXBF1))
 225 #define de620_flip_ds() NIC_Cmd ^= DS0 | DS1; outb(NIC_Cmd, COMMAND_PORT);
 226 
 227 
 228 #ifdef COUNT_LOOPS
 229 static int tot_cnt;
 230 #endif
 231 static inline byte
 232 de620_ready(void)
     
 233 {
 234         byte value;
 235         register short int cnt = 0;
 236 
 237         while ((((value = inb(STATUS_PORT)) & READY) == 0) && (cnt <= 1000))
 238                 ++cnt;
 239 
 240 #ifdef COUNT_LOOPS
 241         tot_cnt += cnt;
 242 #endif
 243         return value & 0xf0; 
 244 }
 245 
 246 static inline void
 247 de620_send_command(byte cmd)
     
 248 {
 249         de620_ready();
 250         if (cmd == W_DUMMY)
 251                 outb(NIC_Cmd, COMMAND_PORT);
 252 
 253         outb(cmd, DATA_PORT);
 254 
 255         outb(NIC_Cmd ^ CS0, COMMAND_PORT);
 256         de620_ready();
 257         outb(NIC_Cmd, COMMAND_PORT);
 258 }
 259 
 260 static inline void
 261 de620_put_byte(byte value)
     
 262 {
 263         
 264         de620_ready();
 265         outb(value, DATA_PORT);
 266         de620_flip_ds();
 267 }
 268 
 269 static inline byte
 270 de620_read_byte(void)
     
 271 {
 272         byte value;
 273 
 274         
 275         value = de620_ready(); 
 276         de620_flip_ds();
 277         value |= de620_ready() >> 4; 
 278         return value;
 279 }
 280 
 281 static inline void
 282 de620_write_block(byte *buffer, int count)
     
 283 {
 284 #ifndef LOWSPEED
 285         byte uflip = NIC_Cmd ^ (DS0 | DS1);
 286         byte dflip = NIC_Cmd;
 287 #else 
 288 #ifdef COUNT_LOOPS
 289         int bytes = count;
 290 #endif 
 291 #endif 
 292 
 293 #ifdef LOWSPEED
 294 #ifdef COUNT_LOOPS
 295         tot_cnt = 0;
 296 #endif 
 297         
 298         for ( ; count > 0; --count, ++buffer) {
 299                 de620_put_byte(*buffer);
 300         }
 301         de620_send_command(W_DUMMY);
 302 #ifdef COUNT_LOOPS
 303         
 304         printk("WRITE(%d)\n", tot_cnt/((bytes?bytes:1)));
 305 #endif 
 306 #else 
 307         for ( ; count > 0; count -=2) {
 308                 outb(*buffer++, DATA_PORT);
 309                 outb(uflip, COMMAND_PORT);
 310                 outb(*buffer++, DATA_PORT);
 311                 outb(dflip, COMMAND_PORT);
 312         }
 313         de620_send_command(W_DUMMY);
 314 #endif 
 315 }
 316 
 317 static inline void
 318 de620_read_block(byte *data, int count)
     
 319 {
 320 #ifndef LOWSPEED
 321         byte value;
 322         byte uflip = NIC_Cmd ^ (DS0 | DS1);
 323         byte dflip = NIC_Cmd;
 324 #else 
 325 #ifdef COUNT_LOOPS
 326         int bytes = count;
 327 
 328         tot_cnt = 0;
 329 #endif 
 330 #endif 
 331 
 332 #ifdef LOWSPEED
 333         
 334         while (count-- > 0) {
 335                 *data++ = de620_read_byte();
 336                 de620_flip_ds();
 337         }
 338 #ifdef COUNT_LOOPS
 339         
 340         printk("READ(%d)\n", tot_cnt/(2*(bytes?bytes:1)));
 341 #endif 
 342 #else 
 343         while (count-- > 0) {
 344                 value = inb(STATUS_PORT) & 0xf0; 
 345                 outb(uflip, COMMAND_PORT);
 346                 *data++ = value | inb(STATUS_PORT) >> 4; 
 347                 outb(dflip , COMMAND_PORT);
 348         }
 349 #endif 
 350 }
 351 
 352 static inline void
 353 de620_set_delay(void)
     
 354 {
 355         de620_ready();
 356         outb(W_DFR, DATA_PORT);
 357         outb(NIC_Cmd ^ CS0, COMMAND_PORT);
 358 
 359         de620_ready();
 360 #ifdef LOWSPEED
 361         outb(WRITE_DELAY, DATA_PORT);
 362 #else
 363         outb(0, DATA_PORT);
 364 #endif
 365         de620_flip_ds();
 366 
 367         de620_ready();
 368 #ifdef LOWSPEED
 369         outb(READ_DELAY, DATA_PORT);
 370 #else
 371         outb(0, DATA_PORT);
 372 #endif
 373         de620_flip_ds();
 374 }
 375 
 376 static inline void
 377 de620_set_register(byte reg, byte value)
     
 378 {
 379         de620_ready();
 380         outb(reg, DATA_PORT);
 381         outb(NIC_Cmd ^ CS0, COMMAND_PORT);
 382 
 383         de620_put_byte(value);
 384 }
 385 
 386 static inline byte
 387 de620_get_register(byte reg)
     
 388 {
 389         byte value;
 390 
 391         de620_send_command(reg);
 392         value = de620_read_byte();
 393         de620_send_command(W_DUMMY);
 394 
 395         return value;
 396 }
 397 
 398 
 399 
 400 
 401 
 402 
 403 
 404 
 405 
 406 
 407 static int
 408 de620_open(struct device *dev)
     
 409 {
 410         if (request_irq(DE620_IRQ, de620_interrupt, 0, "de620")) {
 411                 printk ("%s: unable to get IRQ %d\n", dev->name, DE620_IRQ);
 412                 return 1;
 413         }
 414         irq2dev_map[DE620_IRQ] = dev;
 415 
 416 #ifdef MODULE
 417         MOD_INC_USE_COUNT;
 418 #endif
 419         if (adapter_init(dev)) {
 420                 return 1;
 421         }
 422         dev->start = 1;
 423         return 0;
 424 }
 425 
 426 
 427 
 428 
 429 
 430 
 431 static int
 432 de620_close(struct device *dev)
     
 433 {
 434         
 435         de620_set_register(W_TCR, RXOFF);
 436 
 437         free_irq(DE620_IRQ);
 438         irq2dev_map[DE620_IRQ] = NULL;
 439 
 440         dev->start = 0;
 441 #ifdef MODULE
 442         MOD_DEC_USE_COUNT;
 443 #endif
 444         return 0;
 445 }
 446 
 447 
 448 
 449 
 450 
 451 
 452 static struct netstats *
 453 get_stats(struct device *dev)
     
 454 {
 455         return (struct netstats *)(dev->priv);
 456 }
 457 
 458 
 459 
 460 
 461 
 462 
 463 
 464 
 465 
 466 
 467 
 468 static void
 469 de620_set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     
 470 {
 471         if (num_addrs) { 
 472                 de620_set_register(W_TCR, (TCR_DEF & ~RXPBM) | RXALL);
 473         }
 474         else { 
 475                 de620_set_register(W_TCR, TCR_DEF);
 476         }
 477 }
 478 
 479 
 480 
 481 
 482 
 483 
 484 static int
 485 de620_start_xmit(struct sk_buff *skb, struct device *dev)
     
 486 {
 487         unsigned long flags;
 488         int len;
 489         int tickssofar;
 490         byte *buffer = skb->data;
 491         byte using_txbuf;
 492 
 493         
 494 
 495 
 496 
 497 
 498 
 499         if (skb == NULL) {
 500                 dev_tint(dev);
 501                 return 0;
 502         }
 503 
 504         using_txbuf = de620_tx_buffs(); 
 505         dev->tbusy = (using_txbuf == (TXBF0 | TXBF1)); 
 506 
 507         if (dev->tbusy) {       
 508                 tickssofar = jiffies - dev->trans_start;
 509 
 510                 if (tickssofar < 5)
 511                         return 1;
 512 
 513                 
 514                 printk("%s: transmit timed out (%d), %s?\n",
 515                         dev->name,
 516                         tickssofar,
 517                         "network cable problem"
 518                         );
 519                 
 520                 if (adapter_init(dev)) 
 521                         return 1;
 522         }
 523 
 524         if ((len = skb->len) < RUNT)
 525                 len = RUNT;
 526         if (len & 1) 
 527                 ++len;
 528 
 529         
 530         save_flags(flags);
 531         cli();
 532 
 533         PRINTK(("de620_start_xmit: len=%d, bufs 0x%02x\n",
 534                 (int)skb->len, using_txbuf));
 535 
 536         
 537         switch (using_txbuf) {
 538         default: 
 539         case TXBF1: 
 540                 de620_send_command(W_CR | RW0);
 541                 using_txbuf |= TXBF0;
 542                 break;
 543 
 544         case TXBF0: 
 545                 de620_send_command(W_CR | RW1);
 546                 using_txbuf |= TXBF1;
 547                 break;
 548 
 549         case (TXBF0 | TXBF1): 
 550                 printk("de620: Ouch! No tx-buffer available!\n");
 551                 restore_flags(flags);
 552                 return 1;
 553                 break;
 554         }
 555         de620_write_block(buffer, len);
 556 
 557         dev->trans_start = jiffies;
 558         dev->tbusy = (using_txbuf == (TXBF0 | TXBF1)); 
 559 
 560         ((struct netstats *)(dev->priv))->tx_packets++;
 561         
 562         restore_flags(flags); 
 563         
 564         dev_kfree_skb (skb, FREE_WRITE);
 565 
 566         return 0;
 567 }
 568 
 569 
 570 
 571 
 572 
 573 
 574 static void
 575 de620_interrupt(int irq, struct pt_regs *regs)
     
 576 {
 577         struct device *dev = irq2dev_map[irq];
 578         byte irq_status;
 579         int bogus_count = 0;
 580         int again = 0;
 581 
 582         
 583         if ((dev == NULL) || (DE620_IRQ != irq)) {
 584                 printk("%s: bogus interrupt %d\n", dev?dev->name:"DE620", irq);
 585                 return;
 586         }
 587 
 588         cli();
 589         dev->interrupt = 1;
 590 
 591         
 592         irq_status = de620_get_register(R_STS);
 593 
 594         PRINTK(("de620_interrupt (%2.2X)\n", irq_status));
 595 
 596         if (irq_status & RXGOOD) {
 597                 do {
 598                         again = de620_rx_intr(dev);
 599                         PRINTK(("again=%d\n", again));
 600                 }
 601                 while (again && (++bogus_count < 100));
 602         }
 603 
 604         dev->tbusy = (de620_tx_buffs() == (TXBF0 | TXBF1)); 
 605 
 606         dev->interrupt = 0;
 607         sti();
 608         return;
 609 }
 610 
 611 
 612 
 613 
 614 
 615 
 616 
 617 
 618 static int
 619 de620_rx_intr(struct device *dev)
     
 620 {
 621         struct header_buf {
 622                 byte            status;
 623                 byte            Rx_NextPage;
 624                 unsigned short  Rx_ByteCount;
 625         } header_buf;
 626         struct sk_buff *skb;
 627         int size;
 628         byte *buffer;
 629         byte pagelink;
 630         byte curr_page;
 631 
 632         PRINTK(("de620_rx_intr: next_rx_page = %d\n", next_rx_page));
 633 
 634         
 635         de620_send_command(W_CR | RRN);
 636         de620_set_register(W_RSA1, next_rx_page);
 637         de620_set_register(W_RSA0, 0);
 638 
 639         
 640         de620_read_block((byte *)&header_buf, sizeof(struct header_buf));
 641         PRINTK(("page status=0x%02x, nextpage=%d, packetsize=%d\n",
 642         header_buf.status, header_buf.Rx_NextPage, header_buf.Rx_ByteCount));
 643 
 644         
 645         pagelink = header_buf.Rx_NextPage;
 646         if ((pagelink < first_rx_page) || (last_rx_page < pagelink)) {
 647                 
 648                 printk("%s: Ring overrun? Restoring...\n", dev->name);
 649                 
 650                 adapter_init(dev);
 651                 ((struct netstats *)(dev->priv))->rx_over_errors++;
 652                 return 0;
 653         }
 654 
 655         
 656         
 657         pagelink = next_rx_page +
 658                 ((header_buf.Rx_ByteCount + (4 - 1 + 0x100)) >> 8);
 659 
 660         
 661         if (pagelink > last_rx_page)
 662                 pagelink -= (last_rx_page - first_rx_page + 1);
 663 
 664         
 665         if (pagelink != header_buf.Rx_NextPage) {
 666                 
 667                 printk("%s: Page link out of sync! Restoring...\n", dev->name);
 668                 next_rx_page = header_buf.Rx_NextPage; 
 669                 de620_send_command(W_DUMMY);
 670                 de620_set_register(W_NPRF, next_rx_page);
 671                 ((struct netstats *)(dev->priv))->rx_over_errors++;
 672                 return 0;
 673         }
 674         next_rx_page = pagelink;
 675 
 676         size = header_buf.Rx_ByteCount - 4;
 677         if ((size < RUNT) || (GIANT < size)) {
 678                 printk("%s: Illegal packet size: %d!\n", dev->name, size);
 679         }
 680         else { 
 681                 skb = dev_alloc_skb(size+2);
 682                 if (skb == NULL) { 
 683                         printk("%s: Couldn't allocate a sk_buff of size %d.\n",
 684                                 dev->name, size);
 685                         ((struct netstats *)(dev->priv))->rx_dropped++;
 686                 }
 687                 else { 
 688                         skb_reserve(skb,2);     
 689                         skb->dev = dev;
 690                         skb->free = 1;
 691                         
 692                         buffer = skb_put(skb,size);
 693                         
 694                         de620_read_block(buffer, size);
 695                         PRINTK(("Read %d bytes\n", size));
 696                         skb->protocol=eth_type_trans(skb,dev);
 697                         netif_rx(skb); 
 698                         
 699                         ((struct netstats *)(dev->priv))->rx_packets++;
 700                 }
 701         }
 702 
 703         
 704         
 705         curr_page = de620_get_register(R_CPR);
 706         de620_set_register(W_NPRF, next_rx_page);
 707         PRINTK(("next_rx_page=%d CPR=%d\n", next_rx_page, curr_page));
 708 
 709         return (next_rx_page != curr_page); 
 710 }
 711 
 712 
 713 
 714 
 715 
 716 
 717 static int
 718 adapter_init(struct device *dev)
     
 719 {
 720         int i;
 721         static int was_down = 0;
 722 
 723         if ((nic_data.Model == 3) || (nic_data.Model == 0)) { 
 724                 EIPRegister = NCTL0;
 725                 if (nic_data.Media != 1)
 726                         EIPRegister |= NIS0;    
 727         }
 728         else if (nic_data.Model == 2) { 
 729                 EIPRegister = NCTL0 | NIS0;
 730         }
 731 
 732         if (utp)
 733                 EIPRegister = NCTL0 | NIS0;
 734         if (bnc)
 735                 EIPRegister = NCTL0;
 736 
 737         de620_send_command(W_CR | RNOP | CLEAR);
 738         de620_send_command(W_CR | RNOP);
 739 
 740         de620_set_register(W_SCR, SCR_DEF);
 741         
 742         de620_set_register(W_TCR, RXOFF);
 743 
 744         
 745         for (i = 0; i < 6; ++i) { 
 746                 de620_set_register(W_PAR0 + i, dev->dev_addr[i]);
 747         }
 748 
 749         de620_set_register(W_EIP, EIPRegister);
 750 
 751         next_rx_page = first_rx_page = DE620_RX_START_PAGE;
 752         if (nic_data.RAM_Size)
 753                 last_rx_page = nic_data.RAM_Size - 1;
 754         else 
 755                 last_rx_page = 255;
 756 
 757         de620_set_register(W_SPR, first_rx_page); 
 758         de620_set_register(W_EPR, last_rx_page);  
 759         de620_set_register(W_CPR, first_rx_page); 
 760         de620_send_command(W_NPR | first_rx_page); 
 761         de620_send_command(W_DUMMY);
 762         de620_set_delay();
 763 
 764         
 765         
 766 #define CHECK_MASK (  0 | TXSUC |  T16  |  0  | RXCRC | RXSHORT |  0  |  0  )
 767 #define CHECK_OK   (  0 |   0   |  0    |  0  |   0   |   0     |  0  |  0  )
 768         
 769         
 770 
 771         if (((i = de620_get_register(R_STS)) & CHECK_MASK) != CHECK_OK) {
 772                 printk("Something has happened to the DE-620!  Please check it"
 773 #ifdef SHUTDOWN_WHEN_LOST
 774                         " and do a new ifconfig"
 775 #endif
 776                         "! (%02x)\n", i);
 777 #ifdef SHUTDOWN_WHEN_LOST
 778                 
 779                 dev->flags &= ~IFF_UP;
 780                 de620_close(dev);
 781 #endif
 782                 was_down = 1;
 783                 return 1; 
 784         }
 785         if (was_down) {
 786                 printk("Thanks, I feel much better now!\n");
 787                 was_down = 0;
 788         }
 789 
 790         
 791         de620_set_register(W_TCR, TCR_DEF);
 792 
 793         return 0; 
 794 }
 795 
 796 
 797 
 798 
 799 
 800 
 801 
 802 
 803 
 804 
 805 int
 806 de620_probe(struct device *dev)
     
 807 {
 808         static struct netstats de620_netstats;
 809         int i;
 810         byte checkbyte = 0xa5;
 811 
 812         if (de620_debug)
 813                 printk(version);
 814 
 815         printk("D-Link DE-620 pocket adapter");
 816 
 817         
 818         NIC_Cmd = DEF_NIC_CMD;
 819         de620_set_register(W_EIP, EIPRegister);
 820 
 821         
 822         de620_set_register(W_CPR, checkbyte);
 823         checkbyte = de620_get_register(R_CPR);
 824 
 825         if ((checkbyte != 0xa5) || (read_eeprom() != 0)) {
 826                 printk(" not identified in the printer port\n");
 827                 return ENODEV;
 828         }
 829 
 830 #if 0 
 831         if (check_region(DE620_IO, 3)) {
 832                 printk(", port 0x%x busy\n", DE620_IO);
 833                 return EBUSY;
 834         }
 835 #endif
 836         request_region(DE620_IO, 3, "de620");
 837 
 838         
 839         printk(", Ethernet Address: %2.2X",
 840                 dev->dev_addr[0] = nic_data.NodeID[0]);
 841         for (i = 1; i < ETH_ALEN; i++) {
 842                 printk(":%2.2X", dev->dev_addr[i] = nic_data.NodeID[i]);
 843                 dev->broadcast[i] = 0xff;
 844         }
 845 
 846         printk(" (%dk RAM,",
 847                 (nic_data.RAM_Size) ? (nic_data.RAM_Size >> 2) : 64);
 848 
 849         if (nic_data.Media == 1)
 850                 printk(" BNC)\n");
 851         else
 852                 printk(" UTP)\n");
 853 
 854         
 855         
 856         dev->priv = &de620_netstats;
 857 
 858         memset(dev->priv, 0, sizeof(struct netstats));
 859         dev->get_stats = get_stats;
 860         dev->open = de620_open;
 861         dev->stop = de620_close;
 862         dev->hard_start_xmit = &de620_start_xmit;
 863         dev->set_multicast_list = &de620_set_multicast_list;
 864         dev->base_addr = DE620_IO;
 865         dev->irq = DE620_IRQ;
 866 
 867         ether_setup(dev);
 868         
 869         
 870         if (de620_debug) {
 871                 printk("\nEEPROM contents:\n");
 872                 printk("RAM_Size = 0x%02X\n", nic_data.RAM_Size);
 873                 printk("NodeID = %02X:%02X:%02X:%02X:%02X:%02X\n",
 874                         nic_data.NodeID[0], nic_data.NodeID[1],
 875                         nic_data.NodeID[2], nic_data.NodeID[3],
 876                         nic_data.NodeID[4], nic_data.NodeID[5]);
 877                 printk("Model = %d\n", nic_data.Model);
 878                 printk("Media = %d\n", nic_data.Media);
 879                 printk("SCR = 0x%02x\n", nic_data.SCR);
 880         }
 881 
 882         return 0;
 883 }
 884 
 885 
 886 
 887 
 888 
 889 
 890 
 891 #define sendit(data) de620_set_register(W_EIP, data | EIPRegister);
 892 
 893 static unsigned short
 894 ReadAWord(int from)
     
 895 {
 896         unsigned short data;
 897         int nbits;
 898 
 899         
 900         
 901         
 902         sendit(0); sendit(1); sendit(5); sendit(4);
 903 
 904         
 905         for (nbits = 9; nbits > 0; --nbits, from <<= 1) {
 906                 if (from & 0x0100) { 
 907                         
 908                         
 909                         
 910                         sendit(6); sendit(7); sendit(7); sendit(6);
 911                 }
 912                 else {
 913                         
 914                         
 915                         
 916                         sendit(4); sendit(5); sendit(5); sendit(4);
 917                 }
 918         }
 919 
 920         
 921         for (data = 0, nbits = 16; nbits > 0; --nbits) {
 922                 
 923                 
 924                 
 925                 sendit(4); sendit(5); sendit(5); sendit(4);
 926                 data = (data << 1) | ((de620_get_register(R_STS) & EEDI) >> 7);
 927         }
 928         
 929         
 930         
 931         sendit(0); sendit(1); sendit(1); sendit(0);
 932 
 933         return data;
 934 }
 935 
 936 static int
 937 read_eeprom(void)
     
 938 {
 939         unsigned short wrd;
 940 
 941         
 942         wrd = ReadAWord(0x1aa); 
 943         if (wrd != htons(0x0080)) 
 944                 return -1; 
 945         nic_data.NodeID[0] = wrd & 0xff;
 946         nic_data.NodeID[1] = wrd >> 8;
 947 
 948         wrd = ReadAWord(0x1ab); 
 949         if ((wrd & 0xff) != 0xc8) 
 950                 return -1; 
 951         nic_data.NodeID[2] = wrd & 0xff;
 952         nic_data.NodeID[3] = wrd >> 8;
 953 
 954         wrd = ReadAWord(0x1ac); 
 955         nic_data.NodeID[4] = wrd & 0xff;
 956         nic_data.NodeID[5] = wrd >> 8;
 957 
 958         wrd = ReadAWord(0x1ad); 
 959         nic_data.RAM_Size = (wrd >> 8);
 960 
 961         wrd = ReadAWord(0x1ae); 
 962         nic_data.Model = (wrd & 0xff);
 963 
 964         wrd = ReadAWord(0x1af); 
 965         nic_data.Media = (wrd & 0xff);
 966 
 967         wrd = ReadAWord(0x1a8); 
 968         nic_data.SCR = (wrd >> 8);
 969 
 970         return 0; 
 971 }
 972 
 973 
 974 
 975 
 976 
 977 
 978 #ifdef MODULE
 979 char kernel_version[] = UTS_RELEASE;
 980 static char nullname[8];
 981 static struct device de620_dev = {
 982         nullname, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, de620_probe };
 983 
 984 int
 985 init_module(void)
     
 986 {
 987         if (register_netdev(&de620_dev) != 0)
 988                 return -EIO;
 989         return 0;
 990 }
 991 
 992 void
 993 cleanup_module(void)
     
 994 {
 995         unregister_netdev(&de620_dev);
 996         release_region(DE620_IO, 3);
 997 }
 998 #endif 
 999 
1000 
1001 
1002 
1003 
1004 
1005 
1006 
1007