This source file includes following definitions.
- __get_order
 
- dma_mem_alloc
 
- inb_status
 
- inb_control
 
- inb_command
 
- outb_control
 
- outb_command
 
- inw_data
 
- outw_data
 
- backlog_next
 
- get_status
 
- set_hsf
 
- adapter_reset
 
- check_dma
 
- send_pcb_slow
 
- send_pcb_fast
 
- prime_rx
 
- send_pcb
 
- receive_pcb
 
- start_receive
 
- receive_packet
 
- elp_interrupt
 
- elp_open
 
- send_packet
 
- elp_start_xmit
 
- elp_get_stats
 
- elp_close
 
- elp_set_mc_list
 
- elp_init
 
- elp_sense
 
- elp_autodetect
 
- elplus_probe
 
- 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 
  42 
  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 
  69 
  70 
  71 
  72 
  73 
  74 
  75 
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 #include <linux/module.h>
  87 
  88 #include <linux/kernel.h>
  89 #include <linux/sched.h>
  90 #include <linux/string.h>
  91 #include <linux/interrupt.h>
  92 #include <linux/ptrace.h>
  93 #include <linux/errno.h>
  94 #include <linux/in.h>
  95 #include <linux/malloc.h>
  96 #include <linux/ioport.h>
  97 #include <asm/bitops.h>
  98 #include <asm/io.h>
  99 #include <asm/dma.h>
 100 
 101 #include <linux/netdevice.h>
 102 #include <linux/etherdevice.h>
 103 #include <linux/skbuff.h>
 104 
 105 #include "3c505.h"
 106 
 107 #define ELP_DMA      6          
 108 #define ELP_RX_PCBS  4
 109 
 110 
 111 
 112 
 113 
 114 
 115 
 116 static const char *filename = __FILE__;
 117 
 118 static const char *timeout_msg = "*** timeout at %s:%s (line %d) ***\n";
 119 #define TIMEOUT_MSG(lineno) \
 120         printk(timeout_msg, filename,__FUNCTION__,(lineno))
 121 
 122 static const char *invalid_pcb_msg =
 123 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
 124 #define INVALID_PCB_MSG(len) \
 125         printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
 126 
 127 static const char *search_msg = "%s: Looking for 3c505 adapter at address %#x...";
 128 
 129 static const char *stilllooking_msg = "still looking...";
 130 
 131 static const char *found_msg = "found.\n";
 132 
 133 static const char *notfound_msg = "not found (reason = %d)\n";
 134 
 135 static const char *couldnot_msg = "%s: 3c505 not found\n";
 136 
 137 
 138 
 139 
 140 
 141 
 142 
 143 #ifdef ELP_DEBUG
 144 static const int elp_debug = ELP_DEBUG;
 145 #else
 146 static const int elp_debug = 0;
 147 #endif
 148 
 149 
 150 
 151 
 152 
 153 
 154 
 155 
 156 
 157 
 158 
 159 
 160 
 161 
 162 #ifndef TRUE
 163 #define TRUE    1
 164 #endif
 165 
 166 #ifndef FALSE
 167 #define FALSE   0
 168 #endif
 169 
 170 
 171 
 172 
 173 
 174 
 175 
 176 
 177 const int addr_list[] = {0x300, 0x280, 0x310, 0};
 178 
 179 
 180 
 181 
 182 static inline int __get_order(unsigned long size)
     
 183 {
 184         int order;
 185 
 186         size = (size - 1) >> (PAGE_SHIFT - 1);
 187         order = -1;
 188         do {
 189                 size >>= 1;
 190                 order++;
 191         } while (size);
 192         return order;
 193 }
 194 
 195 static unsigned long dma_mem_alloc(int size)
     
 196 {
 197         int order = __get_order(size);
 198 
 199         return __get_dma_pages(GFP_KERNEL, order);
 200 }
 201 
 202 
 203 
 204 
 205 
 206 
 207 
 208 
 209 static inline unsigned char inb_status(unsigned int base_addr)
     
 210 {
 211         return inb(base_addr + PORT_STATUS);
 212 }
 213 
 214 static inline unsigned char inb_control(unsigned int base_addr)
     
 215 {
 216         return inb(base_addr + PORT_CONTROL);
 217 }
 218 
 219 static inline int inb_command(unsigned int base_addr)
     
 220 {
 221         return inb(base_addr + PORT_COMMAND);
 222 }
 223 
 224 static inline void outb_control(unsigned char val, unsigned int base_addr)
     
 225 {
 226         outb(val, base_addr + PORT_CONTROL);
 227 }
 228 
 229 static inline void outb_command(unsigned char val, unsigned int base_addr)
     
 230 {
 231         outb(val, base_addr + PORT_COMMAND);
 232 }
 233 
 234 static inline unsigned int inw_data(unsigned int base_addr)
     
 235 {
 236         return inw(base_addr + PORT_DATA);
 237 }
 238 
 239 static inline void outw_data(unsigned int val, unsigned int base_addr)
     
 240 {
 241         outw(val, base_addr + PORT_DATA);
 242 }
 243 
 244 
 245 
 246 
 247 
 248 
 249 
 250 
 251 #define DMA_BUFFER_SIZE  1600
 252 #define BACKLOG_SIZE      4
 253 
 254 typedef struct {
 255         volatile short got[NUM_TRANSMIT_CMDS];  
 256         pcb_struct tx_pcb;      
 257         pcb_struct rx_pcb;      
 258         pcb_struct itx_pcb;     
 259         pcb_struct irx_pcb;     
 260         struct enet_statistics stats;
 261 
 262         void *dma_buffer;
 263 
 264         struct {
 265                 unsigned int length[BACKLOG_SIZE];
 266                 unsigned int in;
 267                 unsigned int out;
 268         } rx_backlog;
 269 
 270         struct {
 271                 unsigned int direction;
 272                 unsigned int length;
 273                 unsigned int copy_flag;
 274                 struct sk_buff *skb;
 275                 long int start_time;
 276         } current_dma;
 277 
 278         
 279         unsigned long send_pcb_semaphore;
 280         unsigned int dmaing;
 281         unsigned long busy;
 282 
 283         unsigned int rx_active;  
 284 } elp_device;
 285 
 286 static inline unsigned int backlog_next(unsigned int n)
     
 287 {
 288         return (n + 1) % BACKLOG_SIZE;
 289 }
 290 
 291 
 292 
 293 
 294 
 295 
 296 
 297 
 298 
 299 
 300 
 301 
 302 
 303 #define GET_ASF(addr) \
 304         (get_status(addr)&ASF_PCB_MASK)
 305 
 306 static inline int get_status(unsigned int base_addr)
     
 307 {
 308         int timeout = jiffies + 10;
 309         register int stat1;
 310         do {
 311                 stat1 = inb_status(base_addr);
 312         } while (stat1 != inb_status(base_addr) && jiffies < timeout);
 313         if (jiffies >= timeout)
 314                 TIMEOUT_MSG(__LINE__);
 315         return stat1;
 316 }
 317 
 318 static inline void set_hsf(unsigned int base_addr, int hsf)
     
 319 {
 320         cli();
 321         outb_control((inb_control(base_addr) & ~HSF_PCB_MASK) | hsf, base_addr);
 322         sti();
 323 }
 324 
 325 static int start_receive(struct device *, pcb_struct *);
 326 
 327 inline static void adapter_reset(struct device *dev)
     
 328 {
 329         int timeout;
 330         unsigned char orig_hcr = inb_control(dev->base_addr);
 331 
 332         elp_device *adapter = dev->priv;
 333 
 334         outb_control(0, dev->base_addr);
 335 
 336         if (inb_status(dev->base_addr) & ACRF) {
 337                 do {
 338                         inb_command(dev->base_addr);
 339                         timeout = jiffies + 2;
 340                         while ((jiffies <= timeout) && !(inb_status(dev->base_addr) & ACRF));
 341                 } while (inb_status(dev->base_addr) & ACRF);
 342                 set_hsf(dev->base_addr, HSF_PCB_NAK);
 343         }
 344         outb_control(inb_control(dev->base_addr) | ATTN | DIR, dev->base_addr);
 345         timeout = jiffies + 1;
 346         while (jiffies <= timeout);
 347         outb_control(inb_control(dev->base_addr) & ~ATTN, dev->base_addr);
 348         timeout = jiffies + 1;
 349         while (jiffies <= timeout);
 350         outb_control(inb_control(dev->base_addr) | FLSH, dev->base_addr);
 351         timeout = jiffies + 1;
 352         while (jiffies <= timeout);
 353         outb_control(inb_control(dev->base_addr) & ~FLSH, dev->base_addr);
 354         timeout = jiffies + 1;
 355         while (jiffies <= timeout);
 356 
 357         outb_control(orig_hcr, dev->base_addr);
 358         if (!start_receive(dev, &adapter->tx_pcb))
 359                 printk("%s: start receive command failed \n", dev->name);
 360 }
 361 
 362 
 363 
 364 
 365 
 366 static inline void check_dma(struct device *dev)
     
 367 {
 368         elp_device *adapter = dev->priv;
 369         if (adapter->dmaing && (jiffies > (adapter->current_dma.start_time + 10))) {
 370                 unsigned long flags;
 371                 printk("%s: DMA %s timed out, %d bytes left\n", dev->name, adapter->current_dma.direction ? "download" : "upload", get_dma_residue(dev->dma));
 372                 save_flags(flags);
 373                 cli();
 374                 adapter->dmaing = 0;
 375                 adapter->busy = 0;
 376                 disable_dma(dev->dma);
 377                 if (adapter->rx_active)
 378                         adapter->rx_active--;
 379                 outb_control(inb_control(dev->base_addr) & ~(DMAE | TCEN | DIR), dev->base_addr);
 380                 restore_flags(flags);
 381         }
 382 }
 383 
 384 
 385 static inline unsigned int send_pcb_slow(unsigned int base_addr, unsigned char byte)
     
 386 {
 387         unsigned int timeout;
 388         outb_command(byte, base_addr);
 389         for (timeout = jiffies + 5; jiffies < timeout;) {
 390                 if (inb_status(base_addr) & HCRE)
 391                         return FALSE;
 392         }
 393         printk("3c505: send_pcb_slow timed out\n");
 394         return TRUE;
 395 }
 396 
 397 static inline unsigned int send_pcb_fast(unsigned int base_addr, unsigned char byte)
     
 398 {
 399         unsigned int timeout;
 400         outb_command(byte, base_addr);
 401         for (timeout = 0; timeout < 40000; timeout++) {
 402                 if (inb_status(base_addr) & HCRE)
 403                         return FALSE;
 404         }
 405         printk("3c505: send_pcb_fast timed out\n");
 406         return TRUE;
 407 }
 408 
 409 
 410 static inline void prime_rx(struct device *dev)
     
 411 {
 412         elp_device *adapter = dev->priv;
 413         while (adapter->rx_active < ELP_RX_PCBS && dev->start) {
 414                 if (!start_receive(dev, &adapter->itx_pcb))
 415                         break;
 416         }
 417 }
 418 
 419 
 420 
 421 
 422 
 423 
 424 
 425 
 426 
 427 
 428 
 429 
 430 
 431 
 432 
 433 
 434 
 435 
 436 
 437 
 438 
 439 
 440 
 441 
 442 
 443 static int send_pcb(struct device *dev, pcb_struct * pcb)
     
 444 {
 445         int i;
 446         int timeout;
 447         elp_device *adapter = dev->priv;
 448 
 449         check_dma(dev);
 450 
 451         if (adapter->dmaing && adapter->current_dma.direction == 0)
 452                 return FALSE;
 453 
 454         
 455         if (set_bit(1, &adapter->send_pcb_semaphore)) {
 456                 if (elp_debug >= 3) {
 457                         printk("%s: send_pcb entered while threaded\n", dev->name);
 458                 }
 459                 return FALSE;
 460         }
 461         
 462 
 463 
 464 
 465 
 466         set_hsf(dev->base_addr, 0);
 467 
 468         if (send_pcb_slow(dev->base_addr, pcb->command))
 469                 goto abort;
 470 
 471         cli();
 472 
 473         if (send_pcb_fast(dev->base_addr, pcb->length))
 474                 goto sti_abort;
 475 
 476         for (i = 0; i < pcb->length; i++) {
 477                 if (send_pcb_fast(dev->base_addr, pcb->data.raw[i]))
 478                         goto sti_abort;
 479         }
 480 
 481         outb_control(inb_control(dev->base_addr) | 3, dev->base_addr);  
 482         outb_command(2 + pcb->length, dev->base_addr);
 483 
 484         
 485         sti();
 486 
 487         for (timeout = jiffies + 5; jiffies < timeout;) {
 488                 switch (GET_ASF(dev->base_addr)) {
 489                 case ASF_PCB_ACK:
 490                         adapter->send_pcb_semaphore = 0;
 491                         return TRUE;
 492                         break;
 493                 case ASF_PCB_NAK:
 494                         cli();
 495                         printk("%s: send_pcb got NAK\n", dev->name);
 496                         goto abort;
 497                         break;
 498                 }
 499         }
 500 
 501         if (elp_debug >= 1)
 502                 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev->name, inb_status(dev->base_addr));
 503 
 504       sti_abort:
 505         sti();
 506       abort:
 507         adapter->send_pcb_semaphore = 0;
 508         return FALSE;
 509 }
 510 
 511 
 512 
 513 
 514 
 515 
 516 
 517 
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 static int receive_pcb(struct device *dev, pcb_struct * pcb)
     
 526 {
 527         int i, j;
 528         int total_length;
 529         int stat;
 530         int timeout;
 531 
 532         elp_device *adapter = dev->priv;
 533 
 534         set_hsf(dev->base_addr, 0);
 535 
 536         
 537         timeout = jiffies + 2;
 538         while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout);
 539         if (jiffies >= timeout) {
 540                 TIMEOUT_MSG(__LINE__);
 541                 return FALSE;
 542         }
 543         pcb->command = inb_command(dev->base_addr);
 544 
 545         
 546         timeout = jiffies + 3;
 547         while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout);
 548         if (jiffies >= timeout) {
 549                 TIMEOUT_MSG(__LINE__);
 550                 printk("%s: status %02x\n", dev->name, stat);
 551                 return FALSE;
 552         }
 553         pcb->length = inb_command(dev->base_addr);
 554 
 555         if (pcb->length > MAX_PCB_DATA) {
 556                 INVALID_PCB_MSG(pcb->length);
 557                 adapter_reset(dev);
 558                 return FALSE;
 559         }
 560         
 561         cli();
 562         i = 0;
 563         do {
 564                 j = 0;
 565                 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
 566                 pcb->data.raw[i++] = inb_command(dev->base_addr);
 567                 if (i > MAX_PCB_DATA)
 568                         INVALID_PCB_MSG(i);
 569         } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
 570         sti();
 571         if (j >= 20000) {
 572                 TIMEOUT_MSG(__LINE__);
 573                 return FALSE;
 574         }
 575         
 576         total_length = pcb->data.raw[--i];
 577 
 578         
 579         if (total_length != (pcb->length + 2)) {
 580                 if (elp_debug >= 2)
 581                         printk("%s: mangled PCB received\n", dev->name);
 582                 set_hsf(dev->base_addr, HSF_PCB_NAK);
 583                 return FALSE;
 584         }
 585 
 586         if (pcb->command == CMD_RECEIVE_PACKET_COMPLETE) {
 587                 if (set_bit(0, (void *) &adapter->busy)) {
 588                         if (backlog_next(adapter->rx_backlog.in) == adapter->rx_backlog.out) {
 589                                 set_hsf(dev->base_addr, HSF_PCB_NAK);
 590                                 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev->name);
 591                                 pcb->command = 0;
 592                                 return TRUE;
 593                         } else {
 594                                 pcb->command = 0xff;
 595                         }
 596                 }
 597         }
 598         set_hsf(dev->base_addr, HSF_PCB_ACK);
 599         return TRUE;
 600 }
 601 
 602 
 603 
 604 
 605 
 606 
 607 
 608 
 609 static int start_receive(struct device *dev, pcb_struct * tx_pcb)
     
 610 {
 611         int status;
 612         elp_device *adapter = dev->priv;
 613 
 614         if (elp_debug >= 3)
 615                 printk("%s: restarting receiver\n", dev->name);
 616         tx_pcb->command = CMD_RECEIVE_PACKET;
 617         tx_pcb->length = sizeof(struct Rcv_pkt);
 618         tx_pcb->data.rcv_pkt.buf_seg
 619             = tx_pcb->data.rcv_pkt.buf_ofs = 0;         
 620         tx_pcb->data.rcv_pkt.buf_len = 1600;
 621         tx_pcb->data.rcv_pkt.timeout = 0;       
 622         status = send_pcb(dev, tx_pcb);
 623         if (status)
 624                 adapter->rx_active++;
 625         return status;
 626 }
 627 
 628 
 629 
 630 
 631 
 632 
 633 
 634 
 635 
 636 
 637 static void receive_packet(struct device *dev, int len)
     
 638 {
 639         int rlen;
 640         elp_device *adapter = dev->priv;
 641         unsigned long target;
 642         struct sk_buff *skb;
 643 
 644         rlen = (len + 1) & ~1;
 645         skb = dev_alloc_skb(rlen + 2);
 646 
 647         adapter->current_dma.copy_flag = 0;
 648 
 649         if (!skb) {
 650           printk("%s: memory squeeze, dropping packet\n", dev->name);
 651           target = virt_to_bus(adapter->dma_buffer);
 652         } else {
 653           skb_reserve(skb, 2);
 654           target = virt_to_bus(skb_put(skb, rlen));
 655           if ((target + rlen) >= MAX_DMA_ADDRESS) {
 656             target = virt_to_bus(adapter->dma_buffer);
 657             adapter->current_dma.copy_flag = 1;
 658           }
 659         }
 660         
 661         if (set_bit(0, (void *) &adapter->dmaing))
 662                 printk("%s: rx blocked, DMA in progress, dir %d\n", dev->name, adapter->current_dma.direction);
 663 
 664         adapter->current_dma.direction = 0;
 665         adapter->current_dma.length = rlen;
 666         adapter->current_dma.skb = skb;
 667         adapter->current_dma.start_time = jiffies;
 668 
 669         outb_control(inb_control(dev->base_addr) | DIR | TCEN | DMAE, dev->base_addr);
 670 
 671         disable_dma(dev->dma);
 672         clear_dma_ff(dev->dma);
 673         set_dma_mode(dev->dma, 0x04);   
 674         set_dma_addr(dev->dma, target);
 675         set_dma_count(dev->dma, rlen);
 676         enable_dma(dev->dma);
 677 
 678         if (elp_debug >= 3) {
 679                 printk("%s: rx DMA transfer started\n", dev->name);
 680         }
 681         if (adapter->rx_active)
 682                 adapter->rx_active--;
 683 
 684         if (!adapter->busy)
 685                 printk("%s: receive_packet called, busy not set.\n", dev->name);
 686 }
 687 
 688 
 689 
 690 
 691 
 692 
 693 
 694 static void elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
     
 695 {
 696         int len;
 697         int dlen;
 698         int icount = 0;
 699         struct device *dev;
 700         elp_device *adapter;
 701         int timeout;
 702 
 703         if (irq < 0 || irq > 15) {
 704                 printk("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
 705                 return;
 706         }
 707         dev = irq2dev_map[irq];
 708 
 709         if (dev == NULL) {
 710                 printk("elp_interrupt(): irq %d for unknown device.\n", irq);
 711                 return;
 712         }
 713         adapter = (elp_device *) dev->priv;
 714 
 715         if (dev->interrupt) {
 716                 printk("%s: re-entering the interrupt handler!\n", dev->name);
 717                 return;
 718         }
 719         dev->interrupt = 1;
 720 
 721         do {
 722                 
 723 
 724 
 725                 if (inb_status(dev->base_addr) & DONE) {
 726                         if (!adapter->dmaing) {
 727                                 printk("%s: phantom DMA completed\n", dev->name);
 728                         }
 729                         if (elp_debug >= 3) {
 730                                 printk("%s: %s DMA complete, status %02x\n", dev->name, adapter->current_dma.direction ? "tx" : "rx", inb_status(dev->base_addr));
 731                         }
 732 
 733                         outb_control(inb_control(dev->base_addr) & ~(DMAE | TCEN | DIR), dev->base_addr);
 734                         if (adapter->current_dma.direction) {
 735                                 dev_kfree_skb(adapter->current_dma.skb, FREE_WRITE);
 736                         } else {
 737                                 struct sk_buff *skb = adapter->current_dma.skb;
 738                                 if (skb) {
 739                                   skb->dev = dev;
 740                                   if (adapter->current_dma.copy_flag) {
 741                                     memcpy(skb_put(skb, adapter->current_dma.length), adapter->dma_buffer, adapter->current_dma.length);
 742                                   }
 743                                   skb->protocol = eth_type_trans(skb,dev);
 744                                   netif_rx(skb);
 745                                 }
 746                         }
 747                         adapter->dmaing = 0;
 748                         if (adapter->rx_backlog.in != adapter->rx_backlog.out) {
 749                                 int t = adapter->rx_backlog.length[adapter->rx_backlog.out];
 750                                 adapter->rx_backlog.out = backlog_next(adapter->rx_backlog.out);
 751                                 if (elp_debug >= 2)
 752                                         printk("%s: receiving backlogged packet (%d)\n", dev->name, t);
 753                                 receive_packet(dev, t);
 754                         } else {
 755                                 adapter->busy = 0;
 756                         }
 757                 } else {
 758                         
 759                         check_dma(dev);
 760                 }
 761 
 762                 sti();
 763 
 764                 
 765 
 766 
 767                 timeout = jiffies + 3;
 768                 while ((inb_status(dev->base_addr) & ACRF) != 0 && jiffies < timeout) {
 769                         if (receive_pcb(dev, &adapter->irx_pcb)) {
 770                                 switch (adapter->irx_pcb.command) {
 771                                 case 0:
 772                                         break;
 773                                         
 774 
 775 
 776                                 case 0xff:
 777                                 case CMD_RECEIVE_PACKET_COMPLETE:
 778                                         
 779                                         if (dev->start == 0)
 780                                                 break;
 781                                         cli();
 782                                         len = adapter->irx_pcb.data.rcv_resp.pkt_len;
 783                                         dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
 784                                         if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
 785                                                 printk("%s: interrupt - packet not received correctly\n", dev->name);
 786                                                 sti();
 787                                         } else {
 788                                                 if (elp_debug >= 3) {
 789                                                         sti();
 790                                                         printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
 791                                                         cli();
 792                                                 }
 793                                                 if (adapter->irx_pcb.command == 0xff) {
 794                                                         if (elp_debug >= 2)
 795                                                                 printk("%s: adding packet to backlog (len = %d)\n", dev->name, dlen);
 796                                                         adapter->rx_backlog.length[adapter->rx_backlog.in] = dlen;
 797                                                         adapter->rx_backlog.in = backlog_next(adapter->rx_backlog.in);
 798                                                 } else {
 799                                                         receive_packet(dev, dlen);
 800                                                 }
 801                                                 sti();
 802                                                 if (elp_debug >= 3)
 803                                                         printk("%s: packet received\n", dev->name);
 804                                         }
 805                                         break;
 806 
 807                                         
 808 
 809 
 810                                 case CMD_CONFIGURE_82586_RESPONSE:
 811                                         adapter->got[CMD_CONFIGURE_82586] = 1;
 812                                         if (elp_debug >= 3)
 813                                                 printk("%s: interrupt - configure response received\n", dev->name);
 814                                         break;
 815 
 816                                         
 817 
 818 
 819                                 case CMD_CONFIGURE_ADAPTER_RESPONSE:
 820                                         adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
 821                                         if (elp_debug >= 3)
 822                                                 printk("%s: Adapter memory configuration %s.\n", dev->name,
 823                                                        adapter->irx_pcb.data.failed ? "failed" : "succeeded");
 824                                         break;
 825 
 826                                         
 827 
 828 
 829                                 case CMD_LOAD_MULTICAST_RESPONSE:
 830                                         adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
 831                                         if (elp_debug >= 3)
 832                                                 printk("%s: Multicast address list loading %s.\n", dev->name,
 833                                                        adapter->irx_pcb.data.failed ? "failed" : "succeeded");
 834                                         break;
 835 
 836                                         
 837 
 838 
 839                                 case CMD_SET_ADDRESS_RESPONSE:
 840                                         adapter->got[CMD_SET_STATION_ADDRESS] = 1;
 841                                         if (elp_debug >= 3)
 842                                                 printk("%s: Ethernet address setting %s.\n", dev->name,
 843                                                        adapter->irx_pcb.data.failed ? "failed" : "succeeded");
 844                                         break;
 845 
 846 
 847                                         
 848 
 849 
 850                                 case CMD_NETWORK_STATISTICS_RESPONSE:
 851                                         adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
 852                                         adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
 853                                         adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
 854                                         adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
 855                                         adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
 856                                         adapter->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
 857                                         adapter->got[CMD_NETWORK_STATISTICS] = 1;
 858                                         if (elp_debug >= 3)
 859                                                 printk("%s: interrupt - statistics response received\n", dev->name);
 860                                         break;
 861 
 862                                         
 863 
 864 
 865                                 case CMD_TRANSMIT_PACKET_COMPLETE:
 866                                         if (elp_debug >= 3)
 867                                                 printk("%s: interrupt - packet sent\n", dev->name);
 868                                         if (dev->start == 0)
 869                                                 break;
 870                                         switch (adapter->irx_pcb.data.xmit_resp.c_stat) {
 871                                         case 0xffff:
 872                                                 adapter->stats.tx_aborted_errors++;
 873                                                 printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name);
 874                                                 break;
 875                                         case 0xfffe:
 876                                                 adapter->stats.tx_fifo_errors++;
 877                                                 printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name);
 878                                                 break;
 879                                         }
 880                                         dev->tbusy = 0;
 881                                         mark_bh(NET_BH);
 882                                         break;
 883 
 884                                         
 885 
 886 
 887                                 default:
 888                                         printk(KERN_DEBUG "%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
 889                                         break;
 890                                 }
 891                         } else {
 892                                 printk("%s: failed to read PCB on interrupt\n", dev->name);
 893                                 adapter_reset(dev);
 894                         }
 895                 }
 896 
 897         } while (icount++ < 5 && (inb_status(dev->base_addr) & (ACRF | DONE)));
 898 
 899         prime_rx(dev);
 900 
 901         
 902 
 903 
 904         dev->interrupt = 0;
 905 }
 906 
 907 
 908 
 909 
 910 
 911 
 912 
 913 
 914 static int elp_open(struct device *dev)
     
 915 {
 916         elp_device *adapter;
 917 
 918         adapter = dev->priv;
 919 
 920         if (elp_debug >= 3)
 921                 printk("%s: request to open device\n", dev->name);
 922 
 923         
 924 
 925 
 926         if (adapter == NULL) {
 927                 printk("%s: Opening a non-existent physical device\n", dev->name);
 928                 return -EAGAIN;
 929         }
 930         
 931 
 932 
 933         outb_control(0x00, dev->base_addr);
 934 
 935         
 936 
 937 
 938         inb_command(dev->base_addr);
 939         adapter_reset(dev);
 940 
 941         
 942 
 943 
 944         dev->interrupt = 0;
 945 
 946         
 947 
 948 
 949         dev->tbusy = 0;
 950 
 951         
 952 
 953 
 954         adapter->rx_active = 0;
 955 
 956         adapter->busy = 0;
 957         adapter->send_pcb_semaphore = 0;
 958         adapter->rx_backlog.in = 0;
 959         adapter->rx_backlog.out = 0;
 960 
 961         
 962 
 963 
 964         irq2dev_map[dev->irq] = dev;
 965 
 966         
 967 
 968 
 969         if (request_irq(dev->irq, &elp_interrupt, 0, "3c505", NULL)) {
 970                 irq2dev_map[dev->irq] = NULL;
 971                 return -EAGAIN;
 972         }
 973         if (request_dma(dev->dma, "3c505")) {
 974                 printk("%s: could not allocate DMA channel\n", dev->name);
 975                 return -EAGAIN;
 976         }
 977         adapter->dma_buffer = (void *) dma_mem_alloc(DMA_BUFFER_SIZE);
 978         if (!adapter->dma_buffer) {
 979                 printk("Could not allocate DMA buffer\n");
 980         }
 981         adapter->dmaing = 0;
 982 
 983         
 984 
 985 
 986         outb_control(CMDE, dev->base_addr);
 987 
 988         
 989 
 990 
 991         dev->start = 1;
 992 
 993         
 994 
 995 
 996         if (elp_debug >= 3)
 997                 printk("%s: sending 3c505 memory configuration command\n", dev->name);
 998         adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
 999         adapter->tx_pcb.data.memconf.cmd_q = 10;
1000         adapter->tx_pcb.data.memconf.rcv_q = 20;
1001         adapter->tx_pcb.data.memconf.mcast = 10;
1002         adapter->tx_pcb.data.memconf.frame = 20;
1003         adapter->tx_pcb.data.memconf.rcv_b = 20;
1004         adapter->tx_pcb.data.memconf.progs = 0;
1005         adapter->tx_pcb.length = sizeof(struct Memconf);
1006         adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
1007         if (!send_pcb(dev, &adapter->tx_pcb))
1008                 printk("%s: couldn't send memory configuration command\n", dev->name);
1009         else {
1010                 int timeout = jiffies + TIMEOUT;
1011                 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout);
1012                 if (jiffies >= timeout)
1013                         TIMEOUT_MSG(__LINE__);
1014         }
1015 
1016 
1017         
1018 
1019 
1020         if (elp_debug >= 3)
1021                 printk("%s: sending 82586 configure command\n", dev->name);
1022         adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1023         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1024         adapter->tx_pcb.length = 2;
1025         adapter->got[CMD_CONFIGURE_82586] = 0;
1026         if (!send_pcb(dev, &adapter->tx_pcb))
1027                 printk("%s: couldn't send 82586 configure command\n", dev->name);
1028         else {
1029                 int timeout = jiffies + TIMEOUT;
1030                 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout);
1031                 if (jiffies >= timeout)
1032                         TIMEOUT_MSG(__LINE__);
1033         }
1034 
1035         
1036         outb(0x1, dev->base_addr + PORT_AUXDMA);
1037 
1038         
1039 
1040 
1041         prime_rx(dev);
1042         if (elp_debug >= 3)
1043                 printk("%s: %d receive PCBs active\n", dev->name, adapter->rx_active);
1044 
1045         MOD_INC_USE_COUNT;
1046 
1047         return 0;               
1048 }
1049 
1050 
1051 
1052 
1053 
1054 
1055 
1056 
1057 static int send_packet(struct device *dev, struct sk_buff *skb)
     
