1/* 2 * Copyright (c) 1995, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/dev/ed/if_ed.c 50852 1999-09-03 19:10:56Z peter $ |
28 */ 29 30/* 31 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 32 * adapters. By David Greenman, 29-April-1993 33 * 34 * Currently supports the Western Digital/SMC 8003 and 8013 series, 35 * the SMC Elite Ultra (8216), the 3Com 3c503, the NE1000 and NE2000, 36 * and a variety of similar clones. 37 * 38 */ 39 |
40#include "bpf.h" |
41 |
42#include <sys/param.h> 43#include <sys/systm.h> |
44#include <sys/kernel.h> |
45#include <sys/sockio.h> 46#include <sys/malloc.h> 47#include <sys/mbuf.h> 48#include <sys/socket.h> 49#include <sys/syslog.h> 50 |
51#include <sys/module.h> 52#include <sys/bus.h> 53 54#include <machine/bus.h> 55#include <sys/rman.h> 56#include <machine/resource.h> 57 |
58#include <net/ethernet.h> 59#include <net/if.h> 60#include <net/if_arp.h> 61#include <net/if_dl.h> 62#include <net/if_mib.h> 63 64#if NBPF > 0 65#include <net/bpf.h> 66#endif 67#include "opt_bdg.h" 68#ifdef BRIDGE 69#include <net/bridge.h> 70#endif 71 72#include <machine/clock.h> 73#include <machine/md_var.h> 74 |
75#include <i386/isa/if_edreg.h> |
76#include <i386/isa/if_edvar.h> |
77 |
78#include <isa/isavar.h> 79#include <isa/pnpvar.h> |
80 |
81static int ed_alloc_port __P((device_t, int, int)); 82static int ed_alloc_memory __P((device_t, int, int)); 83static int ed_alloc_irq __P((device_t, int, int)); 84static void ed_release_resources __P((device_t)); |
85 |
86static int ed_attach __P((struct ed_softc *, int, int)); |
87static int ed_isa_attach __P((device_t)); |
88 89static void ed_init __P((void *)); |
90static driver_intr_t edintr; |
91static int ed_ioctl __P((struct ifnet *, u_long, caddr_t)); |
92static int ed_isa_probe __P((device_t)); |
93static void ed_start __P((struct ifnet *)); 94static void ed_reset __P((struct ifnet *)); 95static void ed_watchdog __P((struct ifnet *)); 96 97static void ed_stop __P((struct ed_softc *)); 98static int ed_probe_generic8390 __P((struct ed_softc *)); |
99static int ed_probe_WD80x3 __P((device_t)); 100static int ed_probe_3Com __P((device_t)); 101static int ed_probe_Novell __P((device_t)); 102static int ed_probe_Novell_generic __P((device_t, int, int)); 103static int ed_probe_HP_pclanp __P((device_t)); |
104 105#include "pci.h" 106#if NPCI > 0 |
107int ed_attach_NE2000_pci __P((device_t, int)); |
108#endif 109 110#include "card.h" |
111#if NCARDxx > 0 |
112static int ed_probe_pccard __P((struct isa_device *, u_char *)); 113#endif 114 115static void ds_getmcaf __P((struct ed_softc *, u_long *)); 116 117static void ed_get_packet __P((struct ed_softc *, char *, /* u_short */ int, int)); 118 119static __inline void ed_rint __P((struct ed_softc *)); --- 7 unchanged lines hidden (view full) --- 127 int)); 128 129static void ed_pio_readmem __P((struct ed_softc *, int, unsigned char *, 130 /* u_short */ int)); 131static void ed_pio_writemem __P((struct ed_softc *, char *, 132 /* u_short */ int, /* u_short */ int)); 133static u_short ed_pio_write_mbufs __P((struct ed_softc *, struct mbuf *, 134 int)); |
135 136static void ed_setrcr __P((struct ed_softc *)); 137 138static u_long ds_crc __P((u_char *ep)); 139 |
140#if NCARDxx > 0 |
141#include <sys/select.h> 142#include <sys/module.h> 143#include <pccard/cardinfo.h> 144#include <pccard/slot.h> 145 146/* 147 * PC-Card (PCMCIA) specific code. 148 */ --- 24 unchanged lines hidden (view full) --- 173 if (ed_probe_pccard(&devi->isahd, devi->misc) == 0) 174 return(ENXIO); 175 e = 0; 176 for (i = 0; i < ETHER_ADDR_LEN; ++i) 177 e |= devi->misc[i]; 178 if (e) 179 for (i = 0; i < ETHER_ADDR_LEN; ++i) 180 sc->arpcom.ac_enaddr[i] = devi->misc[i]; |
181 if (ed_isa_attach(&devi->isahd) == 0) |
182 return(ENXIO); 183 184 return(0); 185} 186 187/* 188 * edunload - unload the driver and clear the table. 189 * XXX TODO: --- 21 unchanged lines hidden (view full) --- 211 212/* 213 * card_intr - Shared interrupt called from 214 * front end of PC-Card handler. 215 */ 216static int 217card_intr(struct pccard_devinfo *devi) 218{ |
219 edintr(&ed_softc[devi->isahd.id_unit]); |
220 return(1); 221} 222#endif /* NCARD > 0 */ 223 |
224/* 225 * Interrupt conversion table for WD/SMC ASIC/83C584 |
226 */ |
227static unsigned short ed_intr_val[] = { 228 9, 229 3, 230 5, 231 7, 232 10, 233 11, 234 15, 235 4 |
236}; 237 238/* 239 * Interrupt conversion table for 83C790 240 */ |
241static unsigned short ed_790_intr_val[] = { |
242 0, |
243 9, 244 3, 245 5, 246 7, 247 10, 248 11, 249 15 |
250}; 251 252/* 253 * Interrupt conversion table for the HP PC LAN+ 254 */ 255 |
256static unsigned short ed_hpp_intr_val[] = { |
257 0, /* 0 */ 258 0, /* 1 */ 259 0, /* 2 */ |
260 3, /* 3 */ 261 4, /* 4 */ 262 5, /* 5 */ 263 6, /* 6 */ 264 7, /* 7 */ |
265 0, /* 8 */ |
266 9, /* 9 */ 267 10, /* 10 */ 268 11, /* 11 */ 269 12, /* 12 */ |
270 0, /* 13 */ 271 0, /* 14 */ |
272 15 /* 15 */ |
273}; 274 |
275static struct isa_pnp_id ed_ids[] = { 276 { 0xd680d041, "NE2000 Compatible" }, /* PNP80d6 */ 277 { 0x1980635e, "WSC8019" }, /* WSC8019 */ 278 { 0x0131d805, "Acer ALN-101T" }, /* ANX3101 */ 279 { 0x01200507, "PLANET ENW-2401" }, /* AXE2001 */ 280 { 0x19808c4a, "Realtek Plug & Play Ethernet Card" }, /* RTL8019 */ 281 { 0x0090252a, "CNet NE2000 Compatible" }, /* JQE9000 */ 282 { 0x0020832e, "Kingston EtheRX KNE20 Plug & Play ISA" }, /* KTC2000 */ 283 { 0, NULL} 284}; 285 |
286static int |
287ed_isa_probe(dev) 288 device_t dev; |
289{ |
290 struct ed_softc *sc = device_get_softc(dev); 291 int error = 0; |
292 |
293 bzero(sc, sizeof(struct ed_softc)); |
294 |
295 /* Check isapnp ids */ 296 error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids); |
297 |
298 /* If the card had a PnP ID that didn't match any we know about */ 299 if (error == ENXIO) 300 goto end; |
301 |
302 /* If we found a PnP card. */ 303 if (error == 0) { 304 error = ed_probe_Novell(dev); 305 goto end; 306 } 307 308 /* Heuristic probes */ |
309 |
310 error = ed_probe_WD80x3(dev); 311 if (error == 0) 312 goto end; 313 ed_release_resources(dev); 314 315 error = ed_probe_3Com(dev); 316 if (error == 0) 317 goto end; 318 ed_release_resources(dev); 319 320 error = ed_probe_Novell(dev); 321 if (error == 0) 322 goto end; 323 ed_release_resources(dev); 324 325 error = ed_probe_HP_pclanp(dev); 326 if (error == 0) 327 goto end; 328 ed_release_resources(dev); 329 330end: 331 if (error == 0) 332 error = ed_alloc_irq(dev, 0, 0); 333 334 ed_release_resources(dev); 335 return (error); |
336} 337 338/* 339 * Generic probe routine for testing for the existance of a DS8390. 340 * Must be called after the NIC has just been reset. This routine 341 * works by looking at certain register values that are guaranteed 342 * to be initialized a certain way after power-up or reset. Seems 343 * not to currently work on the 83C690. --- 27 unchanged lines hidden (view full) --- 371 372 return (1); 373} 374 375/* 376 * Probe and vendor-specific initialization routine for SMC/WD80x3 boards 377 */ 378static int |
379ed_probe_WD80x3(dev) 380 device_t dev; |
381{ |
382 struct ed_softc *sc = device_get_softc(dev); 383 int error; |
384 int i; |
385 int flags = isa_get_flags(dev); |
386 u_int memsize, maddr; 387 u_char iptr, isa16bit, sum; |
388 u_long conf_maddr, conf_msize, irq, junk; |
389 |
390 error = ed_alloc_port(dev, 0, ED_WD_IO_PORTS); 391 if (error) 392 return (error); 393 394 sc->asic_addr = rman_get_start(sc->port_res); |
395 sc->nic_addr = sc->asic_addr + ED_WD_NIC_OFFSET; 396 sc->is790 = 0; 397 398#ifdef TOSH_ETHER 399 outb(sc->asic_addr + ED_WD_MSR, ED_WD_MSR_POW); 400 DELAY(10000); 401#endif 402 --- 10 unchanged lines hidden (view full) --- 413 414 /* 415 * Checksum is invalid. This often happens with cheap WD8003E 416 * clones. In this case, the checksum byte (the eighth byte) 417 * seems to always be zero. 418 */ 419 if (inb(sc->asic_addr + ED_WD_CARD_ID) != ED_TYPE_WD8003E || 420 inb(sc->asic_addr + ED_WD_PROM + 7) != 0) |
421 return (ENXIO); |
422 } 423 /* reset card to force it into a known state. */ 424#ifdef TOSH_ETHER 425 outb(sc->asic_addr + ED_WD_MSR, ED_WD_MSR_RST | ED_WD_MSR_POW); 426#else 427 outb(sc->asic_addr + ED_WD_MSR, ED_WD_MSR_RST); 428#endif 429 DELAY(100); --- 118 unchanged lines hidden (view full) --- 548#ifdef TOSH_ETHER 549 && (sc->type != ED_TYPE_TOSHIBA1) && (sc->type != ED_TYPE_TOSHIBA4) 550#endif 551 && ((inb(sc->asic_addr + ED_WD_ICR) & ED_WD_ICR_16BIT) == 0)) { 552 isa16bit = 0; 553 memsize = 8192; 554 } 555 |
556 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 557 SYS_RES_MEMORY, 0, 558 &conf_maddr, &conf_msize); 559 if (error) 560 return (error); 561 |
562#if ED_DEBUG 563 printf("type = %x type_str=%s isa16bit=%d memsize=%d id_msize=%d\n", |
564 sc->type, sc->type_str, isa16bit, memsize, conf_msize); |
565 for (i = 0; i < 8; i++) 566 printf("%x -> %x\n", i, inb(sc->asic_addr + i)); 567#endif 568 569 /* 570 * Allow the user to override the autoconfiguration 571 */ |
572 if (conf_msize > 1) 573 memsize = conf_msize; |
574 |
575 maddr = conf_maddr; |
576 if (maddr < 0xa0000 || maddr + memsize > 0x1000000) { |
577 device_printf(dev, "Invalid ISA memory address range configured: 0x%x - 0x%x\n", 578 maddr, maddr + memsize); 579 return (ENXIO); |
580 } 581 582 /* 583 * (note that if the user specifies both of the following flags that 584 * '8bit' mode intentionally has precedence) 585 */ |
586 if (flags & ED_FLAGS_FORCE_16BIT_MODE) |
587 isa16bit = 1; |
588 if (flags & ED_FLAGS_FORCE_8BIT_MODE) |
589 isa16bit = 0; 590 591 /* 592 * If possible, get the assigned interrupt number from the card and 593 * use it. 594 */ 595 if ((sc->type & ED_WD_SOFTCONFIG) && (!sc->is790)) { 596 597 /* 598 * Assemble together the encoded interrupt number. 599 */ |
600 iptr = (inb(sc->asic_addr + ED_WD_ICR) & ED_WD_ICR_IR2) | 601 ((inb(sc->asic_addr + ED_WD_IRR) & |
602 (ED_WD_IRR_IR0 | ED_WD_IRR_IR1)) >> 5); 603 604 /* 605 * If no interrupt specified (or "?"), use what the board tells us. 606 */ |
607 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 608 SYS_RES_IRQ, 0, 609 &irq, &junk); 610 if (error) { 611 ISA_SET_RESOURCE(device_get_parent(dev), dev, 612 SYS_RES_IRQ, 0, 613 ed_intr_val[iptr], 1); 614 } |
615 616 /* 617 * Enable the interrupt. 618 */ |
619 outb(sc->asic_addr + ED_WD_IRR, 620 inb(sc->asic_addr + ED_WD_IRR) | ED_WD_IRR_IEN); |
621 } 622 if (sc->is790) { |
623 outb(sc->asic_addr + ED_WD790_HWR, 624 inb(sc->asic_addr + ED_WD790_HWR) | ED_WD790_HWR_SWH); 625 iptr = (((inb(sc->asic_addr + ED_WD790_GCR) & ED_WD790_GCR_IR2) >> 4) | 626 (inb(sc->asic_addr + ED_WD790_GCR) & |
627 (ED_WD790_GCR_IR1 | ED_WD790_GCR_IR0)) >> 2); |
628 outb(sc->asic_addr + ED_WD790_HWR, 629 inb(sc->asic_addr + ED_WD790_HWR) & ~ED_WD790_HWR_SWH); |
630 631 /* 632 * If no interrupt specified (or "?"), use what the board tells us. 633 */ |
634 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 635 SYS_RES_IRQ, 0, 636 &irq, &junk); 637 if (error) { 638 ISA_SET_RESOURCE(device_get_parent(dev), dev, 639 SYS_RES_IRQ, 0, 640 ed_790_intr_val[iptr], 1); 641 } |
642 643 /* 644 * Enable interrupts. 645 */ |
646 outb(sc->asic_addr + ED_WD790_ICR, 647 inb(sc->asic_addr + ED_WD790_ICR) | ED_WD790_ICR_EIL); |
648 } |
649 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 650 SYS_RES_IRQ, 0, 651 &irq, &junk); 652 if (error) { 653 device_printf(dev, "%s cards don't support auto-detected/assigned interrupts.\n", 654 sc->type_str); 655 return (ENXIO); |
656 } 657 sc->isa16bit = isa16bit; 658 sc->mem_shared = 1; |
659 |
660 error = ed_alloc_memory(dev, 0, memsize); 661 if (error) 662 return (error); 663 sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res); 664 |
665 /* 666 * allocate one xmit buffer if < 16k, two buffers otherwise 667 */ 668 if ((memsize < 16384) || |
669 (flags & ED_FLAGS_NO_MULTI_BUFFERING)) { |
670 sc->txb_cnt = 1; 671 } else { 672 sc->txb_cnt = 2; 673 } 674 sc->tx_page_start = ED_WD_PAGE_OFFSET; 675 sc->rec_page_start = ED_WD_PAGE_OFFSET + ED_TXBUF_SIZE * sc->txb_cnt; 676 sc->rec_page_stop = ED_WD_PAGE_OFFSET + memsize / ED_PAGE_SIZE; 677 sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * sc->rec_page_start); --- 67 unchanged lines hidden (view full) --- 745 746 /* 747 * Now zero memory and verify that it is clear 748 */ 749 bzero(sc->mem_start, memsize); 750 751 for (i = 0; i < memsize; ++i) { 752 if (sc->mem_start[i]) { |
753 device_printf(dev, "failed to clear shared memory at %lx - check configuration\n", 754 kvtop(sc->mem_start + i)); |
755 756 /* 757 * Disable 16 bit access to shared memory 758 */ 759 if (isa16bit) { 760 if (sc->is790) { 761 outb(sc->asic_addr + ED_WD_MSR, 0x00); 762 } 763 outb(sc->asic_addr + ED_WD_LAAR, sc->wd_laar_proto & 764 ~ED_WD_LAAR_M16EN); 765 } |
766 return (ENXIO); |
767 } 768 } 769 770 /* 771 * Disable 16bit access to shared memory - we leave it 772 * disabled so that 1) machines reboot properly when the board 773 * is set 16 bit mode and there are conflicting 8bit 774 * devices/ROMS in the same 128k address space as this boards 775 * shared memory. and 2) so that other 8 bit devices with 776 * shared memory can be used in this 128k region, too. 777 */ 778 if (isa16bit) { 779 if (sc->is790) { 780 outb(sc->asic_addr + ED_WD_MSR, 0x00); 781 } 782 outb(sc->asic_addr + ED_WD_LAAR, sc->wd_laar_proto & 783 ~ED_WD_LAAR_M16EN); 784 } |
785 return (0); |
786} 787 788/* 789 * Probe and vendor-specific initialization routine for 3Com 3c503 boards 790 */ 791static int |
792ed_probe_3Com(dev) 793 device_t dev; |
794{ |
795 struct ed_softc *sc = device_get_softc(dev); 796 int error; |
797 int i; |
798 int flags = isa_get_flags(dev); |
799 u_int memsize; 800 u_char isa16bit; |
801 u_long conf_maddr, conf_msize, irq, junk; |
802 |
803 error = ed_alloc_port(dev, 0, ED_3COM_IO_PORTS); 804 if (error) 805 return (error); |
806 |
807 sc->asic_addr = rman_get_start(sc->port_res) + ED_3COM_ASIC_OFFSET; 808 sc->nic_addr = rman_get_start(sc->port_res) + ED_3COM_NIC_OFFSET; 809 |
810 /* 811 * Verify that the kernel configured I/O address matches the board 812 * configured address 813 */ 814 switch (inb(sc->asic_addr + ED_3COM_BCFR)) { 815 case ED_3COM_BCFR_300: |
816 if (rman_get_start(sc->port_res) != 0x300) 817 return (ENXIO); |
818 break; 819 case ED_3COM_BCFR_310: |
820 if (rman_get_start(sc->port_res) != 0x310) 821 return (ENXIO); |
822 break; 823 case ED_3COM_BCFR_330: |
824 if (rman_get_start(sc->port_res) != 0x330) 825 return (ENXIO); |
826 break; 827 case ED_3COM_BCFR_350: |
828 if (rman_get_start(sc->port_res) != 0x350) 829 return (ENXIO); |
830 break; 831 case ED_3COM_BCFR_250: |
832 if (rman_get_start(sc->port_res) != 0x250) 833 return (ENXIO); |
834 break; 835 case ED_3COM_BCFR_280: |
836 if (rman_get_start(sc->port_res) != 0x280) 837 return (ENXIO); |
838 break; 839 case ED_3COM_BCFR_2A0: |
840 if (rman_get_start(sc->port_res) != 0x2a0) 841 return (ENXIO); |
842 break; 843 case ED_3COM_BCFR_2E0: |
844 if (rman_get_start(sc->port_res) != 0x2e0) 845 return (ENXIO); |
846 break; 847 default: |
848 return (ENXIO); |
849 } 850 |
851 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 852 SYS_RES_MEMORY, 0, 853 &conf_maddr, &conf_msize); 854 if (error) 855 return (error); 856 |
857 /* 858 * Verify that the kernel shared memory address matches the board 859 * configured address. 860 */ 861 switch (inb(sc->asic_addr + ED_3COM_PCFR)) { 862 case ED_3COM_PCFR_DC000: |
863 if (conf_maddr != 0xdc000) 864 return (ENXIO); |
865 break; 866 case ED_3COM_PCFR_D8000: |
867 if (conf_maddr != 0xd8000) 868 return (ENXIO); |
869 break; 870 case ED_3COM_PCFR_CC000: |
871 if (conf_maddr != 0xcc000) 872 return (ENXIO); |
873 break; 874 case ED_3COM_PCFR_C8000: |
875 if (conf_maddr != 0xc8000) 876 return (ENXIO); |
877 break; 878 default: |
879 return (ENXIO); |
880 } 881 882 883 /* 884 * Reset NIC and ASIC. Enable on-board transceiver throughout reset 885 * sequence because it'll lock up if the cable isn't connected if we 886 * don't. 887 */ --- 75 unchanged lines hidden (view full) --- 963 else 964 isa16bit = 0; 965 966 /* 967 * select page 0 registers 968 */ 969 outb(sc->nic_addr + ED_P2_CR, ED_CR_RD2 | ED_CR_STP); 970 |
971 error = ed_alloc_memory(dev, 0, memsize); 972 if (error) 973 return (error); 974 975 sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res); |
976 sc->mem_size = memsize; 977 sc->mem_end = sc->mem_start + memsize; 978 979 /* 980 * We have an entire 8k window to put the transmit buffers on the 981 * 16bit boards. But since the 16bit 3c503's shared memory is only 982 * fast enough to overlap the loading of one full-size packet, trying 983 * to load more than 2 buffers can actually leave the transmitter idle 984 * during the load. So 2 seems the best value. (Although a mix of 985 * variable-sized packets might change this assumption. Nonetheless, 986 * we optimize for linear transfers of same-size packets.) 987 */ 988 if (isa16bit) { |
989 if (flags & ED_FLAGS_NO_MULTI_BUFFERING) |
990 sc->txb_cnt = 1; 991 else 992 sc->txb_cnt = 2; 993 994 sc->tx_page_start = ED_3COM_TX_PAGE_OFFSET_16BIT; 995 sc->rec_page_start = ED_3COM_RX_PAGE_OFFSET_16BIT; 996 sc->rec_page_stop = memsize / ED_PAGE_SIZE + 997 ED_3COM_RX_PAGE_OFFSET_16BIT; --- 14 unchanged lines hidden (view full) --- 1012 * doing DMA, but what the hell. 1013 */ 1014 outb(sc->asic_addr + ED_3COM_PSTR, sc->rec_page_start); 1015 outb(sc->asic_addr + ED_3COM_PSPR, sc->rec_page_stop); 1016 1017 /* 1018 * Set IRQ. 3c503 only allows a choice of irq 2-5. 1019 */ |
1020 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 1021 SYS_RES_IRQ, 0, 1022 &irq, &junk); 1023 if (error) 1024 return (error); 1025 1026 switch (irq) { 1027 case 2: |
1028 outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ2); 1029 break; |
1030 case 3: |
1031 outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ3); 1032 break; |
1033 case 4: |
1034 outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ4); 1035 break; |
1036 case 5: |
1037 outb(sc->asic_addr + ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ5); 1038 break; 1039 default: |
1040 device_printf(dev, "Invalid irq configuration (%ld) must be 3-5,9 for 3c503\n", 1041 irq); 1042 return (ENXIO); |
1043 } 1044 1045 /* 1046 * Initialize GA configuration register. Set bank and enable shared 1047 * mem. 1048 */ 1049 outb(sc->asic_addr + ED_3COM_GACFR, ED_3COM_GACFR_RSEL | 1050 ED_3COM_GACFR_MBS0); --- 10 unchanged lines hidden (view full) --- 1061 1062 /* 1063 * Zero memory and verify that it is clear 1064 */ 1065 bzero(sc->mem_start, memsize); 1066 1067 for (i = 0; i < memsize; ++i) 1068 if (sc->mem_start[i]) { |
1069 device_printf(dev, "failed to clear shared memory at %lx - check configuration\n", 1070 kvtop(sc->mem_start + i)); 1071 return (ENXIO); |
1072 } |
1073 return (0); |
1074} 1075 1076/* 1077 * Probe and vendor-specific initialization routine for NE1000/2000 boards 1078 */ 1079static int |
1080ed_probe_Novell_generic(dev, port_rid, flags) 1081 device_t dev; 1082 int port_rid; |
1083 int flags; 1084{ |
1085 struct ed_softc *sc = device_get_softc(dev); |
1086 u_int memsize, n; 1087 u_char romdata[16], tmp; 1088 static char test_pattern[32] = "THIS is A memory TEST pattern"; 1089 char test_buffer[32]; |
1090 int error; |
1091 |
1092 error = ed_alloc_port(dev, port_rid, ED_NOVELL_IO_PORTS); 1093 if (error) 1094 return (error); |
1095 |
1096 sc->asic_addr = rman_get_start(sc->port_res) + ED_NOVELL_ASIC_OFFSET; 1097 sc->nic_addr = rman_get_start(sc->port_res) + ED_NOVELL_NIC_OFFSET; 1098 |
1099 /* XXX - do Novell-specific probe here */ 1100 1101 /* Reset the board */ 1102#ifdef GWETHER 1103 outb(sc->asic_addr + ED_NOVELL_RESET, 0); 1104 DELAY(200); 1105#endif /* GWETHER */ 1106 tmp = inb(sc->asic_addr + ED_NOVELL_RESET); --- 16 unchanged lines hidden (view full) --- 1123 * judgement. -DLG 1124 */ 1125 outb(sc->nic_addr + ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 1126 1127 DELAY(5000); 1128 1129 /* Make sure that we really have an 8390 based board */ 1130 if (!ed_probe_generic8390(sc)) |
1131 return (ENXIO); |
1132 1133 sc->vendor = ED_VENDOR_NOVELL; 1134 sc->mem_shared = 0; 1135 sc->cr_proto = ED_CR_RD2; 1136 1137 /* 1138 * Test the ability to read and write to the NIC memory. This has the 1139 * side affect of determining if this is an NE1000 or an NE2000. --- 33 unchanged lines hidden (view full) --- 1173 /* 1174 * Write a test pattern in word mode. If this also fails, then 1175 * we don't know what this board is. 1176 */ 1177 ed_pio_writemem(sc, test_pattern, 16384, sizeof(test_pattern)); 1178 ed_pio_readmem(sc, 16384, test_buffer, sizeof(test_pattern)); 1179 1180 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) |
1181 return (ENXIO); /* not an NE2000 either */ |
1182 1183 sc->type = ED_TYPE_NE2000; 1184 sc->type_str = "NE2000"; 1185 } else { 1186 sc->type = ED_TYPE_NE1000; 1187 sc->type_str = "NE1000"; 1188 } 1189 --- 38 unchanged lines hidden (view full) --- 1228 mstart = x * ED_PAGE_SIZE; 1229 msize = ED_PAGE_SIZE; 1230 break; 1231 } 1232 } 1233 } 1234 1235 if (mstart == 0) { |
1236 device_printf(dev, "Cannot find start of RAM.\n"); 1237 return (ENXIO); |
1238 } 1239 /* Search for the start of RAM. */ 1240 for (x = (mstart / ED_PAGE_SIZE) + 1; x < 256; x++) { 1241 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE); 1242 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) { 1243 for (i = 0; i < ED_PAGE_SIZE; i++) 1244 pbuf[i] = 255 - x; 1245 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE); --- 4 unchanged lines hidden (view full) --- 1250 break; 1251 } 1252 } else { 1253 break; 1254 } 1255 } 1256 1257 if (msize == 0) { |
1258 device_printf(dev, "Cannot find any RAM, start : %d, x = %d.\n", mstart, x); 1259 return (ENXIO); |
1260 } |
1261 device_printf(dev, "RAM start at %d, size : %d.\n", mstart, msize); |
1262 1263 sc->mem_size = msize; 1264 sc->mem_start = (char *) mstart; 1265 sc->mem_end = (char *) (msize + mstart); 1266 sc->tx_page_start = mstart / ED_PAGE_SIZE; 1267 } 1268#endif /* GWETHER */ 1269 --- 19 unchanged lines hidden (view full) --- 1289 if (sc->arpcom.ac_enaddr[2] == 0x86) { 1290 sc->type_str = "Gateway AT"; 1291 } 1292#endif /* GWETHER */ 1293 1294 /* clear any pending interrupts that might have occurred above */ 1295 outb(sc->nic_addr + ED_P0_ISR, 0xff); 1296 |
1297 return (0); |
1298} 1299 1300static int |
1301ed_probe_Novell(dev) 1302 device_t dev; |
1303{ |
1304 return ed_probe_Novell_generic(dev, 0, isa_get_flags(dev)); |
1305} 1306 |
1307#if NCARDxx > 0 |
1308/* 1309 * Probe framework for pccards. Replicates the standard framework, 1310 * minus the pccard driver registration and ignores the ether address 1311 * supplied (from the CIS), relying on the probe to find it instead. 1312 */ 1313static int 1314ed_probe_pccard(isa_dev, ether) 1315 struct isa_device *isa_dev; --- 34 unchanged lines hidden (view full) --- 1350 * is inactive. 1351 * 1352 * For more information; please consult the CRYNWR packet driver. 1353 * 1354 * The AUI port is turned on using the "link2" option on the ifconfig 1355 * command line. 1356 */ 1357static int |
1358ed_probe_HP_pclanp(dev) 1359 device_t dev; |
1360{ |
1361 struct ed_softc *sc = device_get_softc(dev); 1362 int error; |
1363 int n; /* temp var */ 1364 int memsize; /* mem on board */ 1365 u_char checksum; /* checksum of board address */ 1366 u_char irq; /* board configured IRQ */ 1367 char test_pattern[ED_HPP_TEST_SIZE]; /* read/write areas for */ 1368 char test_buffer[ED_HPP_TEST_SIZE]; /* probing card */ |
1369 u_long conf_maddr, conf_msize, conf_irq, junk; |
1370 |
1371 error = ed_alloc_port(dev, 0, ED_HPP_IO_PORTS); 1372 if (error) 1373 return (error); |
1374 1375 /* Fill in basic information */ |
1376 sc->asic_addr = rman_get_start(sc->port_res) + ED_HPP_ASIC_OFFSET; 1377 sc->nic_addr = rman_get_start(sc->port_res) + ED_HPP_NIC_OFFSET; |
1378 sc->is790 = 0; 1379 sc->isa16bit = 0; /* the 8390 core needs to be in byte mode */ 1380 1381 /* 1382 * Look for the HP PCLAN+ signature: "0x50,0x48,0x00,0x53" 1383 */ 1384 1385 if ((inb(sc->asic_addr + ED_HPP_ID) != 0x50) || --- 63 unchanged lines hidden (view full) --- 1449 outw(sc->asic_addr + ED_HPP_PAGING, ED_HPP_PAGE_HW); 1450 1451 irq = inb(sc->asic_addr + ED_HPP_HW_IRQ); 1452 1453 /* 1454 * Check for impossible IRQ. 1455 */ 1456 |
1457 if (irq >= (sizeof(ed_hpp_intr_val) / sizeof(ed_hpp_intr_val[0]))) |
1458 return 0; 1459 1460 /* 1461 * If the kernel IRQ was specified with a '?' use the cards idea 1462 * of the IRQ. If the kernel IRQ was explicitly specified, it 1463 * should match that of the hardware. 1464 */ |
1465 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 1466 SYS_RES_IRQ, 0, 1467 &conf_irq, &junk); 1468 if (error) { 1469 ISA_SET_RESOURCE(device_get_parent(dev), dev, 1470 SYS_RES_IRQ, 0, 1471 ed_hpp_intr_val[irq], 1); 1472 } else { 1473 if (conf_irq != ed_hpp_intr_val[irq]) 1474 return (ENXIO); 1475 } |
1476 |
1477 /* 1478 * Fill in softconfig info. 1479 */ 1480 1481 sc->vendor = ED_VENDOR_HP; 1482 sc->type = ED_TYPE_HP_PCLANPLUS; 1483 sc->type_str = "HP-PCLAN+"; 1484 1485 sc->mem_shared = 0; /* we DON'T have dual ported RAM */ 1486 sc->mem_start = 0; /* we use offsets inside the card RAM */ 1487 1488 sc->hpp_mem_start = NULL;/* no memory mapped I/O by default */ 1489 1490 /* |
1491 * The board has 32KB of memory. Is there a way to determine 1492 * this programmatically? 1493 */ 1494 1495 memsize = 32768; 1496 1497 /* |
1498 * Check if memory mapping of the I/O registers possible. 1499 */ 1500 1501 if (sc->hpp_options & ED_HPP_OPTION_MEM_ENABLE) 1502 { 1503 u_long mem_addr; 1504 1505 /* 1506 * determine the memory address from the board. 1507 */ 1508 1509 outw(sc->asic_addr + ED_HPP_PAGING, ED_HPP_PAGE_HW); 1510 mem_addr = (inw(sc->asic_addr + ED_HPP_HW_MEM_MAP) << 8); 1511 1512 /* 1513 * Check that the kernel specified start of memory and 1514 * hardware's idea of it match. 1515 */ |
1516 error = ISA_GET_RESOURCE(device_get_parent(dev), dev, 1517 SYS_RES_MEMORY, 0, 1518 &conf_maddr, &conf_msize); 1519 if (error) 1520 return (error); |
1521 |
1522 if (mem_addr != conf_maddr) |
1523 return 0; 1524 |
1525 error = ed_alloc_memory(dev, 0, memsize); 1526 if (error) 1527 return (error); 1528 1529 sc->hpp_mem_start = rman_get_virtual(sc->mem_res); |
1530 } 1531 1532 /* |
1533 * Fill in the rest of the soft config structure. 1534 */ 1535 1536 /* 1537 * The transmit page index. 1538 */ 1539 1540 sc->tx_page_start = ED_HPP_TX_PAGE_OFFSET; 1541 |
1542 if (isa_get_flags(dev) & ED_FLAGS_NO_MULTI_BUFFERING) |
1543 sc->txb_cnt = 1; 1544 else 1545 sc->txb_cnt = 2; 1546 1547 /* 1548 * Memory description 1549 */ 1550 --- 111 unchanged lines hidden (view full) --- 1662 /* 1663 * Restore normal pages. 1664 */ 1665 1666 outw(sc->asic_addr + ED_HPP_PAGING, ED_HPP_PAGE_PERF); 1667 1668} 1669 |
1670/* 1671 * Allocate a port resource with the given resource id. 1672 */ 1673static int 1674ed_alloc_port(dev, rid, size) 1675 device_t dev; 1676 int rid; 1677 int size; 1678{ 1679 struct ed_softc *sc = device_get_softc(dev); 1680 struct resource *res; |
1681 |
1682 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 1683 0ul, ~0ul, size, RF_ACTIVE); 1684 if (res) { 1685 sc->port_rid = rid; 1686 sc->port_res = res; 1687 sc->port_used = 1; 1688 return (0); 1689 } else { 1690 return (ENOENT); 1691 } 1692} 1693 |
1694/* |
1695 * Allocate a memory resource with the given resource id. 1696 */ 1697static int 1698ed_alloc_memory(dev, rid, size) 1699 device_t dev; 1700 int rid; 1701 int size; 1702{ 1703 struct ed_softc *sc = device_get_softc(dev); 1704 struct resource *res; 1705 1706 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 1707 0ul, ~0ul, size, RF_ACTIVE); 1708 if (res) { 1709 sc->mem_rid = rid; 1710 sc->mem_res = res; 1711 sc->mem_used = 1; 1712 return (0); 1713 } else { 1714 return (ENOENT); 1715 } 1716} 1717 1718/* 1719 * Allocate an irq resource with the given resource id. 1720 */ 1721static int 1722ed_alloc_irq(dev, rid, flags) 1723 device_t dev; 1724 int rid; 1725 int flags; 1726{ 1727 struct ed_softc *sc = device_get_softc(dev); 1728 struct resource *res; 1729 1730 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 1731 0ul, ~0ul, 1, (RF_ACTIVE | flags)); 1732 if (res) { 1733 sc->irq_rid = rid; 1734 sc->irq_res = res; 1735 return (0); 1736 } else { 1737 return (ENOENT); 1738 } 1739} 1740 1741/* 1742 * Release all resources 1743 */ 1744static void 1745ed_release_resources(dev) 1746 device_t dev; 1747{ 1748 struct ed_softc *sc = device_get_softc(dev); 1749 1750 if (sc->port_res) { 1751 bus_release_resource(dev, SYS_RES_IOPORT, 1752 sc->port_rid, sc->port_res); 1753 sc->port_res = 0; 1754 } 1755 if (sc->mem_res) { 1756 bus_release_resource(dev, SYS_RES_MEMORY, 1757 sc->mem_rid, sc->mem_res); 1758 sc->mem_res = 0; 1759 } 1760 if (sc->irq_res) { 1761 bus_release_resource(dev, SYS_RES_IRQ, 1762 sc->irq_rid, sc->irq_res); 1763 sc->irq_res = 0; 1764 } 1765} 1766 1767/* |
1768 * Install interface into kernel networking data structures 1769 */ 1770static int 1771ed_attach(sc, unit, flags) 1772 struct ed_softc *sc; 1773 int unit; 1774 int flags; 1775{ --- 75 unchanged lines hidden (view full) --- 1851 (ifp->if_flags & IFF_ALTPHYS)) ? " tranceiver disabled" : ""); 1852 1853 /* 1854 * If BPF is in the kernel, call the attach for it 1855 */ 1856#if NBPF > 0 1857 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); 1858#endif |
1859 return (0); |
1860} 1861 1862static int |
1863ed_isa_attach(dev) 1864 device_t dev; |
1865{ |
1866 struct ed_softc *sc = device_get_softc(dev); 1867 int flags = isa_get_flags(dev); 1868 int error; |
1869 |
1870 if (sc->port_used > 0) 1871 ed_alloc_port(dev, sc->port_rid, 1); 1872 if (sc->mem_used) 1873 ed_alloc_memory(dev, sc->mem_rid, 1); 1874 ed_alloc_irq(dev, sc->irq_rid, 0); 1875 1876 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 1877 edintr, sc, &sc->irq_handle); 1878 if (error) { 1879 ed_release_resources(dev); 1880 return (error); 1881 } 1882 1883 return ed_attach(sc, device_get_unit(dev), flags); |
1884} 1885 1886#if NPCI > 0 |
1887int 1888ed_attach_NE2000_pci(dev, port_rid) 1889 device_t dev; 1890 int port_rid; |
1891{ |
1892 struct ed_softc *sc = device_get_softc(dev); 1893 int flags = 0; 1894 int error; |
1895 |
1896 error = ed_probe_Novell_generic(dev, port_rid, flags); 1897 if (error) 1898 return (error); |
1899 |
1900 error = ed_alloc_irq(dev, 0, RF_SHAREABLE); 1901 if (error) { 1902 ed_release_resources(dev); 1903 return (error); |
1904 } |
1905 1906 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 1907 edintr, sc, &sc->irq_handle); 1908 if (error) { 1909 ed_release_resources(dev); 1910 return (error); 1911 } 1912 1913 return ed_attach(sc, device_get_unit(dev), flags); |
1914} 1915#endif 1916 1917/* 1918 * Reset interface. 1919 */ 1920static void 1921ed_reset(ifp) --- 555 unchanged lines hidden (view full) --- 2477 */ 2478 outb(sc->nic_addr + ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA); 2479 } 2480} 2481 2482/* 2483 * Ethernet interface interrupt processor 2484 */ |
2485static void 2486edintr(arg) 2487 void *arg; |
2488{ |
2489 struct ed_softc *sc = (struct ed_softc*) arg; |
2490 struct ifnet *ifp = (struct ifnet *)sc; 2491 u_char isr; 2492 2493 if (sc->gone) 2494 return; 2495 /* 2496 * Set NIC to page 0 registers 2497 */ --- 222 unchanged lines hidden (view full) --- 2720 if (isr & ED_ISR_CNT) { 2721 (void) inb(sc->nic_addr + ED_P0_CNTR0); 2722 (void) inb(sc->nic_addr + ED_P0_CNTR1); 2723 (void) inb(sc->nic_addr + ED_P0_CNTR2); 2724 } 2725 } 2726} 2727 |
2728/* 2729 * Process an ioctl request. This code needs some work - it looks 2730 * pretty ugly. 2731 */ 2732static int 2733ed_ioctl(ifp, command, data) 2734 register struct ifnet *ifp; 2735 u_long command; --- 841 unchanged lines hidden (view full) --- 3577 if (ifma->ifma_addr->sa_family != AF_LINK) 3578 continue; 3579 index = ds_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)) 3580 >> 26; 3581 af[index >> 3] |= 1 << (index & 7); 3582 } 3583} 3584 |
3585static device_method_t ed_isa_methods[] = { 3586 /* Device interface */ 3587 DEVMETHOD(device_probe, ed_isa_probe), 3588 DEVMETHOD(device_attach, ed_isa_attach), |
3589 |
3590 { 0, 0 } |
3591}; 3592 |
3593static driver_t ed_isa_driver = { 3594 "ed", 3595 ed_isa_methods, 3596 sizeof(struct ed_softc) |
3597}; |
3598 |
3599static devclass_t ed_isa_devclass; |
3600 |
3601DRIVER_MODULE(ed, isa, ed_isa_driver, ed_isa_devclass, 0, 0); |