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/eisa/if_tlp_eisa.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_tlp_eisa.c,v 1.18 2006/11/16 01:32:50 christos Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 1999, 2000 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  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed by the NetBSD
   22  *      Foundation, Inc. and its contributors.
   23  * 4. Neither the name of The NetBSD Foundation nor the names of its
   24  *    contributors may be used to endorse or promote products derived
   25  *    from this software without specific prior written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   37  * POSSIBILITY OF SUCH DAMAGE.
   38  */
   39 
   40 /*
   41  * EISA bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
   42  * Ethernet controller family driver.
   43  */
   44 
   45 #include <sys/cdefs.h>
   46 __KERNEL_RCSID(0, "$NetBSD: if_tlp_eisa.c,v 1.18 2006/11/16 01:32:50 christos Exp $");
   47 
   48 #include "opt_inet.h"
   49 #include "bpfilter.h"
   50 
   51 #include <sys/param.h>
   52 #include <sys/systm.h>
   53 #include <sys/mbuf.h>
   54 #include <sys/malloc.h>
   55 #include <sys/kernel.h>
   56 #include <sys/socket.h>
   57 #include <sys/ioctl.h>
   58 #include <sys/errno.h>
   59 #include <sys/device.h>
   60 
   61 #include <machine/endian.h>
   62 
   63 #include <net/if.h>
   64 #include <net/if_dl.h>
   65 #include <net/if_media.h>
   66 #include <net/if_ether.h>
   67 
   68 #if NBPFILTER > 0
   69 #include <net/bpf.h>
   70 #endif
   71 
   72 #ifdef INET
   73 #include <netinet/in.h>
   74 #include <netinet/if_inarp.h>
   75 #endif
   76 
   77 
   78 #include <machine/bus.h>
   79 #include <machine/intr.h>
   80 
   81 #include <dev/mii/miivar.h>
   82 #include <dev/mii/mii_bitbang.h>
   83 
   84 #include <dev/ic/tulipreg.h>
   85 #include <dev/ic/tulipvar.h>
   86 
   87 #include <dev/eisa/eisareg.h>
   88 #include <dev/eisa/eisavar.h>
   89 #include <dev/eisa/eisadevs.h>
   90 
   91 #include <dev/pci/pcireg.h>
   92 
   93 /*
   94  * DE425 configuration registers; literal offsets from CSR base.
   95  * This is effectively the 21040 PCI configuration space interleaved
   96  * into the CSR space (CSRs are space 16 bytes on the DE425).
   97  *
   98  * What a cool address decoder hack they must have on that board...
   99  */
  100 #define DE425_CFID              0x08    /* Configuration ID */
  101 #define DE425_CFCS              0x0c    /* Configuration Command-Status */
  102 #define DE425_CFRV              0x18    /* Configuration Revision */
  103 #define DE425_CFLT              0x1c    /* Configuration Latency Timer */
  104 #define DE425_CBIO              0x28    /* Configuration Base I/O Address */
  105 #define DE425_CFDA              0x2c    /* Configuration Driver Area */
  106 #define DE425_ENETROM           0xc90   /* Offset in I/O space for ENETROM */
  107 #define DE425_CFG0              0xc88   /* IRQ Configuration Register */
  108 
  109 struct tulip_eisa_softc {
  110         struct tulip_softc sc_tulip;    /* real Tulip softc */
  111 
  112         /* EISA-specific goo. */
  113         void    *sc_ih;                 /* interrupt handle */
  114 };
  115 
  116 static int      tlp_eisa_match(struct device *, struct cfdata *, void *);
  117 static void     tlp_eisa_attach(struct device *, struct device *, void *);
  118 
  119 CFATTACH_DECL(tlp_eisa, sizeof(struct tulip_eisa_softc),
  120     tlp_eisa_match, tlp_eisa_attach, NULL, NULL);
  121 
  122 static const int tlp_eisa_irqs[] = { 5, 9, 10, 11 };
  123 
  124 static const struct tulip_eisa_product {
  125         const char      *tep_eisaid;    /* EISA ID */
  126         const char      *tep_name;      /* device name */
  127         tulip_chip_t    tep_chip;       /* base Tulip chip type */
  128 } tlp_eisa_products[] = {
  129         { "DEC4250",                    "DEC DE425",
  130           TULIP_CHIP_DE425 },
  131 
  132         { NULL,                         NULL,
  133           TULIP_CHIP_INVALID },
  134 };
  135 
  136 static const struct tulip_eisa_product *
  137 tlp_eisa_lookup(const struct eisa_attach_args *ea)
  138 {
  139         const struct tulip_eisa_product *tep;
  140 
  141         for (tep = tlp_eisa_products;
  142              tep->tep_chip != TULIP_CHIP_INVALID; tep++)
  143                 if (strcmp(ea->ea_idstring, tep->tep_eisaid) == 0)
  144                         return (tep);
  145         return (NULL);
  146 }
  147 
  148 static int
  149 tlp_eisa_match(struct device *parent, struct cfdata *match,
  150     void *aux)
  151 {
  152         struct eisa_attach_args *ea = aux;
  153 
  154         if (tlp_eisa_lookup(ea) != NULL)
  155                 return (1);
  156 
  157         return (0);
  158 }
  159 
  160 static void
  161 tlp_eisa_attach(struct device *parent, struct device *self, void *aux)
  162 {
  163         static const u_int8_t testpat[] =
  164             { 0xff, 0, 0x55, 0xaa, 0xff, 0, 0x55, 0xaa };
  165         struct tulip_eisa_softc *esc = device_private(self);
  166         struct tulip_softc *sc = &esc->sc_tulip;
  167         struct eisa_attach_args *ea = aux;
  168         eisa_chipset_tag_t ec = ea->ea_ec;
  169         eisa_intr_handle_t ih;
  170         bus_space_tag_t iot = ea->ea_iot;
  171         bus_space_handle_t ioh;
  172         const char *intrstr;
  173         const struct tulip_eisa_product *tep;
  174         u_int8_t enaddr[ETHER_ADDR_LEN], tmpbuf[sizeof(testpat)];
  175         u_int32_t val;
  176         int irq, i, cnt;
  177 
  178         /*
  179          * Map the device.
  180          */
  181         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
  182             EISA_SLOT_SIZE, 0, &ioh)) {
  183                 printf(": unable to map I/O space\n");
  184                 return;
  185         }
  186 
  187         sc->sc_st = iot;
  188         sc->sc_sh = ioh;
  189 
  190         tep = tlp_eisa_lookup(ea);
  191         if (tep == NULL) {
  192                 printf("\n");
  193                 panic("tlp_eisa_attach: impossible");
  194         }
  195         sc->sc_chip = tep->tep_chip;
  196 
  197         /*
  198          * DE425's registers are 16 bytes long; the PCI configuration
  199          * space registers are interleaved in the I/O space.
  200          */
  201         sc->sc_regshift = 4;
  202 
  203         /*
  204          * No power management hooks.
  205          */
  206         sc->sc_flags |= TULIPF_ENABLED;
  207 
  208         /*
  209          * CBIO must map the EISA slot, and I/O access and Bus Mastering
  210          * must be enabled.
  211          */
  212         bus_space_write_4(iot, ioh, DE425_CBIO, EISA_SLOT_ADDR(ea->ea_slot));
  213         bus_space_write_4(iot, ioh, DE425_CFCS,
  214             bus_space_read_4(iot, ioh, DE425_CFCS) |
  215             PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE);
  216 
  217         /*
  218          * Get revision info.
  219          */
  220         sc->sc_rev = bus_space_read_4(iot, ioh, DE425_CFRV) & 0xff;
  221 
  222         printf(": %s Ethernet, pass %d.%d\n",
  223             tep->tep_name, (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
  224 
  225         sc->sc_dmat = ea->ea_dmat;
  226 
  227         /*
  228          * EISA doesn't have a cache line register.
  229          */
  230         sc->sc_cacheline = 0;
  231 
  232         /*
  233          * Find the beginning of the Ethernet Address ROM.
  234          */
  235         for (i = 0, cnt = 0; i < sizeof(testpat) && cnt < 32; cnt++) {
  236                 tmpbuf[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
  237                 if (tmpbuf[i] == testpat[i])
  238                         i++;
  239                 else
  240                         i = 0;
  241         }
  242 
  243         /*
  244          * ...and now read the contents of the Ethernet Address ROM.
  245          */
  246         sc->sc_srom = malloc(32, M_DEVBUF, M_WAITOK|M_ZERO);
  247         for (i = 0; i < 32; i++)
  248                 sc->sc_srom[i] = bus_space_read_1(iot, ioh, DE425_ENETROM);
  249 
  250         /*
  251          * None of the DE425 boards have the new-style SROMs.
  252          */
  253         if (tlp_parse_old_srom(sc, enaddr) == 0) {
  254                 printf("%s: unable to decode old-style SROM\n",
  255                     sc->sc_dev.dv_xname);
  256                 return;
  257         }
  258 
  259         /*
  260          * All DE425 boards use the 21040 media switch.
  261          */
  262         sc->sc_mediasw = &tlp_21040_mediasw;
  263 
  264         /*
  265          * Figure out which IRQ we want to use, and determine of it's
  266          * edge- or level-triggered.
  267          */
  268         val = bus_space_read_4(iot, ioh, DE425_CFG0);
  269         irq = tlp_eisa_irqs[(val >> 1) & 0x03];
  270 
  271         /*
  272          * Map and establish our interrupt.
  273          */
  274         if (eisa_intr_map(ec, irq, &ih)) {
  275                 printf("%s: unable to map interrupt (%u)\n",
  276                     sc->sc_dev.dv_xname, irq);
  277                 return;
  278         }
  279         intrstr = eisa_intr_string(ec, ih);
  280         esc->sc_ih = eisa_intr_establish(ec, ih,
  281             (val & 0x01) ? IST_EDGE : IST_LEVEL, IPL_NET, tlp_intr, sc);
  282         if (esc->sc_ih == NULL) {
  283                 printf("%s: unable to establish interrupt",
  284                     sc->sc_dev.dv_xname);
  285                 if (intrstr != NULL)
  286                         printf(" at %s", intrstr);
  287                 printf("\n");
  288                 return;
  289         }
  290         if (intrstr != NULL)
  291                 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
  292                     intrstr);
  293 
  294         /*
  295          * Finish off the attach.
  296          */
  297         tlp_attach(sc, enaddr);
  298 }

Cache object: e739384dad6a03388e641956e5de5afe


[ 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.