1 /* $NetBSD: if_ne_zbus.c,v 1.6 2000/12/29 22:39:29 is Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Bernd Ernesti. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Thanks to Village Tronic for giving me a card. 41 * Bernd Ernesti 42 */ 43 44 #include <sys/param.h> 45 #include <sys/device.h> 46 #include <sys/malloc.h> 47 #include <sys/mbuf.h> 48 #include <sys/socket.h> 49 #include <sys/syslog.h> 50 #include <sys/systm.h> 51 52 #include <net/if.h> 53 #include <net/if_media.h> 54 #include <net/if_ether.h> 55 56 #include <machine/bus.h> 57 58 #include <dev/ic/dp8390reg.h> 59 #include <dev/ic/dp8390var.h> 60 61 #include <dev/ic/ne2000reg.h> 62 #include <dev/ic/ne2000var.h> 63 64 #include <dev/ic/rtl80x9reg.h> 65 #include <dev/ic/rtl80x9var.h> 66 67 #include <amiga/amiga/device.h> 68 #include <amiga/amiga/isr.h> 69 70 #include <amiga/dev/zbusvar.h> 71 72 int ne_zbus_match __P((struct device *, struct cfdata *, void *)); 73 void ne_zbus_attach __P((struct device *, struct device *, void *)); 74 75 struct ne_zbus_softc { 76 struct ne2000_softc sc_ne2000; 77 struct bus_space_tag sc_bst; 78 struct isr sc_isr; 79 }; 80 81 struct cfattach ne_zbus_ca = { 82 sizeof(struct ne_zbus_softc), ne_zbus_match, ne_zbus_attach 83 }; 84 85 /* 86 * The Amiga address are shifted by one bit to the ISA-Bus, but 87 * this is handled by the bus_space functions. 88 */ 89 #define NE_ARIADNE_II_NPORTS 0x20 90 #define NE_ARIADNE_II_NICBASE 0x0300 /* 0x0600 */ 91 #define NE_ARIADNE_II_NICSIZE 0x10 92 #define NE_ARIADNE_II_ASICBASE 0x0310 /* 0x0620 */ 93 #define NE_ARIADNE_II_ASICSIZE 0x10 94 95 int 96 ne_zbus_match(parent, cf, aux) 97 struct device *parent; 98 struct cfdata *cf; 99 void *aux; 100 { 101 struct zbus_args *zap = aux; 102 103 /* Ariadne II ethernet card */ 104 if (zap->manid == 2167 && zap->prodid == 202) 105 return (1); 106 107 /* X-surf ethernet card */ 108 if (zap->manid == 4626 && zap->prodid == 23) 109 return (1); 110 111 return (0); 112 } 113 114 /* 115 * Install interface into kernel networking data structures 116 */ 117 void 118 ne_zbus_attach(parent, self, aux) 119 struct device *parent, *self; 120 void *aux; 121 { 122 struct ne_zbus_softc *zsc = (struct ne_zbus_softc *)self; 123 struct ne2000_softc *nsc = &zsc->sc_ne2000; 124 struct dp8390_softc *dsc = &nsc->sc_dp8390; 125 struct zbus_args *zap = aux; 126 bus_space_tag_t nict = &zsc->sc_bst; 127 bus_space_handle_t nich; 128 bus_space_tag_t asict = nict; 129 bus_space_handle_t asich; 130 int *media, nmedia, defmedia; 131 132 media = NULL; 133 nmedia = defmedia = 0; 134 135 dsc->sc_mediachange = rtl80x9_mediachange; 136 dsc->sc_mediastatus = rtl80x9_mediastatus; 137 dsc->init_card = rtl80x9_init_card; 138 139 zsc->sc_bst.base = (u_long)zap->va + 0; 140 if (zap->manid == 4626) 141 zsc->sc_bst.base += 0x8000; 142 143 zsc->sc_bst.absm = &amiga_bus_stride_2; 144 145 printf("\n"); 146 147 /* Map i/o space. */ 148 if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) { 149 printf("%s: can't map nic i/o space\n", dsc->sc_dev.dv_xname); 150 return; 151 } 152 153 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE, 154 &asich)) { 155 printf("%s: can't map asic i/o space\n", dsc->sc_dev.dv_xname); 156 return; 157 } 158 159 dsc->sc_regt = nict; 160 dsc->sc_regh = nich; 161 162 nsc->sc_asict = asict; 163 nsc->sc_asich = asich; 164 165 /* Initialize media. */ 166 rtl80x9_init_media(dsc, &media, &nmedia, &defmedia); 167 168 /* This interface is always enabled. */ 169 dsc->sc_enabled = 1; 170 171 /* 172 * Do generic NE2000 attach. This will read the station address 173 * from the EEPROM. 174 */ 175 ne2000_attach(nsc, NULL, media, nmedia, defmedia); 176 177 zsc->sc_isr.isr_intr = dp8390_intr; 178 zsc->sc_isr.isr_arg = dsc; 179 zsc->sc_isr.isr_ipl = 2; 180 add_isr(&zsc->sc_isr); 181 } 182