if_ep_isa.c revision 52549
1220Snever/* 28346Smhaupt * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 3220Snever * All rights reserved. 4220Snever * 5220Snever * Redistribution and use in source and binary forms, with or without 6220Snever * modification, are permitted provided that the following conditions 71472Strims * are met: 8220Snever * 1. Redistributions of source code must retain the above copyright 91472Strims * notice, this list of conditions and the following disclaimer. 10220Snever * 2. Redistributions in binary form must reproduce the above copyright 11220Snever * notice, this list of conditions and the following disclaimer in the 12220Snever * documentation and/or other materials provided with the distribution. 13220Snever * 3. All advertising materials mentioning features or use of this software 14220Snever * must display the following acknowledgement: 15220Snever * This product includes software developed by Herb Peyerl. 16220Snever * 4. The name of Herb Peyerl may not be used to endorse or promote products 17220Snever * derived from this software without specific prior written permission. 18220Snever * 19220Snever * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20220Snever * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 211472Strims * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 221472Strims * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 231472Strims * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24220Snever * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25220Snever * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26220Snever * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27220Snever * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28220Snever * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29220Snever * 30220Snever * $FreeBSD: head/sys/dev/ep/if_ep_isa.c 52549 1999-10-27 06:25:16Z mdodd $ 31220Snever */ 32220Snever 33220Snever#include <sys/param.h> 34220Snever#include <sys/systm.h> 35220Snever#include <sys/kernel.h> 36220Snever#include <sys/socket.h> 37220Snever 38220Snever#include <sys/module.h> 39220Snever#include <sys/bus.h> 408346Smhaupt 41220Snever#include <machine/bus.h> 428346Smhaupt#include <machine/resource.h> 43220Snever#include <sys/rman.h> 44220Snever 45220Snever#include <net/if.h> 46220Snever#include <net/if_arp.h> 47220Snever#include <net/if_media.h> 48220Snever 49220Snever#include <machine/clock.h> 50 51#include <isa/isavar.h> 52#include <isa/pnpvar.h> 53 54#include <dev/ep/if_epreg.h> 55#include <dev/ep/if_epvar.h> 56#include <i386/isa/elink.h> 57 58static int get_eeprom_data (int, int); 59 60static void ep_isa_identify (driver_t *, device_t); 61static int ep_isa_probe (device_t); 62static int ep_isa_attach (device_t); 63 64struct isa_ident { 65 u_int32_t id; 66 char * name; 67}; 68const char * ep_isa_match_id (u_int32_t, struct isa_ident *); 69 70#define ISA_ID_3C509_TP 0x506d5090 71#define ISA_ID_3C509_BNC 0x506d5091 72#define ISA_ID_3C509_COMBO 0x506d5094 73#define ISA_ID_3C509_TPO 0x506d5095 74 75static struct isa_ident ep_isa_devs[] = { 76 { ISA_ID_3C509_TP, "3Com EtherLink III (3c509-TP)" }, 77 { ISA_ID_3C509_BNC, "3Com EtherLink III (3c509-BNC)" }, 78 { ISA_ID_3C509_COMBO, "3Com EtherLink III (3c509-Combo)" }, 79 { ISA_ID_3C509_TPO, "3Com EtherLink III (3c509-TPO)" }, 80 { 0, NULL }, 81}; 82 83static struct isa_pnp_id ep_ids[] = { 84 { 0x90506d50, NULL }, /* TCM5090 */ 85 { 0x91506d50, NULL }, /* TCM5091 */ 86 { 0x94506d50, NULL }, /* TCM5094 */ 87 { 0x95506d50, NULL }, /* TCM5095 */ 88 { 0xf780d041, NULL }, /* PNP80f7 */ 89 { 0, NULL }, 90}; 91 92/* 93 * We get eeprom data from the id_port given an offset into the eeprom. 94 * Basically; after the ID_sequence is sent to all of the cards; they enter 95 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads 96 * the eeprom data. We then read the port 16 times and with every read; the 97 * cards check for contention (ie: if one card writes a 0 bit and another 98 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card 99 * compares the data on the bus; if there is a difference then that card goes 100 * into ID_WAIT state again). In the meantime; one bit of data is returned in 101 * the AX register which is conveniently returned to us by inb(). Hence; we 102 * read 16 times getting one bit of data with each read. 103 */ 104 105static int 106get_eeprom_data(id_port, offset) 107 int id_port; 108 int offset; 109{ 110 int i, data = 0; 111 outb(id_port, 0x80 + offset); 112 for (i = 0; i < 16; i++) { 113 DELAY(BIT_DELAY_MULTIPLE * 1000); 114 data = (data << 1) | (inw(id_port) & 1); 115 } 116 return (data); 117} 118 119const char * 120ep_isa_match_id (id, isa_devs) 121 u_int32_t id; 122 struct isa_ident * isa_devs; 123{ 124 struct isa_ident * i = isa_devs; 125 while(i->name != NULL) { 126 if (id == i->id) 127 return (i->name); 128 i++; 129 } 130 return (NULL); 131} 132 133static void 134ep_isa_identify (driver_t *driver, device_t parent) 135{ 136 int tag = EP_LAST_TAG; 137 int found = 0; 138 int i; 139 int j; 140 const char * desc; 141 u_int32_t data; 142 u_int32_t irq; 143 u_int32_t ioport; 144 u_int32_t isa_id; 145 device_t child; 146 147 outb(ELINK_ID_PORT, 0); 148 outb(ELINK_ID_PORT, 0); 149 150 elink_idseq(ELINK_509_POLY); 151 elink_reset(); 152 153 DELAY(DELAY_MULTIPLE * 10000); 154 155 for (i = 0; i < EP_MAX_BOARDS; i++) { 156 157 outb(ELINK_ID_PORT, 0); 158 outb(ELINK_ID_PORT, 0); 159 elink_idseq(0xCF); 160 161 /* For the first probe, clear all 162 * board's tag registers. 163 * Otherwise kill off already-found 164 * boards. -- linux 3c509.c 165 */ 166 if (i == 0) { 167 outb(ELINK_ID_PORT, 0xd0); 168 } else { 169 outb(ELINK_ID_PORT, 0xd8); 170 } 171 172 /* 173 * Construct an 'isa_id' in 'EISA' 174 * format. 175 */ 176 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_MFG_ID); 177 isa_id = (htons(data) << 16); 178 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_PROD_ID); 179 isa_id |= htons(data); 180 181 /* Find known ISA boards */ 182 desc = ep_isa_match_id(isa_id, ep_isa_devs); 183 if (!desc) { 184 if (bootverbose) { 185 device_printf(parent, "if_ep: unknown ID 0x%08x\n", 186 isa_id); 187 } 188 break; 189 } 190 191 /* resolve contention using the Ethernet address */ 192 for (j = 0; j < 3; j++) { 193 get_eeprom_data(ELINK_ID_PORT, j); 194 } 195 196 /* Retreive IRQ */ 197 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_RESOURCE_CFG); 198 irq = (data >> 12); 199 200 /* Retreive IOPORT */ 201 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_ADDR_CFG); 202#ifdef PC98 203 ioport = ((data * 0x100) + 0x40d0); 204#else 205 ioport = ((data << 4) + 0x200); 206#endif 207 208 /* Set the adaptor tag so that the next card can be found. */ 209 outb(ELINK_ID_PORT, tag--); 210 211 /* Activate the adaptor at the EEPROM location. */ 212 outb(ELINK_ID_PORT, ((ioport >> 4) | 0xe0)); 213 214 /* Test for an adapter in PnP mode */ 215 data = inw(ioport + EP_W0_EEPROM_COMMAND); 216 if (data & EEPROM_TST_MODE) { 217 device_printf(parent, "if_ep: Adapter at 0x%03x in PnP mode!\n", 218 ioport); 219 continue; 220 } 221 222 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "ep", -1); 223 device_set_desc_copy(child, desc); 224 device_set_driver(child, driver); 225 bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1); 226 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, EP_IOSIZE); 227 228 if (bootverbose) { 229 device_printf(parent, "if_ep: <%s> at port 0x%03x-0x%03x irq %d\n", 230 desc, ioport, ioport + EP_IOSIZE, irq); 231 } 232 233 found++; 234 } 235 236 return; 237} 238 239static int 240ep_isa_probe (device_t dev) 241{ 242 int error = 0; 243 244 /* Check isapnp ids */ 245 error = ISA_PNP_PROBE(device_get_parent(dev), dev, ep_ids); 246 247 /* If the card had a PnP ID that didn't match any we know about */ 248 if (error == ENXIO) { 249 return (error); 250 } 251 252 /* If we had some other problem. */ 253 if (!(error == 0 || error == ENOENT)) { 254 return (error); 255 } 256 257 /* If we have the resources we need then we're good to go. */ 258 if ((bus_get_resource_start(dev, SYS_RES_IOPORT, 0) != 0) && 259 (bus_get_resource_start(dev, SYS_RES_IRQ, 0) != 0)) { 260 return (0); 261 } 262 263 return (ENXIO); 264} 265 266static int 267ep_isa_attach (device_t dev) 268{ 269 struct ep_softc * sc = device_get_softc(dev); 270 int error = 0; 271 272 if ((error = ep_alloc(dev))) { 273 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 274 goto bad; 275 } 276 277 ep_get_media(sc); 278 279 GO_WINDOW(0); 280 SET_IRQ(BASE, rman_get_start(sc->irq)); 281 282 if ((error = ep_attach(sc))) { 283 device_printf(dev, "ep_attach() failed! (%d)\n", error); 284 goto bad; 285 } 286 287 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 288 sc, &sc->ep_intrhand))) { 289 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 290 goto bad; 291 } 292 293 return (0); 294bad: 295 ep_free(dev); 296 return (error); 297} 298 299static device_method_t ep_isa_methods[] = { 300 /* Device interface */ 301 DEVMETHOD(device_identify, ep_isa_identify), 302 DEVMETHOD(device_probe, ep_isa_probe), 303 DEVMETHOD(device_attach, ep_isa_attach), 304 305 { 0, 0 } 306}; 307 308static driver_t ep_isa_driver = { 309 "ep", 310 ep_isa_methods, 311 sizeof(struct ep_softc), 312}; 313 314extern devclass_t ep_devclass; 315 316DRIVER_MODULE(ep, isa, ep_isa_driver, ep_devclass, 0, 0); 317