This source file includes following definitions.
- el2_probe
 
- el2_pio_probe
 
- el2_probe1
 
- el2_open
 
- el2_close
 
- el2_reset_8390
 
- el2_init_card
 
- el2_block_output
 
- el2_get_8390_hdr
 
- el2_block_input
 
- 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 static const char *version =
  33     "3c503.c:v1.10 9/23/93  Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  34 
  35 #include <linux/module.h>
  36 
  37 #include <linux/kernel.h>
  38 #include <linux/sched.h>
  39 #include <linux/errno.h>
  40 #include <linux/string.h>
  41 #include <linux/delay.h>
  42 #include <linux/netdevice.h>
  43 #include <linux/etherdevice.h>
  44 
  45 #include <asm/io.h>
  46 #include <asm/system.h>
  47 
  48 #include "8390.h"
  49 #include "3c503.h"
  50 
  51 
  52 int el2_probe(struct device *dev);
  53 int el2_pio_probe(struct device *dev);
  54 int el2_probe1(struct device *dev, int ioaddr);
  55 
  56 
  57 static unsigned int netcard_portlist[] =
  58         { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
  59 
  60 #define EL2_IO_EXTENT   16
  61 
  62 #ifdef HAVE_DEVLIST
  63 
  64 
  65 struct netdev_entry el2_drv =
  66 {"3c503", el2_probe, EL1_IO_EXTENT, 0};
  67 struct netdev_entry el2pio_drv =
  68 {"3c503pio", el2_pioprobe1, EL1_IO_EXTENT, netcard_portlist};
  69 #endif
  70 
  71 static int el2_open(struct device *dev);
  72 static int el2_close(struct device *dev);
  73 static void el2_reset_8390(struct device *dev);
  74 static void el2_init_card(struct device *dev);
  75 static void el2_block_output(struct device *dev, int count,
  76                              const unsigned char *buf, const start_page);
  77 static void el2_block_input(struct device *dev, int count, struct sk_buff *skb,
  78                            int ring_offset);
  79 static void el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
  80                          int ring_page);
  81 
  82 
  83 
  84 
  85 
  86 
  87 
  88 
  89 
  90 int
  91 el2_probe(struct device *dev)
     
  92 {
  93     int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
  94     int base_addr = dev->base_addr;
  95 
  96     if (base_addr > 0x1ff)      
  97         return el2_probe1(dev, base_addr);
  98     else if (base_addr != 0)            
  99         return ENXIO;
 100 
 101     for (addr = addrs; *addr; addr++) {
 102         int i;
 103         unsigned int base_bits = readb(*addr);
 104         
 105         for(i = 7; i >= 0; i--, base_bits >>= 1)
 106             if (base_bits & 0x1)
 107                 break;
 108         if (base_bits != 1)
 109             continue;
 110         if (check_region(netcard_portlist[i], EL2_IO_EXTENT))
 111             continue;
 112         if (el2_probe1(dev, netcard_portlist[i]) == 0)
 113             return 0;
 114     }
 115 #if ! defined(no_probe_nonshared_memory) && ! defined (HAVE_DEVLIST)
 116     return el2_pio_probe(dev);
 117 #else
 118     return ENODEV;
 119 #endif
 120 }
 121 
 122 #ifndef HAVE_DEVLIST
 123 
 124 
 125 int
 126 el2_pio_probe(struct device *dev)
     
 127 {
 128     int i;
 129     int base_addr = dev ? dev->base_addr : 0;
 130 
 131     if (base_addr > 0x1ff)      
 132         return el2_probe1(dev, base_addr);
 133     else if (base_addr != 0)    
 134         return ENXIO;
 135 
 136     for (i = 0; netcard_portlist[i]; i++) {
 137         int ioaddr = netcard_portlist[i];
 138         if (check_region(ioaddr, EL2_IO_EXTENT))
 139             continue;
 140         if (el2_probe1(dev, ioaddr) == 0)
 141             return 0;
 142     }
 143 
 144     return ENODEV;
 145 }
 146 #endif
 147 
 148 
 149 
 150 
 151 int
 152 el2_probe1(struct device *dev, int ioaddr)
     
 153 {
 154     int i, iobase_reg, membase_reg, saved_406, wordlength;
 155     static unsigned version_printed = 0;
 156     unsigned long vendor_id;
 157 
 158     
 159     if (inb(ioaddr + 0x408) == 0xff) {
 160         udelay(1000);
 161         return ENODEV;
 162     }
 163 
 164     
 165 
 166     iobase_reg = inb(ioaddr+0x403);
 167     membase_reg = inb(ioaddr+0x404);
 168     
 169     if (   (iobase_reg  & (iobase_reg - 1))
 170         || (membase_reg & (membase_reg - 1))) {
 171         return ENODEV;
 172     }
 173     saved_406 = inb_p(ioaddr + 0x406);
 174     outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); 
 175     outb_p(ECNTRL_THIN, ioaddr + 0x406);
 176     
 177 
 178     outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
 179     vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
 180     if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
 181         
 182         outb(saved_406, ioaddr + 0x406);
 183         return ENODEV;
 184     }
 185 
 186     
 187     if (dev == NULL) {
 188         printk("3c503.c: Passed a NULL device.\n");
 189         dev = init_etherdev(0, 0);
 190     }
 191 
 192     if (ei_debug  &&  version_printed++ == 0)
 193         printk(version);
 194 
 195     dev->base_addr = ioaddr;
 196 
 197     
 198     if (ethdev_init(dev)) {
 199         printk ("3c503: unable to allocate memory for dev->priv.\n");
 200         return -ENOMEM;
 201      }
 202 
 203     printk("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr);
 204 
 205     
 206     for (i = 0; i < 6; i++)
 207         printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
 208 
 209     
 210     outb(ECNTRL_THIN, ioaddr + 0x406);
 211 
 212     
 213     outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
 214     outb_p(0, ioaddr + EN0_DCFG);
 215     outb_p(E8390_PAGE2, ioaddr + E8390_CMD);
 216     wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS;
 217     outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
 218 
 219     
 220     if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg);
 221     outb(EGACFR_NORM, ioaddr + 0x405);  
 222 
 223     
 224 
 225 
 226 
 227 #if defined(EI8390_THICK) || defined(EL2_AUI)
 228     ei_status.interface_num = 1;
 229 #else
 230     ei_status.interface_num = dev->mem_end & 0xf;
 231 #endif
 232     printk(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex");
 233 
 234     if ((membase_reg & 0xf0) == 0) {
 235         dev->mem_start = 0;
 236         ei_status.name = "3c503-PIO";
 237     } else {
 238         dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
 239             ((membase_reg & 0xA0) ? 0x4000 : 0);
 240 
 241 #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256
 242 #ifdef EL2MEMTEST
 243         
 244 
 245 
 246         {                       
 247             unsigned long mem_base = dev->mem_start;
 248             unsigned int test_val = 0xbbadf00d;
 249             writel(0xba5eba5e, mem_base);
 250             for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
 251                 writel(test_val, mem_base + i);
 252                 if (readl(mem_base) != 0xba5eba5e
 253                     || readl(mem_base + i) != test_val) {
 254                     printk("3c503.c: memory failure or memory address conflict.\n");
 255                     dev->mem_start = 0;
 256                     ei_status.name = "3c503-PIO";
 257                     break;
 258                 }
 259                 test_val += 0x55555555;
 260                 writel(0, mem_base + i);
 261             }
 262         }
 263 #endif  
 264 
 265         dev->mem_end = dev->rmem_end = dev->mem_start + EL2_MEMSIZE;
 266 
 267         if (wordlength) {       
 268                 dev->rmem_start = dev->mem_start;
 269                 ei_status.name = "3c503/16";
 270         } else {
 271                 dev->rmem_start = TX_PAGES*256 + dev->mem_start;
 272                 ei_status.name = "3c503";
 273         }
 274     }
 275 
 276     
 277 
 278 
 279 
 280 
 281 
 282 
 283 
 284     if (wordlength) {
 285         ei_status.tx_start_page = EL2_MB0_START_PG;
 286         ei_status.rx_start_page = EL2_MB1_START_PG;
 287     } else {
 288         ei_status.tx_start_page = EL2_MB1_START_PG;
 289         ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
 290     }
 291 
 292     
 293     ei_status.stop_page = EL2_MB1_STOP_PG;
 294     ei_status.word16 = wordlength;
 295     ei_status.reset_8390 = &el2_reset_8390;
 296     ei_status.get_8390_hdr = &el2_get_8390_hdr;
 297     ei_status.block_input = &el2_block_input;
 298     ei_status.block_output = &el2_block_output;
 299 
 300     request_region(ioaddr, EL2_IO_EXTENT, ei_status.name);
 301 
 302     if (dev->irq == 2)
 303         dev->irq = 9;
 304     else if (dev->irq > 5 && dev->irq != 9) {
 305         printk("3c503: configured interrupt %d invalid, will use autoIRQ.\n",
 306                dev->irq);
 307         dev->irq = 0;
 308     }
 309 
 310     ei_status.saved_irq = dev->irq;
 311 
 312     dev->start = 0;
 313     dev->open = &el2_open;
 314     dev->stop = &el2_close;
 315 
 316     if (dev->mem_start)
 317         printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
 318                 dev->name, ei_status.name, (wordlength+1)<<3,
 319                 dev->mem_start, dev->mem_end-1);
 320 
 321     else
 322         printk("\n%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n",
 323                dev->name, ei_status.name, (wordlength+1)<<3);
 324 
 325     return 0;
 326 }
 327 
 328 static int
 329 el2_open(struct device *dev)
     
 330 {
 331 
 332     if (dev->irq < 2) {
 333         int irqlist[] = {5, 9, 3, 4, 0};
 334         int *irqp = irqlist;
 335 
 336         outb(EGACFR_NORM, E33G_GACFR);  
 337         do {
 338             if (request_irq (*irqp, NULL, 0, "bogus") != -EBUSY) {
 339                 
 340                 autoirq_setup(0);
 341                 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
 342                 outb_p(0x00, E33G_IDCFR);
 343                 if (*irqp == autoirq_report(0)   
 344                     && request_irq (dev->irq = *irqp, &ei_interrupt, 0, ei_status.name) == 0)
 345                     break;
 346             }
 347         } while (*++irqp);
 348         if (*irqp == 0) {
 349             outb(EGACFR_IRQOFF, E33G_GACFR);    
 350             return -EAGAIN;
 351         }
 352     } else {
 353         if (request_irq(dev->irq, &ei_interrupt, 0, ei_status.name)) {
 354             return -EAGAIN;
 355         }
 356     }
 357 
 358     el2_init_card(dev);
 359     ei_open(dev);
 360     MOD_INC_USE_COUNT;
 361     return 0;
 362 }
 363 
 364 static int
 365 el2_close(struct device *dev)
     
 366 {
 367     free_irq(dev->irq);
 368     dev->irq = ei_status.saved_irq;
 369     irq2dev_map[dev->irq] = NULL;
 370     outb(EGACFR_IRQOFF, E33G_GACFR);    
 371 
 372     ei_close(dev);
 373     MOD_DEC_USE_COUNT;
 374     return 0;
 375 }
 376 
 377 
 378 
 379 
 380 
 381 static void
 382 el2_reset_8390(struct device *dev)
     
 383 {
 384     if (ei_debug > 1) {
 385         printk("%s: Resetting the 3c503 board...", dev->name);
 386         printk("%#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
 387                E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
 388     }
 389     outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
 390     ei_status.txing = 0;
 391     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 392     el2_init_card(dev);
 393     if (ei_debug > 1) printk("done\n");
 394 }
 395 
 396 
 397 static void
 398 el2_init_card(struct device *dev)
     
 399 {
 400     
 401     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 402 
 403     
 404     
 405     outb(ei_status.rx_start_page, E33G_STARTPG);
 406     outb(ei_status.stop_page,  E33G_STOPPG);
 407 
 408     
 409     outb(0xff, E33G_VP2);       
 410     outb(0xff, E33G_VP1);
 411     outb(0x00, E33G_VP0);
 412     
 413     outb_p(0x00,  dev->base_addr + EN0_IMR);
 414     
 415     outb(EGACFR_NORM, E33G_GACFR);
 416 
 417     
 418     outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
 419     outb_p(8, E33G_DRQCNT);             
 420     outb_p(0x20, E33G_DMAAH);   
 421     outb_p(0x00, E33G_DMAAL);
 422     return;                     
 423 }
 424 
 425 
 426 
 427 static void
 428 el2_block_output(struct device *dev, int count,
     
 429                  const unsigned char *buf, const start_page)
 430 {
 431     int i;                              
 432     int boguscount = 0;         
 433 
 434     if (ei_status.word16)      
 435         outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR);
 436     else 
 437         outb(EGACFR_NORM, E33G_GACFR);
 438 
 439     if (dev->mem_start) {       
 440         unsigned long dest_addr = dev->mem_start +
 441             ((start_page - ei_status.tx_start_page) << 8);
 442         memcpy_toio(dest_addr, buf, count);
 443         outb(EGACFR_NORM, E33G_GACFR);  
 444         return;
 445     }
 446     
 447     
 448     outb(0x00, E33G_DMAAL);
 449     outb_p(start_page, E33G_DMAAH);
 450     outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
 451            | ECNTRL_START, E33G_CNTRL);
 452 
 453     
 454 
 455 
 456     for(i = 0; i < count; i++) {
 457         if (i % 8 == 0)
 458             while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
 459                 if (++boguscount > (i<<3) + 32) {
 460                     printk("%s: FIFO blocked in el2_block_output (at %d of %d, bc=%d).\n",
 461                            dev->name, i, count, boguscount);
 462                     outb(EGACFR_NORM, E33G_GACFR);      
 463                     return;
 464                 }
 465         outb(buf[i], E33G_FIFOH);
 466     }
 467     outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 468     outb(EGACFR_NORM, E33G_GACFR);      
 469     return;
 470 }
 471 
 472 
 473 static void
 474 el2_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
     
 475 {
 476     unsigned int i;
 477     unsigned long hdr_start = dev->mem_start + ((ring_page - EL2_MB1_START_PG)<<8);
 478     unsigned long fifo_watchdog;
 479 
 480     if (dev->mem_start) {       
 481 #ifdef notdef
 482         
 483         memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
 484 #else
 485         ((unsigned int*)hdr)[0] = readl(hdr_start);
 486 #endif
 487         return;
 488     }
 489 
 490     
 491     outb(0, E33G_DMAAL);
 492     outb_p(ring_page & 0xff, E33G_DMAAH);
 493     outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
 494            | ECNTRL_START, E33G_CNTRL);
 495 
 496     
 497     fifo_watchdog = jiffies;
 498     while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) {
 499         if (jiffies - fifo_watchdog > 2*HZ/100) {
 500                 printk("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name);
 501                 break;
 502         }
 503     }
 504 
 505     for(i = 0; i < sizeof(struct e8390_pkt_hdr); i++)
 506         ((char *)(hdr))[i] = inb_p(E33G_FIFOH);
 507 
 508     outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 509 }
 510 
 511 
 512 static void
 513 el2_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
     
 514 {
 515     int boguscount = 0;
 516     int end_of_ring = dev->rmem_end;
 517     unsigned int i;
 518 
 519     
 520     if (dev->mem_start) {       
 521         ring_offset -= (EL2_MB1_START_PG<<8);
 522         if (dev->mem_start + ring_offset + count > end_of_ring) {
 523             
 524             int semi_count = end_of_ring - (dev->mem_start + ring_offset);
 525             memcpy_fromio(skb->data, dev->mem_start + ring_offset, semi_count);
 526             count -= semi_count;
 527             memcpy_fromio(skb->data + semi_count, dev->rmem_start, count);
 528         } else {
 529                 
 530                 eth_io_copy_and_sum(skb, dev->mem_start + ring_offset, count, 0);
 531         }
 532         return;
 533     }
 534     
 535     outb(ring_offset & 0xff, E33G_DMAAL);
 536     outb_p((ring_offset >> 8) & 0xff, E33G_DMAAH);
 537     outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
 538            | ECNTRL_START, E33G_CNTRL);
 539 
 540     
 541 
 542     for(i = 0; i < count; i++) {
 543         if (i % 8 == 0)
 544             while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
 545                 if (++boguscount > (i<<3) + 32) {
 546                     printk("%s: FIFO blocked in el2_block_input() (at %d of %d, bc=%d).\n",
 547                            dev->name, i, count, boguscount);
 548                     boguscount = 0;
 549                     break;
 550                 }
 551         (skb->data)[i] = inb_p(E33G_FIFOH);
 552     }
 553     outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
 554 }
 555 
 556 
 557 #ifdef MODULE
 558 #define MAX_EL2_CARDS   4       
 559 #define NAMELEN         8       
 560 static char namelist[NAMELEN * MAX_EL2_CARDS] = { 0, };
 561 static struct device dev_el2[MAX_EL2_CARDS] = {
 562         {
 563                 NULL,           
 564                 0, 0, 0, 0,
 565                 0, 0,
 566                 0, 0, 0, NULL, NULL
 567         },
 568 };
 569 
 570 static int io[MAX_EL2_CARDS] = { 0, };
 571 static int irq[MAX_EL2_CARDS]  = { 0, };
 572 static int xcvr[MAX_EL2_CARDS] = { 0, };        
 573 
 574 
 575 
 576 int
 577 init_module(void)
     
 578 {
 579         int this_dev, found = 0;
 580 
 581         for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
 582                 struct device *dev = &dev_el2[this_dev];
 583                 dev->name = namelist+(NAMELEN*this_dev);
 584                 dev->irq = irq[this_dev];
 585                 dev->base_addr = io[this_dev];
 586                 dev->mem_end = xcvr[this_dev];  
 587                 dev->init = el2_probe;
 588                 if (io[this_dev] == 0)  {
 589                         if (this_dev != 0) break; 
 590                         printk(KERN_NOTICE "3c503.c: Presently autoprobing (not recommended) for a single card.\n");
 591                 }
 592                 if (register_netdev(dev) != 0) {
 593                         printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
 594                         if (found != 0) return 0;       
 595                         return -ENXIO;
 596                 }
 597                 found++;
 598         }
 599 
 600         return 0;
 601 }
 602 
 603 void
 604 cleanup_module(void)
     
 605 {
 606         int this_dev;
 607 
 608         for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
 609                 struct device *dev = &dev_el2[this_dev];
 610                 if (dev->priv != NULL) {
 611                         
 612                         kfree(dev->priv);
 613                         dev->priv = NULL;
 614                         release_region(dev->base_addr, EL2_IO_EXTENT);
 615                         unregister_netdev(dev);
 616                 }
 617         }
 618 }
 619 #endif 
 620 
 621 
 622 
 623 
 624 
 625 
 626 
 627