1 /* $NetBSD: if_ne_neptune.c,v 1.15 2008/04/28 20:23:39 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: if_ne_neptune.c,v 1.15 2008/04/28 20:23:39 martin Exp $"); 35 36 #include "opt_inet.h" 37 #include "opt_ns.h" 38 #include "bpfilter.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/mbuf.h> 43 #include <sys/socket.h> 44 #include <sys/ioctl.h> 45 #include <sys/errno.h> 46 #include <sys/syslog.h> 47 #include <sys/select.h> 48 #include <sys/device.h> 49 50 #include <net/if.h> 51 #include <net/if_dl.h> 52 #include <net/if_ether.h> 53 #include <net/if_media.h> 54 55 #ifdef INET 56 #include <netinet/in.h> 57 #include <netinet/in_systm.h> 58 #include <netinet/in_var.h> 59 #include <netinet/ip.h> 60 #include <netinet/if_inarp.h> 61 #endif 62 63 #ifdef NS 64 #include <netns/ns.h> 65 #include <netns/ns_if.h> 66 #endif 67 68 #if NBPFILTER > 0 69 #include <net/bpf.h> 70 #include <net/bpfdesc.h> 71 #endif 72 73 #include <machine/bus.h> 74 75 #include <dev/ic/dp8390reg.h> 76 #include <dev/ic/dp8390var.h> 77 78 #include <dev/ic/ne2000reg.h> 79 #include <dev/ic/ne2000var.h> 80 81 #include <dev/ic/rtl80x9reg.h> 82 #include <dev/ic/rtl80x9var.h> 83 84 #include <arch/x68k/dev/neptunevar.h> 85 86 static int ne_neptune_match(device_t, cfdata_t, void *); 87 static void ne_neptune_attach(device_t, device_t, void *); 88 static int ne_neptune_intr(void *); 89 90 #define ne_neptune_softc ne2000_softc 91 92 CFATTACH_DECL(ne_neptune, sizeof(struct ne_neptune_softc), 93 ne_neptune_match, ne_neptune_attach, NULL, NULL); 94 95 int 96 ne_neptune_match(device_t parent, cfdata_t match, void *aux) 97 { 98 struct neptune_attach_args *na = aux; 99 bus_space_tag_t nict = na->na_bst; 100 bus_space_handle_t nich; 101 bus_space_tag_t asict; 102 bus_space_handle_t asich; 103 int rv = 0; 104 105 if (na->na_addr == NEPTUNECF_ADDR_DEFAULT) 106 na->na_addr = 0x300; 107 108 /* Make sure this is a valid NE[12]000 i/o address. */ 109 if ((na->na_addr & 0x1f) != 0) 110 return (0); 111 112 /* Map i/o space. */ 113 if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich)) 114 return (0); 115 116 asict = nict; 117 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, 118 NE2000_ASIC_NPORTS*2, &asich)) 119 goto out; 120 121 /* Look for an NE2000-compatible card. */ 122 rv = ne2000_detect(nict, nich, asict, asich); 123 124 out: 125 bus_space_unmap(nict, nich, NE2000_NPORTS); 126 return (rv); 127 } 128 129 void 130 ne_neptune_attach(device_t parent, device_t self, void *aux) 131 { 132 struct ne_neptune_softc *nsc = device_private(self); 133 struct dp8390_softc *dsc = &nsc->sc_dp8390; 134 struct neptune_attach_args *na = aux; 135 bus_space_tag_t nict = na->na_bst; 136 bus_space_handle_t nich; 137 bus_space_tag_t asict = nict; 138 bus_space_handle_t asich; 139 const char *typestr; 140 int netype; 141 142 dsc->sc_dev = self; 143 aprint_normal("\n"); 144 145 /* Map i/o space. */ 146 if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich)) { 147 aprint_error_dev(self, "can't map i/o space\n"); 148 return; 149 } 150 151 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, 152 NE2000_ASIC_NPORTS*2, &asich)) { 153 aprint_error_dev(self, "can't subregion i/o space\n"); 154 return; 155 } 156 157 dsc->sc_regt = nict; 158 dsc->sc_regh = nich; 159 160 nsc->sc_asict = asict; 161 nsc->sc_asich = asich; 162 163 /* 164 * Detect it again, so we can print some information about the 165 * interface. 166 */ 167 netype = ne2000_detect(nict, nich, asict, asich); 168 switch (netype) { 169 case NE2000_TYPE_NE1000: 170 typestr = "NE1000"; 171 break; 172 173 case NE2000_TYPE_NE2000: 174 typestr = "NE2000"; 175 /* 176 * Check for a Realtek 8019. 177 */ 178 bus_space_write_1(nict, nich, ED_P0_CR, 179 ED_CR_PAGE_0 | ED_CR_STP); 180 if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) == 181 RTL0_8019ID0 && 182 bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) == 183 RTL0_8019ID1) { 184 typestr = "NE2000 (RTL8019)"; 185 dsc->sc_mediachange = rtl80x9_mediachange; 186 dsc->sc_mediastatus = rtl80x9_mediastatus; 187 dsc->init_card = rtl80x9_init_card; 188 dsc->sc_media_init = rtl80x9_media_init; 189 } 190 break; 191 192 default: 193 aprint_error_dev(self, "where did the card go?!\n"); 194 return; 195 } 196 197 aprint_normal_dev(self, "%s Ethernet\n", typestr); 198 199 /* This interface is always enabled. */ 200 dsc->sc_enabled = 1; 201 202 /* 203 * Do generic NE2000 attach. This will read the station address 204 * from the EEPROM. 205 */ 206 ne2000_attach(nsc, NULL); 207 208 /* Establish the interrupt handler. */ 209 if (neptune_intr_establish(na->na_intr, "ne", ne_neptune_intr, dsc)) 210 aprint_error_dev(self, 211 "couldn't establish interrupt handler\n"); 212 } 213 214 static int 215 ne_neptune_intr(void *arg) 216 { 217 spl4(); /* XXX */ 218 return dp8390_intr(arg); 219 } 220