1058 {
1059         elp_device *adapter = dev->priv;
1060         unsigned long target;
1061 
1062         
1063 
1064 
1065         unsigned int nlen = (((skb->len < 60) ? 60 : skb->len) + 1) & (~1);
1066 
1067         if (set_bit(0, (void *) &adapter->busy)) {
1068                 if (elp_debug >= 2)
1069                         printk("%s: transmit blocked\n", dev->name);
1070                 return FALSE;
1071         }
1072         adapter = dev->priv;
1073 
1074         
1075 
1076 
1077 
1078         adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
1079         adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
1080         adapter->tx_pcb.data.xmit_pkt.buf_ofs
1081             = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;        
1082         adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
1083 
1084         if (!send_pcb(dev, &adapter->tx_pcb)) {
1085                 adapter->busy = 0;
1086                 return FALSE;
1087         }
1088         
1089         if (set_bit(0, (void *) &adapter->dmaing))
1090                 printk("%s: tx: DMA %d in progress\n", dev->name, adapter->current_dma.direction);
1091 
1092         adapter->current_dma.direction = 1;
1093         adapter->current_dma.start_time = jiffies;
1094 
1095         target = virt_to_bus(skb->data);
1096         if ((target + nlen) >= MAX_DMA_ADDRESS) {
1097                 memcpy(adapter->dma_buffer, skb->data, nlen);
1098                 target = virt_to_bus(adapter->dma_buffer);
1099         }
1100         adapter->current_dma.skb = skb;
1101         cli();
1102         disable_dma(dev->dma);
1103         clear_dma_ff(dev->dma);
1104         set_dma_mode(dev->dma, 0x08);   
1105         set_dma_addr(dev->dma, target);
1106         set_dma_count(dev->dma, nlen);
1107         enable_dma(dev->dma);
1108         outb_control(inb_control(dev->base_addr) | DMAE | TCEN, dev->base_addr);
1109         if (elp_debug >= 3)
1110                 printk("%s: DMA transfer started\n", dev->name);
1111 
1112         return TRUE;
1113 }
1114 
1115 
1116 
1117 
1118 
1119 
1120 
1121 
1122 static int elp_start_xmit(struct sk_buff *skb, struct device *dev)
     
