The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/isa/if_ef.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: if_ef.c,v 1.15 2002/10/02 03:10:47 thorpej 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 Rafal K. Boni.
    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_ef.c,v 1.15 2002/10/02 03:10:47 thorpej Exp $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/mbuf.h>
   45 #include <sys/errno.h>
   46 #include <sys/device.h>
   47 #include <sys/protosw.h>
   48 #include <sys/socket.h>
   49 
   50 #include <net/if.h>
   51 #include <net/if_dl.h>
   52 #include <net/if_types.h>
   53 #include <net/if_media.h>
   54 #include <net/if_ether.h>
   55 
   56 #include <machine/cpu.h>
   57 #include <machine/bus.h>
   58 #include <machine/intr.h>
   59 
   60 #include <dev/isa/isareg.h>
   61 #include <dev/isa/isavar.h>
   62 
   63 #include <dev/ic/i82586reg.h>
   64 #include <dev/ic/i82586var.h>
   65 #include <dev/isa/if_efreg.h>
   66 #include <dev/isa/elink.h>
   67 
   68 #ifdef EF_DEBUG
   69 #define DPRINTF(x)      printf x
   70 #else
   71 #define DPRINTF(x)
   72 #endif
   73 
   74 struct ef_softc {
   75         struct ie_softc sc_ie;
   76 
   77         bus_space_tag_t sc_regt;        /* space tag for registers */
   78         bus_space_handle_t sc_regh;     /* space handle for registers */
   79 
   80         void* sc_ih;                    /* interrupt handle */
   81 
   82         u_int8_t card_rev;              /* hardware revision */
   83         u_int8_t card_type;             /* card model -- AUI/BNC or TP */
   84 };
   85 
   86 int ef_media[] = {
   87         IFM_ETHER | IFM_10_5,
   88         IFM_ETHER | IFM_10_2,
   89 };
   90 #define NEF_MEDIA       (sizeof(ef_media) / sizeof(ef_media[0]))
   91 
   92 int eftp_media[] = {
   93         IFM_ETHER | IFM_10_T,
   94 };
   95 #define NEFTP_MEDIA       (sizeof(eftp_media) / sizeof(eftp_media[0]))
   96 
   97 /* Routines required by the MI i82586 driver API */
   98 static void     ef_reset __P((struct ie_softc *, int));
   99 static void     ef_hwinit __P((struct ie_softc *));
  100 static void     ef_atten __P((struct ie_softc *, int));
  101 static int      ef_intrhook __P((struct ie_softc *, int));
  102 
  103 static void     ef_copyin __P((struct ie_softc *, void *, int, size_t));
  104 static void     ef_copyout __P((struct ie_softc *, const void *, int, size_t));
  105 
  106 static u_int16_t ef_read_16 __P((struct ie_softc *, int));
  107 static void     ef_write_16 __P((struct ie_softc *, int, u_int16_t));
  108 static void     ef_write_24 __P((struct ie_softc *, int, int));
  109 
  110 static void     ef_mediastatus __P((struct ie_softc *, struct ifmediareq *));
  111 
  112 /* Local routines */
  113 static int      ef_port_check __P((bus_space_tag_t, bus_space_handle_t));
  114 
  115 int ef_match __P((struct device *, struct cfdata *, void *));
  116 void ef_attach __P((struct device *, struct device *, void *));
  117 
  118 /*
  119  * This keeps track of which ISAs have been through an ie probe sequence.
  120  * A simple static variable isn't enough, since it's conceivable that
  121  * a system might have more than one ISA bus.
  122  *
  123  * The "isa_bus" member is a pointer to the parent ISA bus device struct
  124  * which will unique per ISA bus.
  125  */
  126 
  127 #define MAXCARDS_PER_ISABUS     8       /* if you have more than 8, you lose */
  128 
  129 struct ef_isabus {
  130         LIST_ENTRY(ef_isabus) isa_link;
  131         struct device *isa_bus;
  132 
  133         int bus_state;
  134 
  135         struct card {
  136                 bus_addr_t iobase;
  137                 bus_addr_t maddr;
  138                 bus_size_t msize;
  139                 int irq;
  140                 int available;
  141         } isa_cards[MAXCARDS_PER_ISABUS];
  142 };
  143 
  144 static LIST_HEAD(, ef_isabus) ef_isa_buses;
  145 static int ef_isa_buses_inited;
  146 
  147 static void
  148 ef_card_add(
  149     struct ef_isabus *bus,
  150     bus_addr_t iobase,
  151     bus_addr_t maddr,
  152     bus_size_t msize,
  153     int irq)
  154 {
  155         int idx;
  156 
  157         DPRINTF(("Adding 3c507 at 0x%x, IRQ %d, Mem 0x%lx/%ld\n",
  158                  (u_int) iobase, irq, (u_long) maddr, msize));
  159 
  160         for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
  161                 if (bus->isa_cards[idx].available == 0) {
  162                         bus->isa_cards[idx].iobase = iobase;
  163                         bus->isa_cards[idx].maddr = maddr;
  164                         bus->isa_cards[idx].msize = msize;
  165                         bus->isa_cards[idx].irq = irq;
  166                         bus->isa_cards[idx].available = 1;
  167                         break;
  168                 }
  169         }
  170 }
  171 
  172 /*
  173  * 3C507 support routines
  174  */
  175 static void
  176 ef_reset(sc, why)
  177         struct ie_softc *sc;
  178         int why;
  179 {
  180         struct ef_softc* esc = (struct ef_softc *) sc;
  181 
  182         switch (why) {
  183         case CHIP_PROBE:
  184                 /* reset to chip to see if it responds */
  185                 bus_space_write_1(esc->sc_regt, esc->sc_regh,
  186                                   EF_CTRL, EF_CTRL_RESET);
  187                 DELAY(100);
  188                 bus_space_write_1(esc->sc_regt, esc->sc_regh,
  189                                   EF_CTRL, EF_CTRL_NORMAL);
  190                 DELAY(100);
  191                 break;
  192 
  193         case CARD_RESET:
  194                 /*
  195                  * this takes around 10sec, and we can get
  196                  * by quite well w/out it...
  197                  */
  198                 break;
  199         }
  200 }
  201 
  202 static void
  203 ef_atten(sc, why)
  204         struct ie_softc *sc;
  205         int why;
  206 {
  207         struct ef_softc* esc = (struct ef_softc *) sc;
  208         bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ATTN, 1);
  209 }
  210 
  211 static void
  212 ef_hwinit(sc)
  213         struct ie_softc *sc;
  214 {
  215         struct ef_softc* esc = (struct ef_softc *) sc;
  216         bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
  217 }
  218 
  219 static int
  220 ef_intrhook(sc, where)
  221         struct ie_softc *sc;
  222         int where;
  223 {
  224         unsigned char cr;
  225         struct ef_softc* esc = (struct ef_softc *) sc;
  226 
  227         switch (where) {
  228         case INTR_ENTER:
  229                 /* entering ISR: disable, ack card interrupts */
  230                 cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
  231                 bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
  232                                   cr & ~EF_CTRL_IEN);
  233                 bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
  234                 break;
  235 
  236         case INTR_EXIT:
  237                 /* exiting ISR: re-enable card interrupts */
  238                 cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
  239                 bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
  240                                   cr | EF_CTRL_IEN);
  241                 break;
  242 
  243         case INTR_LOOP:
  244                 /* looping in ISR: ack new interrupts */
  245                 bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
  246                 break;
  247     }
  248 
  249     return 1;
  250 }
  251 
  252 static u_int16_t
  253 ef_read_16 (sc, offset)
  254         struct ie_softc *sc;
  255         int offset;
  256 {
  257         bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
  258         return bus_space_read_2(sc->bt, sc->bh, offset);
  259 }
  260 
  261 static void
  262 ef_copyin (sc, dst, offset, size)
  263         struct ie_softc *sc;
  264         void *dst;
  265         int offset;
  266         size_t size;
  267 {
  268         int dribble;
  269         u_int8_t* bptr = dst;
  270 
  271         bus_space_barrier(sc->bt, sc->bh, offset, size,
  272                           BUS_SPACE_BARRIER_READ);
  273 
  274         if (offset % 2) {
  275                 *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  276                 offset++; bptr++; size--;
  277         }
  278 
  279         dribble = size % 2;
  280         bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
  281                                 size >> 1);
  282 
  283         if (dribble) {
  284                 bptr += size - 1;
  285                 offset += size - 1;
  286                 *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
  287         }
  288 }
  289 
  290 static void
  291 ef_copyout (sc, src, offset, size)
  292         struct ie_softc *sc;
  293         const void *src;
  294         int offset;
  295         size_t size;
  296 {
  297         int dribble;
  298         int osize = size;
  299         int ooffset = offset;
  300         const u_int8_t* bptr = src;
  301 
  302         if (offset % 2) {
  303                 bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  304                 offset++; bptr++; size--;
  305         }
  306 
  307         dribble = size % 2;
  308         bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
  309                                  size >> 1);
  310         if (dribble) {
  311                 bptr += size - 1;
  312                 offset += size - 1;
  313                 bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
  314         }
  315 
  316         bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
  317                           BUS_SPACE_BARRIER_WRITE);
  318 }
  319 
  320 static void
  321 ef_write_16 (sc, offset, value)
  322         struct ie_softc *sc;
  323         int offset;
  324         u_int16_t value;
  325 {
  326         bus_space_write_2(sc->bt, sc->bh, offset, value);
  327         bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
  328 }
  329 
  330 static void
  331 ef_write_24 (sc, offset, addr)
  332         struct ie_softc *sc;
  333         int offset, addr;
  334 {
  335         bus_space_write_4(sc->bt, sc->bh, offset, addr +
  336                           (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
  337         bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
  338 }
  339 
  340 static void
  341 ef_mediastatus(sc, ifmr)
  342         struct ie_softc *sc;
  343         struct ifmediareq *ifmr;
  344 {
  345         struct ifmedia *ifm = &sc->sc_media;
  346 
  347         /*
  348          * The currently selected media is always the active media.
  349          */
  350         ifmr->ifm_active = ifm->ifm_cur->ifm_media;
  351 }
  352 
  353 int
  354 ef_match(parent, cf, aux)
  355         struct device *parent;
  356         struct cfdata *cf;
  357         void *aux;
  358 {
  359         struct isa_attach_args * const ia = aux;
  360 
  361         int idx;
  362         struct ef_isabus *bus;
  363 
  364         bus_space_handle_t ioh;
  365         bus_space_tag_t iot = ia->ia_iot;
  366 
  367         if (ISA_DIRECT_CONFIG(ia))
  368                 return (0);
  369 
  370         if (ef_isa_buses_inited == 0) {
  371                 LIST_INIT(&ef_isa_buses);
  372                 ef_isa_buses_inited = 1;
  373         }
  374 
  375         /*
  376          * Probe this bus if we haven't done so already.
  377          */
  378         for (bus = ef_isa_buses.lh_first; bus != NULL;
  379              bus = bus->isa_link.le_next) {
  380                 if (bus->isa_bus == parent)
  381                         break;
  382         }
  383 
  384         if (bus == NULL) {
  385                 bus_addr_t iobase;
  386 
  387                 /*
  388                  * Mark this bus so we don't probe it again.
  389                  */
  390                 bus = (struct ef_isabus *)
  391                         malloc(sizeof(struct ef_isabus), M_DEVBUF, M_NOWAIT);
  392                 if (bus == NULL)
  393                     panic("ef_isa_probe: can't allocate state storage for %s",
  394                           parent->dv_xname);
  395 
  396                 bus->bus_state = 0;             /* nothing done yet */
  397                 bus->isa_bus = parent;
  398 
  399                 LIST_INSERT_HEAD(&ef_isa_buses, bus, isa_link);
  400 
  401                 if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) {
  402                         DPRINTF(("3c507 probe: can't map Etherlink ID port\n"));
  403                         return 0;
  404                 }
  405 
  406                 /*
  407                  * Reset and put card in CONFIG state without
  408                  * changing address.
  409                  */
  410                 elink_reset(iot, ioh, parent->dv_unit);
  411                 elink_idseq(iot, ioh, ELINK_507_POLY);
  412                 elink_idseq(iot, ioh, ELINK_507_POLY);
  413                 bus_space_write_1(iot, ioh, 0, 0xff);
  414 
  415                 /* Unmap the ID port */
  416                 bus_space_unmap(iot, ioh, 1);
  417 
  418                 bus->bus_state++;       /* cards now in CONFIG state */
  419 
  420                 for (iobase = EF_IOBASE_LOW; iobase <= EF_IOBASE_HIGH;
  421                      iobase += EF_IOSIZE) {
  422                         /*
  423                          * Map the 507's port-space for the probe sequence.
  424                          */
  425                         if (bus_space_map(iot, iobase, EF_IOSIZE,
  426                                           0, &ioh) != 0)
  427                                 continue;
  428 
  429                         /* Now look for the 3Com magic bytes */
  430 
  431                         if (ef_port_check(iot, ioh)) {
  432                                 int irq;
  433                                 u_int8_t v;
  434                                 bus_addr_t maddr;
  435                                 bus_addr_t msize;
  436                                 bus_space_handle_t memh;
  437 
  438                                 irq = bus_space_read_1(iot, ioh, EF_IRQ) &
  439                                         EF_IRQ_MASK;
  440 
  441                                 v = bus_space_read_1(iot, ioh, EF_MADDR);
  442                                 maddr = EF_MADDR_BASE +
  443                                       ((v & EF_MADDR_MASK) << EF_MADDR_SHIFT);
  444                                 msize = ((v & EF_MSIZE_MASK) + 1) *
  445                                         EF_MSIZE_STEP;
  446 
  447                                 if (bus_space_map(ia->ia_memt, maddr,
  448                                                   msize, 0, &memh) == 0) {
  449                                             ef_card_add(bus, iobase, maddr,
  450                                                         msize, irq);
  451                                             bus_space_unmap(ia->ia_memt,
  452                                                             memh, msize);
  453                                 }
  454                         }
  455                         bus_space_unmap(iot, ioh, EF_IOSIZE);
  456                 }
  457         }
  458 
  459         if (ia->ia_nio < 1)
  460                 return (0);
  461         if (ia->ia_niomem < 1)
  462                 return (0);
  463         if (ia->ia_nirq < 1)
  464                 return (0);
  465 
  466         for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
  467                 if (bus->isa_cards[idx].available != 1)
  468                         continue;
  469 
  470                 if (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT &&
  471                     ia->ia_io[0].ir_addr != bus->isa_cards[idx].iobase)
  472                         continue;
  473 
  474                 if (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT &&
  475                     ia->ia_iomem[0].ir_addr != bus->isa_cards[idx].maddr)
  476                         continue;
  477 
  478                 if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
  479                     ia->ia_irq[0].ir_irq != bus->isa_cards[idx].irq)
  480                         continue;
  481 
  482                 break;
  483         }
  484 
  485         if (idx == MAXCARDS_PER_ISABUS)
  486                 return (0);
  487 
  488         bus->isa_cards[idx].available++;
  489 
  490         ia->ia_nio = 1;
  491         ia->ia_io[0].ir_addr = bus->isa_cards[idx].iobase;
  492         ia->ia_io[0].ir_size = EF_IOSIZE;
  493 
  494         ia->ia_niomem = 1;
  495         ia->ia_iomem[0].ir_addr = bus->isa_cards[idx].maddr;
  496         ia->ia_iomem[0].ir_size = bus->isa_cards[idx].msize;
  497 
  498         ia->ia_nirq = 1;
  499         ia->ia_irq[0].ir_irq = bus->isa_cards[idx].irq;
  500 
  501         ia->ia_ndrq = 0;
  502 
  503         return (1);
  504 }
  505 
  506 void
  507 ef_attach(parent, self, aux)
  508         struct device *parent;
  509         struct device *self;
  510         void   *aux;
  511 {
  512         struct ef_softc *esc = (void *)self;
  513         struct ie_softc *sc = &esc->sc_ie;
  514         struct isa_attach_args *ia = aux;
  515         bus_space_tag_t iot = ia->ia_iot;
  516 
  517         int i;
  518         char version[20];
  519         struct ef_isabus *bus;
  520         u_int8_t partno[EF_TYPE_LEN];
  521         bus_space_handle_t ioh, memh;
  522         u_int8_t ethaddr[ETHER_ADDR_LEN];
  523 
  524         sc->hwinit = ef_hwinit;
  525         sc->hwreset = ef_reset;
  526         sc->chan_attn = ef_atten;
  527         sc->intrhook = ef_intrhook;
  528 
  529         sc->ie_bus_barrier = NULL;
  530 
  531         sc->memcopyin = ef_copyin;
  532         sc->memcopyout = ef_copyout;
  533         sc->ie_bus_read16 = ef_read_16;
  534         sc->ie_bus_write16 = ef_write_16;
  535         sc->ie_bus_write24 = ef_write_24;
  536 
  537         sc->sc_msize = 0;
  538 
  539         /*
  540          * NOP chains don't give any advantage on this card, in fact they
  541          * seem to slow it down some.  As the doctor says, "if it hurts,
  542          * don't do it".
  543          */
  544         sc->do_xmitnopchain = 0;
  545 
  546         sc->sc_mediachange = NULL;
  547         sc->sc_mediastatus = ef_mediastatus;
  548 
  549         /* Find the cards parent bus */
  550         for (bus = ef_isa_buses.lh_first; bus != NULL;
  551              bus = bus->isa_link.le_next) {
  552 
  553                 if (bus->isa_bus == parent)
  554                         break;
  555         }
  556 
  557         if (bus == NULL)
  558                 panic("%s: Can't find parent bus!", sc->sc_dev.dv_xname);
  559 
  560 
  561         /* If the bus hasn't been transitioned to the RUN state, do so now */
  562         if (bus->bus_state == 1) {
  563                 if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh) != 0) {
  564                         DPRINTF(("\n%s: Can't map Elink ID port!\n",
  565                                 sc->sc_dev.dv_xname));
  566                         return;
  567                 }
  568 
  569                 bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
  570                 elink_idseq(ia->ia_iot, ioh, ELINK_507_POLY);
  571                 bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
  572                 bus_space_unmap(ia->ia_iot, ioh, 1);
  573 
  574                 bus->bus_state++;
  575         }
  576 
  577         /* Map i/o space. */
  578         if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
  579                           ia->ia_io[0].ir_size, 0, &ioh) != 0) {
  580 
  581                 DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
  582                           sc->sc_dev.dv_xname, ia->ia_io[0].ir_addr,
  583                           ia->ia_io[0].ir_addr + ia->ia_io[0].ir_size - 1));
  584                 return;
  585         }
  586 
  587         esc->sc_regt = ia->ia_iot;
  588         esc->sc_regh = ioh;
  589 
  590         if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
  591                           ia->ia_iomem[0].ir_size, 0, &memh) != 0) {
  592 
  593                 DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
  594                         sc->sc_dev.dv_xname, ia->ia_maddr,
  595                         ia->ia_maddr + ia->ia_msize - 1));
  596                 bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
  597                 return;
  598         }
  599 
  600         sc->bt = ia->ia_memt;
  601         sc->bh = memh;
  602 
  603         sc->sc_msize = ia->ia_iomem[0].ir_size;
  604         sc->sc_maddr = (void *)memh;
  605         sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
  606 
  607         /* set up pointers to important on-card control structures */
  608         sc->iscp = 0;
  609         sc->scb = IE_ISCP_SZ;
  610         sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
  611 
  612         sc->buf_area = sc->scb + IE_SCB_SZ;
  613         sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
  614 
  615         /* zero card memory */
  616         bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
  617 
  618         /* set card to 16-bit bus mode */
  619         bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
  620                           IE_SYSBUS_16BIT);
  621 
  622         /* set up pointers to key structures */
  623         ef_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
  624         ef_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
  625         ef_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
  626 
  627         /* flush setup of pointers, check if chip answers */
  628         bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
  629                           BUS_SPACE_BARRIER_WRITE);
  630         if (!i82586_proberam(sc)) {
  631                 DPRINTF(("\n%s: can't talk to i82586!\n",
  632                         sc->sc_dev.dv_xname));
  633                 bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
  634                 bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size);
  635                 return;
  636         }
  637 
  638         /* set bank 2 for card part number and revision */
  639         bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
  640                           EF_CTRL_NRST | EF_CTRL_BNK2);
  641 
  642         /* card revision is encoded in BCD */
  643         i = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_REV);
  644         esc->card_rev = 10 * (i / 16) + (i % 16);
  645 
  646         for (i = 0; i < EF_TYPE_LEN; i++)
  647                 partno[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh,
  648                                              EF_TYPE + i);
  649 
  650         /* use part number to guess if card is TP or AUI/BNC model */
  651         esc->card_type = EF_IS_TP(partno) ? EF_CARD_TP : EF_CARD_BNC;
  652 
  653         /* set bank 0 for ethernet address */
  654         bus_space_write_1(esc->sc_regt, esc->sc_regh,
  655                           EF_CTRL, EF_CTRL_NORMAL);
  656 
  657         for (i = 0; i < EF_ADDR_LEN; i++)
  658                 ethaddr[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh,
  659                                               EF_ADDR + i);
  660 
  661         sprintf(version, "%s, rev. %d",
  662                 (esc->card_type == EF_CARD_TP) ? "3C507-TP" : "3C507",
  663                 esc->card_rev);
  664 
  665         if (esc->card_type == EF_CARD_TP)
  666                 i82586_attach(sc, version, ethaddr, eftp_media, NEFTP_MEDIA,
  667                               eftp_media[0]);
  668         else {
  669                 u_int8_t media = bus_space_read_1(esc->sc_regt, esc->sc_regh,
  670                                                   EF_MEDIA);
  671                 media = (media & EF_MEDIA_MASK) >> EF_MEDIA_SHIFT;
  672 
  673                 i82586_attach(sc, version, ethaddr, ef_media, NEF_MEDIA,
  674                               ef_media[media]);
  675         }
  676 
  677         /* Clear the interrupt latch just in case. */
  678         bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
  679 
  680         esc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
  681             IST_EDGE, IPL_NET, i82586_intr, sc);
  682         if (esc->sc_ih == NULL) {
  683                 DPRINTF(("\n%s: can't establish interrupt\n",
  684                         sc->sc_dev.dv_xname));
  685         }
  686 }
  687 
  688 static int
  689 ef_port_check(iot, ioh)
  690         bus_space_tag_t iot;
  691         bus_space_handle_t ioh;
  692 {
  693         int i;
  694         u_char ch;
  695         u_char* signature = EF_SIGNATURE;
  696 
  697         for (i = 0; i < strlen(signature); i++) {
  698                 ch = bus_space_read_1(iot, ioh, i);
  699                 if (ch != signature[i])
  700                         return 0;
  701         }
  702 
  703         /* If card is mapped in high memory (above 15Meg), we can't use it */
  704         ch = bus_space_read_1(iot, ioh, EF_MADDR);
  705         if (ch & EF_MADDR_HIGH)
  706             return 0;                   /* XXX: maybe we should panic?? */
  707 
  708         return 1;
  709 }
  710 
  711 CFATTACH_DECL(ef, sizeof(struct ef_softc),
  712     ef_match, ef_attach, NULL, NULL);
  713 

Cache object: 417910926ab8555da2fb08fd99f3ee0f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.