1 /* $NetBSD: if_ne_zbus.c,v 1.9 2002/01/28 09:56:59 aymeric 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 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: if_ne_zbus.c,v 1.9 2002/01/28 09:56:59 aymeric Exp $"); 41 42 /* 43 * Thanks to Village Tronic for giving me a card. 44 * Bernd Ernesti 45 */ 46 47 #include <sys/param.h> 48 #include <sys/device.h> 49 #include <sys/malloc.h> 50 #include <sys/mbuf.h> 51 #include <sys/socket.h> 52 #include <sys/syslog.h> 53 #include <sys/systm.h> 54 55 #include <net/if.h> 56 #include <net/if_media.h> 57 #include <net/if_ether.h> 58 59 #include <machine/bus.h> 60 61 #include <dev/ic/dp8390reg.h> 62 #include <dev/ic/dp8390var.h> 63 64 #include <dev/ic/ne2000reg.h> 65 #include <dev/ic/ne2000var.h> 66 67 #include <dev/ic/rtl80x9reg.h> 68 #include <dev/ic/rtl80x9var.h> 69 70 #include <amiga/amiga/device.h> 71 #include <amiga/amiga/isr.h> 72 73 #include <amiga/dev/zbusvar.h> 74 75 int ne_zbus_match(struct device *, struct cfdata *, void *); 76 void ne_zbus_attach(struct device *, struct device *, void *); 77 78 struct ne_zbus_softc { 79 struct ne2000_softc sc_ne2000; 80 struct bus_space_tag sc_bst; 81 struct isr sc_isr; 82 }; 83 84 struct cfattach ne_zbus_ca = { 85 sizeof(struct ne_zbus_softc), ne_zbus_match, ne_zbus_attach 86 }; 87 88 /* 89 * The Amiga address are shifted by one bit to the ISA-Bus, but 90 * this is handled by the bus_space functions. 91 */ 92 #define NE_ARIADNE_II_NPORTS 0x20 93 #define NE_ARIADNE_II_NICBASE 0x0300 /* 0x0600 */ 94 #define NE_ARIADNE_II_NICSIZE 0x10 95 #define NE_ARIADNE_II_ASICBASE 0x0310 /* 0x0620 */ 96 #define NE_ARIADNE_II_ASICSIZE 0x10 97 98 int 99 ne_zbus_match(struct device *parent, struct cfdata *cf, 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(struct device *parent, struct device *self, void *aux) 119 { 120 struct ne_zbus_softc *zsc = (struct ne_zbus_softc *)self; 121 struct ne2000_softc *nsc = &zsc->sc_ne2000; 122 struct dp8390_softc *dsc = &nsc->sc_dp8390; 123 struct zbus_args *zap = aux; 124 bus_space_tag_t nict = &zsc->sc_bst; 125 bus_space_handle_t nich; 126 bus_space_tag_t asict = nict; 127 bus_space_handle_t asich; 128 129 dsc->sc_mediachange = rtl80x9_mediachange; 130 dsc->sc_mediastatus = rtl80x9_mediastatus; 131 dsc->init_card = rtl80x9_init_card; 132 dsc->sc_media_init = rtl80x9_media_init; 133 134 zsc->sc_bst.base = (u_long)zap->va + 0; 135 if (zap->manid == 4626) 136 zsc->sc_bst.base += 0x8000; 137 138 zsc->sc_bst.absm = &amiga_bus_stride_2; 139 140 printf("\n"); 141 142 /* Map i/o space. */ 143 if (bus_space_map(nict, NE_ARIADNE_II_NICBASE, NE_ARIADNE_II_NPORTS, 0, &nich)) { 144 printf("%s: can't map nic i/o space\n", dsc->sc_dev.dv_xname); 145 return; 146 } 147 148 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, NE_ARIADNE_II_ASICSIZE, 149 &asich)) { 150 printf("%s: can't map asic i/o space\n", dsc->sc_dev.dv_xname); 151 return; 152 } 153 154 dsc->sc_regt = nict; 155 dsc->sc_regh = nich; 156 157 nsc->sc_asict = asict; 158 nsc->sc_asich = asich; 159 160 /* This interface is always enabled. */ 161 dsc->sc_enabled = 1; 162 163 /* 164 * Do generic NE2000 attach. This will read the station address 165 * from the EEPROM. 166 */ 167 ne2000_attach(nsc, NULL); 168 169 zsc->sc_isr.isr_intr = dp8390_intr; 170 zsc->sc_isr.isr_arg = dsc; 171 zsc->sc_isr.isr_ipl = 2; 172 add_isr(&zsc->sc_isr); 173 } 174