1123 {
1124         if (dev->interrupt) {
1125                 printk("%s: start_xmit aborted (in irq)\n", dev->name);
1126                 return 1;
1127         }
1128 
1129         check_dma(dev);
1130 
1131         
1132 
1133 
1134         if (dev->tbusy) {
1135                 elp_device *adapter = dev->priv;
1136                 int tickssofar = jiffies - dev->trans_start;
1137                 int stat;
1138 
1139                 if (tickssofar < 1000)
1140                         return 1;
1141 
1142                 stat = inb_status(dev->base_addr);
1143                 printk("%s: transmit timed out, lost %s?\n", dev->name, (stat & ACRF) ? "interrupt" : "command");
1144                 if (elp_debug >= 1)
1145                         printk("%s: status %#02x\n", dev->name, stat);
1146                 dev->trans_start = jiffies;
1147                 dev->tbusy = 0;
1148                 adapter->stats.tx_dropped++;
1149         }
1150 
1151         
1152         if (skb == NULL) {
1153                 dev_tint(dev);
1154                 return 0;
1155         }
1156 
1157         if (skb->len <= 0)
1158                 return 0;
1159 
1160         if (elp_debug >= 3)
1161                 printk("%s: request to send packet of length %d\n", dev->name, (int) skb->len);
1162 
1163         if (set_bit(0, (void *) &dev->tbusy)) {
1164                 printk("%s: transmitter access conflict\n", dev->name);
1165                 return 1;
1166         }
1167         
1168 
1169 
1170         if (!send_packet(dev, skb)) {
1171                 if (elp_debug >= 2) {
1172                         printk("%s: failed to transmit packet\n", dev->name);
1173                 }
1174                 dev->tbusy = 0;
1175                 return 1;
1176         }
1177         if (elp_debug >= 3)
1178                 printk("%s: packet of length %d sent\n", dev->name, (int) skb->len);
1179 
1180         
1181 
1182 
1183         dev->trans_start = jiffies;
1184 
1185         prime_rx(dev);
1186 
1187         return 0;
1188 }
1189 
1190 
1191 
1192 
1193 
1194 
1195 
1196 static struct enet_statistics *elp_get_stats(struct device *dev)
     
