if_ep_isa.c revision 111292
1/* 2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Herb Peyerl. 16 * 4. The name of Herb Peyerl may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * $FreeBSD: head/sys/dev/ep/if_ep_isa.c 111292 2003-02-23 03:39:22Z marcel $ 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/kernel.h> 36#include <sys/socket.h> 37 38#include <sys/module.h> 39#include <sys/bus.h> 40 41#include <machine/bus.h> 42#include <machine/resource.h> 43#include <sys/rman.h> 44 45#include <net/if.h> 46#include <net/if_arp.h> 47#include <net/if_media.h> 48 49#include <isa/isavar.h> 50 51#include <dev/ep/if_epreg.h> 52#include <dev/ep/if_epvar.h> 53 54#ifdef __i386__ 55#include <i386/isa/elink.h> 56#endif 57 58#ifdef __i386__ 59static u_int16_t get_eeprom_data (int, int); 60static void ep_isa_identify (driver_t *, device_t); 61#endif 62static int ep_isa_probe (device_t); 63static int ep_isa_attach (device_t); 64 65struct isa_ident { 66 u_int32_t id; 67 char * name; 68}; 69const char * ep_isa_match_id (u_int32_t, struct isa_ident *); 70 71#define ISA_ID_3C509_XXX 0x0506d509 72#define ISA_ID_3C509_TP 0x506d5090 73#define ISA_ID_3C509_BNC 0x506d5091 74#define ISA_ID_3C509_COMBO 0x506d5094 75#define ISA_ID_3C509_TPO 0x506d5095 76#define ISA_ID_3C509_TPC 0x506d5098 77#ifdef PC98 78#define ISA_ID_3C569B_COMBO 0x506d5694 79#define ISA_ID_3C569B_TPO 0x506d5695 80#endif 81 82#ifdef __i386__ 83static struct isa_ident ep_isa_devs[] = { 84 { ISA_ID_3C509_TP, "3Com 3C509-TP EtherLink III" }, 85 { ISA_ID_3C509_BNC, "3Com 3C509-BNC EtherLink III" }, 86 { ISA_ID_3C509_COMBO, "3Com 3C509-Combo EtherLink III" }, 87 { ISA_ID_3C509_TPO, "3Com 3C509-TPO EtherLink III" }, 88 { ISA_ID_3C509_TPC, "3Com 3C509-TPC EtherLink III" }, 89#ifdef PC98 90 { ISA_ID_3C569B_COMBO, "3Com 3C569B-J-Combo EtherLink III" }, 91 { ISA_ID_3C569B_TPO, "3Com 3C569B-J-TPO EtherLink III" }, 92#endif 93 { 0, NULL }, 94}; 95#endif 96 97static struct isa_pnp_id ep_ids[] = { 98 { 0x90506d50, "3Com 3C509B-TP EtherLink III (PnP)" }, /* TCM5090 */ 99 { 0x91506d50, "3Com 3C509B-BNC EtherLink III (PnP)" },/* TCM5091 */ 100 { 0x94506d50, "3Com 3C509B-Combo EtherLink III (PnP)" },/* TCM5094 */ 101 { 0x95506d50, "3Com 3C509B-TPO EtherLink III (PnP)" },/* TCM5095 */ 102 { 0x98506d50, "3Com 3C509B-TPC EtherLink III (PnP)" },/* TCM5098 */ 103 { 0xf780d041, NULL }, /* PNP80f7 */ 104 { 0, NULL }, 105}; 106 107/* 108 * We get eeprom data from the id_port given an offset into the eeprom. 109 * Basically; after the ID_sequence is sent to all of the cards; they enter 110 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads 111 * the eeprom data. We then read the port 16 times and with every read; the 112 * cards check for contention (ie: if one card writes a 0 bit and another 113 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card 114 * compares the data on the bus; if there is a difference then that card goes 115 * into ID_WAIT state again). In the meantime; one bit of data is returned in 116 * the AX register which is conveniently returned to us by inb(). Hence; we 117 * read 16 times getting one bit of data with each read. 118 */ 119#ifdef __i386__ 120static u_int16_t 121get_eeprom_data(id_port, offset) 122 int id_port; 123 int offset; 124{ 125 int i; 126 u_int16_t data = 0; 127 128 outb(id_port, EEPROM_CMD_RD|offset); 129 DELAY(BIT_DELAY_MULTIPLE * 1000); 130 for (i = 0; i < 16; i++) { 131 DELAY(50); 132 data = (data << 1) | (inw(id_port) & 1); 133 } 134 return (data); 135} 136#endif 137 138const char * 139ep_isa_match_id (id, isa_devs) 140 u_int32_t id; 141 struct isa_ident * isa_devs; 142{ 143 struct isa_ident * i = isa_devs; 144 while(i->name != NULL) { 145 if (id == i->id) 146 return (i->name); 147 i++; 148 } 149 /* 150 * If we see a card that is likely to be a 3c509 151 * return something so that it will work; be annoying 152 * so that the user will tell us about it though. 153 */ 154 if ((id >> 4) == ISA_ID_3C509_XXX) { 155 return ("Unknown 3c509; notify maintainer!"); 156 } 157 return (NULL); 158} 159 160#ifdef __i386__ 161static void 162ep_isa_identify (driver_t *driver, device_t parent) 163{ 164 int tag = EP_LAST_TAG; 165 int found = 0; 166 int i; 167 int j; 168 const char * desc; 169 u_int16_t data; 170 u_int32_t irq; 171 u_int32_t ioport; 172 u_int32_t isa_id; 173 device_t child; 174 175 outb(ELINK_ID_PORT, 0); 176 outb(ELINK_ID_PORT, 0); 177 elink_idseq(ELINK_509_POLY); 178 elink_reset(); 179 180 DELAY(DELAY_MULTIPLE * 10000); 181 182 for (i = 0; i < EP_MAX_BOARDS; i++) { 183 184 outb(ELINK_ID_PORT, 0); 185 outb(ELINK_ID_PORT, 0); 186 elink_idseq(ELINK_509_POLY); 187 DELAY(400); 188 189 /* For the first probe, clear all 190 * board's tag registers. 191 * Otherwise kill off already-found 192 * boards. -- linux 3c509.c 193 */ 194 if (i == 0) { 195 outb(ELINK_ID_PORT, 0xd0); 196 } else { 197 outb(ELINK_ID_PORT, 0xd8); 198 } 199 200 /* Get out of loop if we're out of cards. */ 201 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_MFG_ID); 202 if (data != MFG_ID) { 203 break; 204 } 205 206 /* resolve contention using the Ethernet address */ 207 for (j = 0; j < 3; j++) { 208 (void)get_eeprom_data(ELINK_ID_PORT, j); 209 } 210 211 /* 212 * Construct an 'isa_id' in 'EISA' 213 * format. 214 */ 215 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_MFG_ID); 216 isa_id = (htons(data) << 16); 217 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_PROD_ID); 218 isa_id |= htons(data); 219 220 /* Find known ISA boards */ 221 desc = ep_isa_match_id(isa_id, ep_isa_devs); 222 if (!desc) { 223 if (bootverbose) { 224 device_printf(parent, "if_ep: unknown ID 0x%08x\n", 225 isa_id); 226 } 227 continue; 228 } 229 230 /* Retreive IRQ */ 231 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_RESOURCE_CFG); 232 irq = (data >> 12); 233 234 /* Retreive IOPORT */ 235 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_ADDR_CFG); 236#ifdef PC98 237 ioport = (((data & ADDR_CFG_MASK) * 0x100) + 0x40d0); 238#else 239 ioport = (((data & ADDR_CFG_MASK) << 4) + 0x200); 240#endif 241 242 if ((data & ADDR_CFG_MASK) == ADDR_CFG_EISA) { 243 device_printf(parent, "if_ep: <%s> at port 0x%03x in EISA mode!\n", 244 desc, ioport); 245 /* Set the adaptor tag so that the next card can be found. */ 246 outb(ELINK_ID_PORT, tag--); 247 continue; 248 } 249 250 /* Test for an adapter with PnP support. */ 251 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_CAP); 252 if (data == CAP_ISA) { 253 data = get_eeprom_data(ELINK_ID_PORT, EEPROM_INT_CONFIG_1); 254 if (data & ICW1_IAS_PNP) { 255 if (bootverbose) { 256 device_printf(parent, "if_ep: <%s> at 0x%03x in PnP mode!\n", 257 desc, ioport); 258 } 259 /* Set the adaptor tag so that the next card can be found. */ 260 outb(ELINK_ID_PORT, tag--); 261 continue; 262 } 263 } 264 265 /* Set the adaptor tag so that the next card can be found. */ 266 outb(ELINK_ID_PORT, tag--); 267 268 /* Activate the adaptor at the EEPROM location. */ 269 outb(ELINK_ID_PORT, ACTIVATE_ADAPTER_TO_CONFIG); 270 271 /* Test for an adapter in TEST mode. */ 272 outw(ioport + EP_COMMAND, WINDOW_SELECT | 0); 273 data = inw(ioport + EP_W0_EEPROM_COMMAND); 274 if (data & EEPROM_TST_MODE) { 275 device_printf(parent, "if_ep: <%s> at port 0x%03x in TEST mode! Erase pencil mark.\n", 276 desc, ioport); 277 continue; 278 } 279 280 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "ep", -1); 281 device_set_desc_copy(child, desc); 282 device_set_driver(child, driver); 283 bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1); 284 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, EP_IOSIZE); 285 286 if (bootverbose) { 287 device_printf(parent, "if_ep: <%s> at port 0x%03x-0x%03x irq %d\n", 288 desc, ioport, ioport + EP_IOSIZE, irq); 289 } 290 291 found++; 292 } 293 294 return; 295} 296#endif 297 298static int 299ep_isa_probe (device_t dev) 300{ 301 int error = 0; 302 303 /* Check isapnp ids */ 304 error = ISA_PNP_PROBE(device_get_parent(dev), dev, ep_ids); 305 306 /* If the card had a PnP ID that didn't match any we know about */ 307 if (error == ENXIO) { 308 return (error); 309 } 310 311 /* If we had some other problem. */ 312 if (!(error == 0 || error == ENOENT)) { 313 return (error); 314 } 315 316 /* If we have the resources we need then we're good to go. */ 317 if ((bus_get_resource_start(dev, SYS_RES_IOPORT, 0) != 0) && 318 (bus_get_resource_start(dev, SYS_RES_IRQ, 0) != 0)) { 319 return (0); 320 } 321 322 return (ENXIO); 323} 324 325static int 326ep_isa_attach (device_t dev) 327{ 328 struct ep_softc * sc = device_get_softc(dev); 329 int error = 0; 330 331 if ((error = ep_alloc(dev))) { 332 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 333 goto bad; 334 } 335 336 ep_get_media(sc); 337 338 GO_WINDOW(0); 339 SET_IRQ(BASE, rman_get_start(sc->irq)); 340 341 if ((error = ep_attach(sc))) { 342 device_printf(dev, "ep_attach() failed! (%d)\n", error); 343 goto bad; 344 } 345 346 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 347 sc, &sc->ep_intrhand))) { 348 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 349 goto bad; 350 } 351 352 return (0); 353bad: 354 ep_free(dev); 355 return (error); 356} 357 358static device_method_t ep_isa_methods[] = { 359 /* Device interface */ 360#ifdef __i386__ 361 DEVMETHOD(device_identify, ep_isa_identify), 362#endif 363 DEVMETHOD(device_probe, ep_isa_probe), 364 DEVMETHOD(device_attach, ep_isa_attach), 365 366 { 0, 0 } 367}; 368 369static driver_t ep_isa_driver = { 370 "ep", 371 ep_isa_methods, 372 sizeof(struct ep_softc), 373}; 374 375extern devclass_t ep_devclass; 376 377DRIVER_MODULE(ep, isa, ep_isa_driver, ep_devclass, 0, 0); 378