1 1.36 thorpej /* $NetBSD: if_ef.c,v 1.36 2022/07/12 02:03:57 thorpej Exp $ */ 2 1.1 pk 3 1.1 pk /*- 4 1.1 pk * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 1.1 pk * All rights reserved. 6 1.1 pk * 7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation 8 1.1 pk * by Rafal K. Boni. 9 1.1 pk * 10 1.1 pk * Redistribution and use in source and binary forms, with or without 11 1.1 pk * modification, are permitted provided that the following conditions 12 1.1 pk * are met: 13 1.1 pk * 1. Redistributions of source code must retain the above copyright 14 1.1 pk * notice, this list of conditions and the following disclaimer. 15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 pk * notice, this list of conditions and the following disclaimer in the 17 1.1 pk * documentation and/or other materials provided with the distribution. 18 1.1 pk * 19 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 pk * POSSIBILITY OF SUCH DAMAGE. 30 1.1 pk */ 31 1.10 lukem 32 1.10 lukem #include <sys/cdefs.h> 33 1.36 thorpej __KERNEL_RCSID(0, "$NetBSD: if_ef.c,v 1.36 2022/07/12 02:03:57 thorpej Exp $"); 34 1.1 pk 35 1.1 pk #include <sys/param.h> 36 1.1 pk #include <sys/systm.h> 37 1.1 pk #include <sys/mbuf.h> 38 1.1 pk #include <sys/errno.h> 39 1.1 pk #include <sys/device.h> 40 1.1 pk #include <sys/protosw.h> 41 1.1 pk #include <sys/socket.h> 42 1.1 pk 43 1.1 pk #include <net/if.h> 44 1.1 pk #include <net/if_dl.h> 45 1.1 pk #include <net/if_types.h> 46 1.1 pk #include <net/if_media.h> 47 1.1 pk #include <net/if_ether.h> 48 1.1 pk 49 1.24 ad #include <sys/cpu.h> 50 1.24 ad #include <sys/bus.h> 51 1.24 ad #include <sys/intr.h> 52 1.1 pk 53 1.1 pk #include <dev/isa/isareg.h> 54 1.1 pk #include <dev/isa/isavar.h> 55 1.1 pk 56 1.1 pk #include <dev/ic/i82586reg.h> 57 1.1 pk #include <dev/ic/i82586var.h> 58 1.1 pk #include <dev/isa/if_efreg.h> 59 1.1 pk #include <dev/isa/elink.h> 60 1.1 pk 61 1.1 pk #ifdef EF_DEBUG 62 1.1 pk #define DPRINTF(x) printf x 63 1.1 pk #else 64 1.2 pk #define DPRINTF(x) 65 1.1 pk #endif 66 1.1 pk 67 1.1 pk struct ef_softc { 68 1.1 pk struct ie_softc sc_ie; 69 1.1 pk 70 1.1 pk bus_space_tag_t sc_regt; /* space tag for registers */ 71 1.1 pk bus_space_handle_t sc_regh; /* space handle for registers */ 72 1.1 pk 73 1.1 pk void* sc_ih; /* interrupt handle */ 74 1.1 pk 75 1.32 msaitoh uint8_t card_rev; /* hardware revision */ 76 1.32 msaitoh uint8_t card_type; /* card model -- AUI/BNC or TP */ 77 1.1 pk }; 78 1.1 pk 79 1.32 msaitoh static int ef_media[] = { 80 1.1 pk IFM_ETHER | IFM_10_5, 81 1.1 pk IFM_ETHER | IFM_10_2, 82 1.1 pk }; 83 1.34 msaitoh #define NEF_MEDIA __arraycount(ef_media) 84 1.1 pk 85 1.32 msaitoh static int eftp_media[] = { 86 1.1 pk IFM_ETHER | IFM_10_T, 87 1.1 pk }; 88 1.34 msaitoh #define NEFTP_MEDIA __arraycount(eftp_media) 89 1.1 pk 90 1.1 pk /* Routines required by the MI i82586 driver API */ 91 1.34 msaitoh static void ef_reset(struct ie_softc *, int); 92 1.34 msaitoh static void ef_hwinit(struct ie_softc *); 93 1.34 msaitoh static void ef_atten(struct ie_softc *, int); 94 1.34 msaitoh static int ef_intrhook(struct ie_softc *, int); 95 1.18 perry 96 1.18 perry static void ef_copyin(struct ie_softc *, void *, int, size_t); 97 1.18 perry static void ef_copyout(struct ie_softc *, const void *, int, size_t); 98 1.18 perry 99 1.32 msaitoh static uint16_t ef_read_16(struct ie_softc *, int); 100 1.32 msaitoh static void ef_write_16(struct ie_softc *, int, uint16_t); 101 1.18 perry static void ef_write_24(struct ie_softc *, int, int); 102 1.1 pk 103 1.18 perry static void ef_mediastatus(struct ie_softc *, struct ifmediareq *); 104 1.1 pk 105 1.1 pk /* Local routines */ 106 1.34 msaitoh static int ef_port_check(bus_space_tag_t, bus_space_handle_t); 107 1.1 pk 108 1.32 msaitoh static int ef_match(device_t, cfdata_t, void *); 109 1.32 msaitoh static void ef_attach(device_t, device_t, void *); 110 1.1 pk 111 1.1 pk /* 112 1.1 pk * This keeps track of which ISAs have been through an ie probe sequence. 113 1.1 pk * A simple static variable isn't enough, since it's conceivable that 114 1.1 pk * a system might have more than one ISA bus. 115 1.1 pk * 116 1.1 pk * The "isa_bus" member is a pointer to the parent ISA bus device struct 117 1.2 pk * which will unique per ISA bus. 118 1.1 pk */ 119 1.1 pk 120 1.34 msaitoh #define MAXCARDS_PER_ISABUS 8 /* If you have more than 8, you lose */ 121 1.1 pk 122 1.1 pk struct ef_isabus { 123 1.2 pk LIST_ENTRY(ef_isabus) isa_link; 124 1.30 cegger device_t isa_bus; 125 1.1 pk 126 1.2 pk int bus_state; 127 1.1 pk 128 1.2 pk struct card { 129 1.2 pk bus_addr_t iobase; 130 1.2 pk bus_addr_t maddr; 131 1.2 pk bus_size_t msize; 132 1.2 pk int irq; 133 1.2 pk int available; 134 1.2 pk } isa_cards[MAXCARDS_PER_ISABUS]; 135 1.1 pk }; 136 1.1 pk 137 1.1 pk static LIST_HEAD(, ef_isabus) ef_isa_buses; 138 1.1 pk static int ef_isa_buses_inited; 139 1.1 pk 140 1.1 pk static void 141 1.32 msaitoh ef_card_add(struct ef_isabus *bus, bus_addr_t iobase, bus_addr_t maddr, 142 1.32 msaitoh bus_size_t msiz, int irq) 143 1.1 pk { 144 1.2 pk int idx; 145 1.1 pk 146 1.33 msaitoh DPRINTF(("Adding 3c507 at 0x%x, IRQ %d, Mem 0x%lx/%zu\n", 147 1.19 christos (u_int) iobase, irq, (u_long) maddr, msiz)); 148 1.1 pk 149 1.2 pk for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) { 150 1.2 pk if (bus->isa_cards[idx].available == 0) { 151 1.2 pk bus->isa_cards[idx].iobase = iobase; 152 1.2 pk bus->isa_cards[idx].maddr = maddr; 153 1.19 christos bus->isa_cards[idx].msize = msiz; 154 1.2 pk bus->isa_cards[idx].irq = irq; 155 1.2 pk bus->isa_cards[idx].available = 1; 156 1.2 pk break; 157 1.2 pk } 158 1.2 pk } 159 1.1 pk } 160 1.1 pk 161 1.1 pk /* 162 1.1 pk * 3C507 support routines 163 1.1 pk */ 164 1.1 pk static void 165 1.27 dsl ef_reset(struct ie_softc *sc, int why) 166 1.1 pk { 167 1.32 msaitoh struct ef_softc *esc = (struct ef_softc *)sc; 168 1.1 pk 169 1.2 pk switch (why) { 170 1.2 pk case CHIP_PROBE: 171 1.32 msaitoh /* Reset to chip to see if it responds */ 172 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, 173 1.2 pk EF_CTRL, EF_CTRL_RESET); 174 1.2 pk DELAY(100); 175 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, 176 1.2 pk EF_CTRL, EF_CTRL_NORMAL); 177 1.2 pk DELAY(100); 178 1.2 pk break; 179 1.2 pk 180 1.2 pk case CARD_RESET: 181 1.2 pk /* 182 1.32 msaitoh * This takes around 10sec, and we can get 183 1.2 pk * by quite well w/out it... 184 1.2 pk */ 185 1.2 pk break; 186 1.2 pk } 187 1.1 pk } 188 1.1 pk 189 1.1 pk static void 190 1.23 christos ef_atten(struct ie_softc *sc, int why) 191 1.1 pk { 192 1.32 msaitoh struct ef_softc *esc = (struct ef_softc *)sc; 193 1.32 msaitoh 194 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ATTN, 1); 195 1.1 pk } 196 1.1 pk 197 1.1 pk static void 198 1.27 dsl ef_hwinit(struct ie_softc *sc) 199 1.1 pk { 200 1.32 msaitoh struct ef_softc *esc = (struct ef_softc *)sc; 201 1.32 msaitoh 202 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1); 203 1.1 pk } 204 1.1 pk 205 1.1 pk static int 206 1.27 dsl ef_intrhook(struct ie_softc *sc, int where) 207 1.1 pk { 208 1.2 pk unsigned char cr; 209 1.32 msaitoh struct ef_softc *esc = (struct ef_softc *)sc; 210 1.1 pk 211 1.2 pk switch (where) { 212 1.2 pk case INTR_ENTER: 213 1.32 msaitoh /* Entering ISR: disable, ack card interrupts */ 214 1.2 pk cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL); 215 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, 216 1.32 msaitoh cr & ~EF_CTRL_IEN); 217 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1); 218 1.2 pk break; 219 1.2 pk 220 1.2 pk case INTR_EXIT: 221 1.32 msaitoh /* Exiting ISR: re-enable card interrupts */ 222 1.2 pk cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL); 223 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, 224 1.32 msaitoh cr | EF_CTRL_IEN); 225 1.2 pk break; 226 1.2 pk 227 1.2 pk case INTR_LOOP: 228 1.32 msaitoh /* Looping in ISR: ack new interrupts */ 229 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1); 230 1.2 pk break; 231 1.1 pk } 232 1.1 pk 233 1.1 pk return 1; 234 1.1 pk } 235 1.1 pk 236 1.32 msaitoh static uint16_t 237 1.32 msaitoh ef_read_16(struct ie_softc *sc, int offset) 238 1.1 pk { 239 1.32 msaitoh 240 1.1 pk return bus_space_read_2(sc->bt, sc->bh, offset); 241 1.1 pk } 242 1.1 pk 243 1.2 pk static void 244 1.32 msaitoh ef_copyin(struct ie_softc *sc, void *dst, int offset, size_t size) 245 1.1 pk { 246 1.2 pk int dribble; 247 1.32 msaitoh uint8_t *bptr = dst; 248 1.1 pk 249 1.2 pk if (offset % 2) { 250 1.2 pk *bptr = bus_space_read_1(sc->bt, sc->bh, offset); 251 1.2 pk offset++; bptr++; size--; 252 1.2 pk } 253 1.1 pk 254 1.2 pk dribble = size % 2; 255 1.32 msaitoh bus_space_read_region_2(sc->bt, sc->bh, offset, (uint16_t *) bptr, 256 1.32 msaitoh size >> 1); 257 1.2 pk 258 1.2 pk if (dribble) { 259 1.2 pk bptr += size - 1; 260 1.2 pk offset += size - 1; 261 1.2 pk *bptr = bus_space_read_1(sc->bt, sc->bh, offset); 262 1.2 pk } 263 1.1 pk } 264 1.1 pk 265 1.2 pk static void 266 1.32 msaitoh ef_copyout(struct ie_softc *sc, const void *src, int offset, size_t size) 267 1.1 pk { 268 1.2 pk int dribble; 269 1.32 msaitoh const uint8_t *bptr = src; 270 1.2 pk 271 1.2 pk if (offset % 2) { 272 1.2 pk bus_space_write_1(sc->bt, sc->bh, offset, *bptr); 273 1.2 pk offset++; bptr++; size--; 274 1.2 pk } 275 1.1 pk 276 1.2 pk dribble = size % 2; 277 1.19 christos bus_space_write_region_2(sc->bt, sc->bh, offset, 278 1.32 msaitoh (const uint16_t *)bptr, size >> 1); 279 1.2 pk if (dribble) { 280 1.2 pk bptr += size - 1; 281 1.2 pk offset += size - 1; 282 1.2 pk bus_space_write_1(sc->bt, sc->bh, offset, *bptr); 283 1.2 pk } 284 1.1 pk } 285 1.1 pk 286 1.1 pk static void 287 1.32 msaitoh ef_write_16(struct ie_softc *sc, int offset, uint16_t value) 288 1.1 pk { 289 1.32 msaitoh 290 1.1 pk bus_space_write_2(sc->bt, sc->bh, offset, value); 291 1.1 pk } 292 1.1 pk 293 1.1 pk static void 294 1.32 msaitoh ef_write_24(struct ie_softc *sc, int offset, int addr) 295 1.1 pk { 296 1.32 msaitoh 297 1.32 msaitoh bus_space_write_4(sc->bt, sc->bh, offset, 298 1.32 msaitoh addr + (u_long)sc->sc_maddr - (u_long)sc->sc_iobase); 299 1.1 pk } 300 1.1 pk 301 1.1 pk static void 302 1.27 dsl ef_mediastatus(struct ie_softc *sc, struct ifmediareq *ifmr) 303 1.1 pk { 304 1.34 msaitoh struct ifmedia *ifm = &sc->sc_media; 305 1.1 pk 306 1.34 msaitoh /* The currently selected media is always the active media. */ 307 1.34 msaitoh ifmr->ifm_active = ifm->ifm_cur->ifm_media; 308 1.1 pk } 309 1.1 pk 310 1.32 msaitoh static int 311 1.30 cegger ef_match(device_t parent, cfdata_t cf, void *aux) 312 1.1 pk { 313 1.2 pk struct isa_attach_args * const ia = aux; 314 1.2 pk int idx; 315 1.2 pk struct ef_isabus *bus; 316 1.2 pk bus_space_handle_t ioh; 317 1.2 pk bus_space_tag_t iot = ia->ia_iot; 318 1.1 pk 319 1.12 thorpej if (ISA_DIRECT_CONFIG(ia)) 320 1.32 msaitoh return 0; 321 1.12 thorpej 322 1.2 pk if (ef_isa_buses_inited == 0) { 323 1.2 pk LIST_INIT(&ef_isa_buses); 324 1.2 pk ef_isa_buses_inited = 1; 325 1.2 pk } 326 1.2 pk 327 1.32 msaitoh /* Probe this bus if we haven't done so already. */ 328 1.2 pk for (bus = ef_isa_buses.lh_first; bus != NULL; 329 1.2 pk bus = bus->isa_link.le_next) { 330 1.2 pk if (bus->isa_bus == parent) 331 1.2 pk break; 332 1.2 pk } 333 1.1 pk 334 1.2 pk if (bus == NULL) { 335 1.2 pk bus_addr_t iobase; 336 1.1 pk 337 1.32 msaitoh /* Mark this bus so we don't probe it again. */ 338 1.35 chs bus = malloc(sizeof(struct ef_isabus), M_DEVBUF, M_WAITOK); 339 1.32 msaitoh bus->bus_state = 0; /* Nothing done yet */ 340 1.2 pk bus->isa_bus = parent; 341 1.1 pk 342 1.2 pk LIST_INSERT_HEAD(&ef_isa_buses, bus, isa_link); 343 1.1 pk 344 1.2 pk if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) { 345 1.2 pk DPRINTF(("3c507 probe: can't map Etherlink ID port\n")); 346 1.2 pk return 0; 347 1.2 pk } 348 1.1 pk 349 1.2 pk /* 350 1.2 pk * Reset and put card in CONFIG state without 351 1.2 pk * changing address. 352 1.2 pk */ 353 1.21 thorpej elink_reset(iot, ioh, device_unit(parent)); 354 1.2 pk elink_idseq(iot, ioh, ELINK_507_POLY); 355 1.2 pk elink_idseq(iot, ioh, ELINK_507_POLY); 356 1.2 pk bus_space_write_1(iot, ioh, 0, 0xff); 357 1.2 pk 358 1.2 pk /* Unmap the ID port */ 359 1.2 pk bus_space_unmap(iot, ioh, 1); 360 1.2 pk 361 1.32 msaitoh bus->bus_state++; /* Cards now in CONFIG state */ 362 1.2 pk 363 1.2 pk for (iobase = EF_IOBASE_LOW; iobase <= EF_IOBASE_HIGH; 364 1.2 pk iobase += EF_IOSIZE) { 365 1.32 msaitoh /* Map the 507's port-space for the probe sequence. */ 366 1.2 pk if (bus_space_map(iot, iobase, EF_IOSIZE, 367 1.2 pk 0, &ioh) != 0) 368 1.2 pk continue; 369 1.2 pk 370 1.2 pk /* Now look for the 3Com magic bytes */ 371 1.2 pk 372 1.2 pk if (ef_port_check(iot, ioh)) { 373 1.2 pk int irq; 374 1.32 msaitoh uint8_t v; 375 1.2 pk bus_addr_t maddr; 376 1.19 christos bus_addr_t msiz1; 377 1.2 pk bus_space_handle_t memh; 378 1.2 pk 379 1.2 pk irq = bus_space_read_1(iot, ioh, EF_IRQ) & 380 1.2 pk EF_IRQ_MASK; 381 1.2 pk 382 1.2 pk v = bus_space_read_1(iot, ioh, EF_MADDR); 383 1.2 pk maddr = EF_MADDR_BASE + 384 1.2 pk ((v & EF_MADDR_MASK) << EF_MADDR_SHIFT); 385 1.19 christos msiz1 = ((v & EF_MSIZE_MASK) + 1) * 386 1.2 pk EF_MSIZE_STEP; 387 1.2 pk 388 1.2 pk if (bus_space_map(ia->ia_memt, maddr, 389 1.19 christos msiz1, 0, &memh) == 0) { 390 1.2 pk ef_card_add(bus, iobase, maddr, 391 1.19 christos msiz1, irq); 392 1.2 pk bus_space_unmap(ia->ia_memt, 393 1.19 christos memh, msiz1); 394 1.2 pk } 395 1.2 pk } 396 1.2 pk bus_space_unmap(iot, ioh, EF_IOSIZE); 397 1.2 pk } 398 1.1 pk } 399 1.1 pk 400 1.12 thorpej if (ia->ia_nio < 1) 401 1.32 msaitoh return 0; 402 1.12 thorpej if (ia->ia_niomem < 1) 403 1.32 msaitoh return 0; 404 1.12 thorpej if (ia->ia_nirq < 1) 405 1.32 msaitoh return 0; 406 1.12 thorpej 407 1.2 pk for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) { 408 1.2 pk if (bus->isa_cards[idx].available != 1) 409 1.2 pk continue; 410 1.2 pk 411 1.17 drochner if (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT && 412 1.12 thorpej ia->ia_io[0].ir_addr != bus->isa_cards[idx].iobase) 413 1.2 pk continue; 414 1.2 pk 415 1.17 drochner if (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM && 416 1.12 thorpej ia->ia_iomem[0].ir_addr != bus->isa_cards[idx].maddr) 417 1.2 pk continue; 418 1.2 pk 419 1.17 drochner if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ && 420 1.12 thorpej ia->ia_irq[0].ir_irq != bus->isa_cards[idx].irq) 421 1.2 pk continue; 422 1.2 pk 423 1.2 pk break; 424 1.2 pk } 425 1.1 pk 426 1.2 pk if (idx == MAXCARDS_PER_ISABUS) 427 1.32 msaitoh return 0; 428 1.1 pk 429 1.2 pk bus->isa_cards[idx].available++; 430 1.12 thorpej 431 1.12 thorpej ia->ia_nio = 1; 432 1.12 thorpej ia->ia_io[0].ir_addr = bus->isa_cards[idx].iobase; 433 1.12 thorpej ia->ia_io[0].ir_size = EF_IOSIZE; 434 1.12 thorpej 435 1.12 thorpej ia->ia_niomem = 1; 436 1.12 thorpej ia->ia_iomem[0].ir_addr = bus->isa_cards[idx].maddr; 437 1.12 thorpej ia->ia_iomem[0].ir_size = bus->isa_cards[idx].msize; 438 1.12 thorpej 439 1.12 thorpej ia->ia_nirq = 1; 440 1.12 thorpej ia->ia_irq[0].ir_irq = bus->isa_cards[idx].irq; 441 1.12 thorpej 442 1.12 thorpej ia->ia_ndrq = 0; 443 1.12 thorpej 444 1.32 msaitoh return 1; 445 1.1 pk } 446 1.1 pk 447 1.32 msaitoh static void 448 1.30 cegger ef_attach(device_t parent, device_t self, void *aux) 449 1.1 pk { 450 1.31 tsutsui struct ef_softc *esc = device_private(self); 451 1.2 pk struct ie_softc *sc = &esc->sc_ie; 452 1.2 pk struct isa_attach_args *ia = aux; 453 1.2 pk bus_space_tag_t iot = ia->ia_iot; 454 1.2 pk 455 1.2 pk int i; 456 1.19 christos char vers[20]; 457 1.2 pk struct ef_isabus *bus; 458 1.32 msaitoh uint8_t partno[EF_TYPE_LEN]; 459 1.2 pk bus_space_handle_t ioh, memh; 460 1.32 msaitoh uint8_t ethaddr[ETHER_ADDR_LEN]; 461 1.2 pk 462 1.31 tsutsui sc->sc_dev = self; 463 1.2 pk sc->hwinit = ef_hwinit; 464 1.2 pk sc->hwreset = ef_reset; 465 1.2 pk sc->chan_attn = ef_atten; 466 1.2 pk sc->intrhook = ef_intrhook; 467 1.8 bjh21 468 1.8 bjh21 sc->ie_bus_barrier = NULL; 469 1.2 pk 470 1.2 pk sc->memcopyin = ef_copyin; 471 1.2 pk sc->memcopyout = ef_copyout; 472 1.2 pk sc->ie_bus_read16 = ef_read_16; 473 1.2 pk sc->ie_bus_write16 = ef_write_16; 474 1.2 pk sc->ie_bus_write24 = ef_write_24; 475 1.2 pk 476 1.2 pk sc->sc_msize = 0; 477 1.2 pk 478 1.2 pk /* 479 1.2 pk * NOP chains don't give any advantage on this card, in fact they 480 1.2 pk * seem to slow it down some. As the doctor says, "if it hurts, 481 1.2 pk * don't do it". 482 1.2 pk */ 483 1.2 pk sc->do_xmitnopchain = 0; 484 1.1 pk 485 1.2 pk sc->sc_mediachange = NULL; 486 1.2 pk sc->sc_mediastatus = ef_mediastatus; 487 1.1 pk 488 1.2 pk /* Find the cards parent bus */ 489 1.2 pk for (bus = ef_isa_buses.lh_first; bus != NULL; 490 1.2 pk bus = bus->isa_link.le_next) { 491 1.1 pk 492 1.2 pk if (bus->isa_bus == parent) 493 1.2 pk break; 494 1.1 pk } 495 1.1 pk 496 1.2 pk if (bus == NULL) 497 1.31 tsutsui panic("%s: Can't find parent bus!", device_xname(self)); 498 1.2 pk 499 1.2 pk 500 1.2 pk /* If the bus hasn't been transitioned to the RUN state, do so now */ 501 1.2 pk if (bus->bus_state == 1) { 502 1.2 pk if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh) != 0) { 503 1.2 pk DPRINTF(("\n%s: Can't map Elink ID port!\n", 504 1.31 tsutsui device_xname(self))); 505 1.2 pk return; 506 1.2 pk } 507 1.2 pk 508 1.2 pk bus_space_write_1(ia->ia_iot, ioh, 0, 0x00); 509 1.2 pk elink_idseq(ia->ia_iot, ioh, ELINK_507_POLY); 510 1.2 pk bus_space_write_1(ia->ia_iot, ioh, 0, 0x00); 511 1.2 pk bus_space_unmap(ia->ia_iot, ioh, 1); 512 1.1 pk 513 1.2 pk bus->bus_state++; 514 1.2 pk } 515 1.2 pk 516 1.2 pk /* Map i/o space. */ 517 1.12 thorpej if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 518 1.32 msaitoh ia->ia_io[0].ir_size, 0, &ioh) != 0) { 519 1.2 pk 520 1.2 pk DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n", 521 1.31 tsutsui device_xname(self), ia->ia_io[0].ir_addr, 522 1.12 thorpej ia->ia_io[0].ir_addr + ia->ia_io[0].ir_size - 1)); 523 1.2 pk return; 524 1.2 pk } 525 1.1 pk 526 1.2 pk esc->sc_regt = ia->ia_iot; 527 1.2 pk esc->sc_regh = ioh; 528 1.1 pk 529 1.12 thorpej if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, 530 1.32 msaitoh ia->ia_iomem[0].ir_size, 0, &memh) != 0) { 531 1.1 pk 532 1.2 pk DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n", 533 1.33 msaitoh device_xname(self), ia->ia_iomem[0].ir_addr, 534 1.33 msaitoh ia->ia_iomem[0].ir_addr + ia->ia_iomem[0].ir_size 535 1.33 msaitoh - 1)); 536 1.12 thorpej bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size); 537 1.2 pk return; 538 1.2 pk } 539 1.1 pk 540 1.2 pk sc->bt = ia->ia_memt; 541 1.2 pk sc->bh = memh; 542 1.1 pk 543 1.12 thorpej sc->sc_msize = ia->ia_iomem[0].ir_size; 544 1.6 augustss sc->sc_maddr = (void *)memh; 545 1.6 augustss sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24); 546 1.2 pk 547 1.32 msaitoh /* Set up pointers to important on-card control structures */ 548 1.2 pk sc->iscp = 0; 549 1.2 pk sc->scb = IE_ISCP_SZ; 550 1.2 pk sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24); 551 1.2 pk 552 1.2 pk sc->buf_area = sc->scb + IE_SCB_SZ; 553 1.2 pk sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ; 554 1.2 pk 555 1.32 msaitoh /* Zero card memory */ 556 1.2 pk bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize); 557 1.2 pk 558 1.32 msaitoh /* Set card to 16-bit bus mode */ 559 1.11 fredette bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 560 1.11 fredette IE_SYSBUS_16BIT); 561 1.2 pk 562 1.32 msaitoh /* Set up pointers to key structures */ 563 1.32 msaitoh ef_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long)sc->iscp); 564 1.32 msaitoh ef_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long)sc->scb); 565 1.32 msaitoh ef_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long)sc->iscp); 566 1.2 pk 567 1.2 pk /* flush setup of pointers, check if chip answers */ 568 1.2 pk if (!i82586_proberam(sc)) { 569 1.2 pk DPRINTF(("\n%s: can't talk to i82586!\n", 570 1.31 tsutsui device_xname(self))); 571 1.12 thorpej bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size); 572 1.12 thorpej bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size); 573 1.2 pk return; 574 1.2 pk } 575 1.1 pk 576 1.32 msaitoh /* Set bank 2 for card part number and revision */ 577 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL, 578 1.32 msaitoh EF_CTRL_NRST | EF_CTRL_BNK2); 579 1.2 pk 580 1.32 msaitoh /* The card revision is encoded in BCD */ 581 1.2 pk i = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_REV); 582 1.2 pk esc->card_rev = 10 * (i / 16) + (i % 16); 583 1.2 pk 584 1.2 pk for (i = 0; i < EF_TYPE_LEN; i++) 585 1.2 pk partno[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh, 586 1.32 msaitoh EF_TYPE + i); 587 1.2 pk 588 1.32 msaitoh /* Use part number to guess if card is TP or AUI/BNC model */ 589 1.2 pk esc->card_type = EF_IS_TP(partno) ? EF_CARD_TP : EF_CARD_BNC; 590 1.2 pk 591 1.32 msaitoh /* Set bank 0 for ethernet address */ 592 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, 593 1.32 msaitoh EF_CTRL, EF_CTRL_NORMAL); 594 1.2 pk 595 1.2 pk for (i = 0; i < EF_ADDR_LEN; i++) 596 1.2 pk ethaddr[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh, 597 1.32 msaitoh EF_ADDR + i); 598 1.2 pk 599 1.19 christos snprintf(vers, sizeof(vers), "%s, rev. %d", 600 1.2 pk (esc->card_type == EF_CARD_TP) ? "3C507-TP" : "3C507", 601 1.2 pk esc->card_rev); 602 1.2 pk 603 1.2 pk if (esc->card_type == EF_CARD_TP) 604 1.19 christos i82586_attach(sc, vers, ethaddr, eftp_media, NEFTP_MEDIA, 605 1.32 msaitoh eftp_media[0]); 606 1.2 pk else { 607 1.32 msaitoh uint8_t media = bus_space_read_1(esc->sc_regt, esc->sc_regh, 608 1.2 pk EF_MEDIA); 609 1.2 pk media = (media & EF_MEDIA_MASK) >> EF_MEDIA_SHIFT; 610 1.1 pk 611 1.19 christos i82586_attach(sc, vers, ethaddr, ef_media, NEF_MEDIA, 612 1.2 pk ef_media[media]); 613 1.2 pk } 614 1.1 pk 615 1.2 pk /* Clear the interrupt latch just in case. */ 616 1.2 pk bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1); 617 1.1 pk 618 1.12 thorpej esc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, 619 1.12 thorpej IST_EDGE, IPL_NET, i82586_intr, sc); 620 1.2 pk if (esc->sc_ih == NULL) { 621 1.2 pk DPRINTF(("\n%s: can't establish interrupt\n", 622 1.31 tsutsui device_xname(self))); 623 1.2 pk } 624 1.1 pk } 625 1.1 pk 626 1.2 pk static int 627 1.27 dsl ef_port_check(bus_space_tag_t iot, bus_space_handle_t ioh) 628 1.1 pk { 629 1.1 pk int i; 630 1.34 msaitoh u_char ch; 631 1.32 msaitoh const u_char *signature = EF_SIGNATURE; 632 1.1 pk 633 1.1 pk for (i = 0; i < strlen(signature); i++) { 634 1.1 pk ch = bus_space_read_1(iot, ioh, i); 635 1.1 pk if (ch != signature[i]) 636 1.1 pk return 0; 637 1.1 pk } 638 1.2 pk 639 1.1 pk /* If card is mapped in high memory (above 15Meg), we can't use it */ 640 1.1 pk ch = bus_space_read_1(iot, ioh, EF_MADDR); 641 1.1 pk if (ch & EF_MADDR_HIGH) 642 1.32 msaitoh return 0; /* XXX: maybe we should panic?? */ 643 1.1 pk 644 1.1 pk return 1; 645 1.1 pk } 646 1.1 pk 647 1.31 tsutsui CFATTACH_DECL_NEW(ef, sizeof(struct ef_softc), 648 1.15 thorpej ef_match, ef_attach, NULL, NULL); 649