1197 {
1198         elp_device *adapter = (elp_device *) dev->priv;
1199 
1200         if (elp_debug >= 3)
1201                 printk("%s: request for stats\n", dev->name);
1202 
1203         
1204 
1205         if (!dev->start)
1206                 return &adapter->stats;
1207 
1208         
1209         adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1210         adapter->tx_pcb.length = 0;
1211         adapter->got[CMD_NETWORK_STATISTICS] = 0;
1212         if (!send_pcb(dev, &adapter->tx_pcb))
1213                 printk("%s: couldn't send get statistics command\n", dev->name);
1214         else {
1215                 int timeout = jiffies + TIMEOUT;
1216                 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout);
1217                 if (jiffies >= timeout) {
1218                         TIMEOUT_MSG(__LINE__);
1219                         return &adapter->stats;
1220                 }
1221         }
1222 
1223         
1224         return &adapter->stats;
1225 }
1226 
1227 
1228 
1229 
1230 
1231 
1232 
1233 static int elp_close(struct device *dev)
     
1234 {
1235         elp_device *adapter;
1236 
1237         adapter = dev->priv;
1238 
1239         if (elp_debug >= 3)
1240                 printk("%s: request to close device\n", dev->name);
1241 
1242         
1243 
1244 
1245 
1246         (void) elp_get_stats(dev);
1247 
1248         
1249 
1250 
1251         outb_control(0x00, dev->base_addr);
1252 
1253         
1254 
1255 
1256         dev->tbusy = 1;
1257 
1258         
1259 
1260 
1261         dev->start = 0;
1262 
1263         
1264 
1265 
1266         free_irq(dev->irq, NULL);
1267 
1268         
1269 
1270 
1271         irq2dev_map[dev->irq] = 0;
1272 
1273         free_dma(dev->dma);
1274         free_pages((unsigned long) adapter->dma_buffer, __get_order(DMA_BUFFER_SIZE));
1275 
1276         MOD_DEC_USE_COUNT;
1277 
1278         return 0;
1279 }
1280 
1281 
1282 
1283 
1284 
1285 
1286 
1287 
1288 
1289 
1290 
1291 static void elp_set_mc_list(struct device *dev)
     
1292 {
1293         elp_device *adapter = (elp_device *) dev->priv;
1294         struct dev_mc_list *dmi = dev->mc_list;
1295         int i;
1296 
1297         if (elp_debug >= 3)
1298                 printk("%s: request to set multicast list\n", dev->name);
1299 
1300         if (!(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1301                 
1302                 
1303                 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1304                 adapter->tx_pcb.length = 6 * dev->mc_count;
1305                 for (i = 0; i < dev->mc_count; i++) {
1306                         memcpy(adapter->tx_pcb.data.multicast[i], dmi->dmi_addr, 6);
1307                         dmi = dmi->next;
1308                 }
1309                 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1310                 if (!send_pcb(dev, &adapter->tx_pcb))
1311                         printk("%s: couldn't send set_multicast command\n", dev->name);
1312                 else {
1313                         int timeout = jiffies + TIMEOUT;
1314                         while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout);
1315                         if (jiffies >= timeout) {
1316                                 TIMEOUT_MSG(__LINE__);
1317                         }
1318                 }
1319                 if (dev->mc_count)
1320                         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1321                 else            
1322                         adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1323         } else
1324                 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1325         
1326 
1327 
1328 
1329         if (elp_debug >= 3)
1330                 printk("%s: sending 82586 configure command\n", dev->name);
1331         adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1332         adapter->tx_pcb.length = 2;
1333         adapter->got[CMD_CONFIGURE_82586] = 0;
1334         if (!send_pcb(dev, &adapter->tx_pcb))
1335                 printk("%s: couldn't send 82586 configure command\n", dev->name);
1336         else {
1337                 int timeout = jiffies + TIMEOUT;
1338                 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout);
1339                 if (jiffies >= timeout)
1340                         TIMEOUT_MSG(__LINE__);
1341         }
1342 }
1343 
1344 
1345 
1346 
1347 
1348 
1349 
1350 static void elp_init(struct device *dev)
     
1351 {
1352         elp_device *adapter = dev->priv;
1353 
1354         
1355 
1356 
1357         dev->open = elp_open;   
1358         dev->stop = elp_close;  
1359         dev->get_stats = elp_get_stats;         
1360         dev->hard_start_xmit = elp_start_xmit;  
1361         dev->set_multicast_list = elp_set_mc_list;      
1362 
1363         
1364         ether_setup(dev);
1365 
1366         
1367 
1368 
1369         memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1370 
1371         
1372 
1373 
1374         dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1375 }
1376 
1377 
1378 
1379 
1380 
1381 
1382 
1383 static int elp_sense(struct device *dev)
     
1384 {
1385         int timeout;
1386         int addr = dev->base_addr;
1387         const char *name = dev->name;
1388         long flags;
1389         byte orig_HCR, orig_HSR;
1390 
1391         if (check_region(addr, 0xf))
1392                 return -1;
1393 
1394         orig_HCR = inb_control(addr);
1395         orig_HSR = inb_status(addr);
1396 
1397         if (elp_debug > 0)
1398                 printk(search_msg, name, addr);
1399 
1400         if (((orig_HCR == 0xff) && (orig_HSR == 0xff)) ||
1401             ((orig_HCR & DIR) != (orig_HSR & DIR))) {
1402                 if (elp_debug > 0)
1403                         printk(notfound_msg, 1);
1404                 return -1;      
1405         }
1406         
1407         save_flags(flags);
1408         sti();
1409 
1410         
1411         if (elp_debug > 0)
1412                 printk(stilllooking_msg);
1413         if (orig_HCR & DIR) {
1414                 
1415                 outb_control(orig_HCR & ~DIR, addr);
1416                 timeout = jiffies + 30;
1417                 while (jiffies < timeout);
1418                 restore_flags(flags);
1419                 if (inb_status(addr) & DIR) {
1420                         outb_control(orig_HCR, addr);
1421                         if (elp_debug > 0)
1422                                 printk(notfound_msg, 2);
1423                         return -1;
1424                 }
1425         } else {
1426                 
1427                 outb_control(orig_HCR | DIR, addr);
1428                 timeout = jiffies + 30;
1429                 while (jiffies < timeout);
1430                 restore_flags(flags);
1431                 if (!(inb_status(addr) & DIR)) {
1432                         outb_control(orig_HCR, addr);
1433                         if (elp_debug > 0)
1434                                 printk(notfound_msg, 3);
1435                         return -1;
1436                 }
1437         }
1438         
1439 
1440 
1441 
1442         if (elp_debug > 0)
1443                 printk(found_msg);
1444 
1445         return 0;
1446 }
1447 
1448 
1449 
1450 
1451 
1452 
1453 
1454 static int elp_autodetect(struct device *dev)
     
1455 {
1456         int idx = 0;
1457 
1458         
1459 
1460         if (dev->base_addr != 0) {      
1461                 if (elp_sense(dev) == 0)
1462                         return dev->base_addr;
1463         } else
1464                 while ((dev->base_addr = addr_list[idx++])) {
1465                         if (elp_sense(dev) == 0)
1466                                 return dev->base_addr;
1467                 }
1468 
1469         
1470         if (elp_debug > 0)
1471                 printk(couldnot_msg, dev->name);
1472 
1473         return 0;               
1474 }
1475 
1476 
1477 
1478 
1479 
1480 
1481 
1482 
1483 
1484 
1485 
1486 
1487 
1488 
1489 
1490 
1491 
1492 
1493 
1494 
1495 
1496 
1497 
1498 int elplus_probe(struct device *dev)
     
1499 {
1500         elp_device *adapter;
1501         int i, tries, tries1, timeout, okay;
1502 
1503         
1504 
1505 
1506 
1507         dev->base_addr = elp_autodetect(dev);
1508         if (!(dev->base_addr))
1509                 return -ENODEV;
1510 
1511         
1512 
1513 
1514         adapter = (elp_device *) (dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1515         if (adapter == NULL) {
1516                 printk("%s: out of memory\n", dev->name);
1517                 return -ENODEV;
1518         }
1519 
1520         for (tries1 = 0; tries1 < 3; tries1++) {
1521                 outb_control((inb_control(dev->base_addr) | CMDE) & ~DIR, dev->base_addr);
1522                 
1523 
1524 
1525                 timeout = jiffies + 5;
1526                 okay = 0;
1527                 while (jiffies < timeout && !(inb_status(dev->base_addr) & HCRE));
1528                 if ((inb_status(dev->base_addr) & HCRE)) {
1529                         outb_command(0, dev->base_addr);        
1530                         timeout = jiffies + 5;
1531                         while (jiffies < timeout && !(inb_status(dev->base_addr) & HCRE));
1532                         if (inb_status(dev->base_addr) & HCRE)
1533                                 okay = 1;
1534                 }
1535                 if (!okay) {
1536                         
1537 
1538 
1539                         printk("%s: command register wouldn't drain, ", dev->name);
1540                         if ((inb_status(dev->base_addr) & 7) == 3) {
1541                                 
1542 
1543 
1544                                 printk("assuming 3c505 still starting\n");
1545                                 timeout = jiffies + 10 * HZ;
1546                                 while (jiffies < timeout && (inb_status(dev->base_addr) & 7));
1547                                 if (inb_status(dev->base_addr) & 7) {
1548                                         printk("%s: 3c505 failed to start\n", dev->name);
1549                                 } else {
1550                                         okay = 1;  
1551                                 }
1552                         } else {
1553                                 
1554 
1555 
1556                                 printk("3c505 is sulking\n");
1557                         }
1558                 }
1559                 for (tries = 0; tries < 5 && okay; tries++) {
1560 
1561                         
1562 
1563 
1564 
1565                         adapter->tx_pcb.command = CMD_STATION_ADDRESS;
1566                         adapter->tx_pcb.length = 0;
1567                         autoirq_setup(0);
1568                         if (!send_pcb(dev, &adapter->tx_pcb)) {
1569                                 printk("%s: could not send first PCB\n", dev->name);
1570                                 autoirq_report(0);
1571                                 continue;
1572                         }
1573                         if (!receive_pcb(dev, &adapter->rx_pcb)) {
1574                                 printk("%s: could not read first PCB\n", dev->name);
1575                                 autoirq_report(0);
1576                                 continue;
1577                         }
1578                         if ((adapter->rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1579                             (adapter->rx_pcb.length != 6)) {
1580                                 printk("%s: first PCB wrong (%d, %d)\n", dev->name, adapter->rx_pcb.command, adapter->rx_pcb.length);
1581                                 autoirq_report(0);
1582                                 continue;
1583                         }
1584                         goto okay;
1585                 }
1586                 
1587 
1588 
1589                 printk(KERN_INFO "%s: resetting adapter\n", dev->name);
1590                 outb_control(inb_control(dev->base_addr) | FLSH | ATTN, dev->base_addr);
1591                 outb_control(inb_control(dev->base_addr) & ~(FLSH | ATTN), dev->base_addr);
1592         }
1593         printk("%s: failed to initialise 3c505\n", dev->name);
1594         return -ENODEV;
1595 
1596       okay:
1597         if (dev->irq) {         
1598                 int rpt = autoirq_report(0);
1599                 if (dev->irq != rpt) {
1600                         printk("%s: warning, irq %d configured but %d detected\n", dev->name, dev->irq, rpt);
1601                         return -ENODEV;
1602                 }
1603                 
1604         } else                  
1605                 dev->irq = autoirq_report(0);
1606         switch (dev->irq) {     
1607         case 0:
1608                 printk("%s: No IRQ reported by autoirq_report().\n", dev->name);
1609                 printk("%s: Check the jumpers of your 3c505 board.\n", dev->name);
1610                 return -ENODEV;
1611         case 1:
1612         case 6:
1613         case 8:
1614         case 13:
1615                 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1616                        dev->name, dev->irq);
1617                 return -ENODEV;
1618         }
1619         
1620 
1621 
1622 
1623         outb_control(inb_control(dev->base_addr) & ~CMDE, dev->base_addr);
1624 
1625         
1626 
1627 
1628         for (i = 0; i < 6; i++)
1629                 dev->dev_addr[i] = adapter->rx_pcb.data.eth_addr[i];
1630 
1631         
1632         dev->dma = ELP_DMA;
1633 
1634         
1635 
1636 
1637         printk("%s: 3c505 at %#lx, irq %d, dma %d, ",
1638                dev->name, dev->base_addr, dev->irq, dev->dma);
1639         printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1640                dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1641                dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1642 
1643         
1644 
1645 
1646 
1647         adapter->tx_pcb.command = CMD_ADAPTER_INFO;
1648         adapter->tx_pcb.length = 0;
1649         if (!send_pcb(dev, &adapter->tx_pcb) ||
1650             !receive_pcb(dev, &adapter->rx_pcb) ||
1651             (adapter->rx_pcb.command != CMD_ADAPTER_INFO_RESPONSE) ||
1652             (adapter->rx_pcb.length != 10)) {
1653                 printk("%s: not responding to second PCB\n", dev->name);
1654         }
1655         printk("rev %d.%d, %dk\n", adapter->rx_pcb.data.info.major_vers, adapter->rx_pcb.data.info.minor_vers, adapter->rx_pcb.data.info.RAM_sz);
1656 
1657         
1658 
1659 
1660         adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
1661         adapter->tx_pcb.length = 12;
1662         adapter->tx_pcb.data.memconf.cmd_q = 8;
1663         adapter->tx_pcb.data.memconf.rcv_q = 8;
1664         adapter->tx_pcb.data.memconf.mcast = 10;
1665         adapter->tx_pcb.data.memconf.frame = 10;
1666         adapter->tx_pcb.data.memconf.rcv_b = 10;
1667         adapter->tx_pcb.data.memconf.progs = 0;
1668         if (!send_pcb(dev, &adapter->tx_pcb) ||
1669             !receive_pcb(dev, &adapter->rx_pcb) ||
1670             (adapter->rx_pcb.command != CMD_CONFIGURE_ADAPTER_RESPONSE) ||
1671             (adapter->rx_pcb.length != 2)) {
1672                 printk("%s: could not configure adapter memory\n", dev->name);
1673         }
1674         if (adapter->rx_pcb.data.configure) {
1675                 printk("%s: adapter configuration failed\n", dev->name);
1676         }
1677         
1678 
1679 
1680         request_region(dev->base_addr, ELP_IO_EXTENT, "3c505");
1681 
1682         
1683 
1684 
1685         elp_init(dev);
1686 
1687         return 0;
1688 }
1689 
1690 #ifdef MODULE
1691 static char devicename[9] = {0,};
1692 static struct device dev_3c505 =
1693 {
1694         devicename,             
1695         0, 0, 0, 0,
1696         0, 0,
1697         0, 0, 0, NULL, elplus_probe};
1698 
1699 int io = 0x300;
1700 int irq = 0;
1701 
1702 int init_module(void)
     
1703 {
1704         if (io == 0)
1705                 printk("3c505: You should not use auto-probing with insmod!\n");
1706         dev_3c505.base_addr = io;
1707         dev_3c505.irq = irq;
1708         if (register_netdev(&dev_3c505) != 0) {
1709                 return -EIO;
1710         }
1711         return 0;
1712 }
1713 
1714 void cleanup_module(void)
     
1715 {
1716         unregister_netdev(&dev_3c505);
1717         kfree(dev_3c505.priv);
1718         dev_3c505.priv = NULL;
1719 
1720         
1721         release_region(dev_3c505.base_addr, ELP_IO_EXTENT);
1722 }
1723 
1724 #endif                          
1725 
1726 
1727 
1728 
1729 
1730 
1731 
1732 
1733