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_ep_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_ep_eisa.c,v 1.35.2.1 2009/01/31 21:46:18 bouyer 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 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  * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org>
   42  * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
   43  * All rights reserved.
   44  *
   45  * Redistribution and use in source and binary forms, with or without
   46  * modification, are permitted provided that the following conditions
   47  * are met:
   48  * 1. Redistributions of source code must retain the above copyright
   49  *    notice, this list of conditions and the following disclaimer.
   50  * 2. Redistributions in binary form must reproduce the above copyright
   51  *    notice, this list of conditions and the following disclaimer in the
   52  *    documentation and/or other materials provided with the distribution.
   53  * 3. All advertising materials mentioning features or use of this software
   54  *    must display the following acknowledgement:
   55  *      This product includes software developed by Herb Peyerl.
   56  *      This product includes software developed by Jonathan Stone.
   57  * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse
   58  *    or promote products derived from this software without specific
   59  *    prior written permission.
   60  *
   61  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   62  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   63  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   64  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   65  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   66  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   67  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   68  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   69  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   70  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   71  */
   72 
   73 #include <sys/cdefs.h>
   74 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.35.2.1 2009/01/31 21:46:18 bouyer Exp $");
   75 
   76 #include "opt_inet.h"
   77 #include "bpfilter.h"
   78 
   79 #include <sys/param.h>
   80 #include <sys/systm.h>
   81 #include <sys/mbuf.h>
   82 #include <sys/socket.h>
   83 #include <sys/ioctl.h>
   84 #include <sys/errno.h>
   85 #include <sys/syslog.h>
   86 #include <sys/select.h>
   87 #include <sys/device.h>
   88 
   89 #include <net/if.h>
   90 #include <net/if_dl.h>
   91 #include <net/if_ether.h>
   92 #include <net/if_media.h>
   93 
   94 #ifdef INET
   95 #include <netinet/in.h>
   96 #include <netinet/in_systm.h>
   97 #include <netinet/in_var.h>
   98 #include <netinet/ip.h>
   99 #include <netinet/if_inarp.h>
  100 #endif
  101 
  102 
  103 #if NBPFILTER > 0
  104 #include <net/bpf.h>
  105 #include <net/bpfdesc.h>
  106 #endif
  107 
  108 #include <machine/cpu.h>
  109 #include <machine/bus.h>
  110 #include <machine/intr.h>
  111 
  112 #include <dev/mii/miivar.h>
  113 
  114 #include <dev/ic/elink3var.h>
  115 #include <dev/ic/elink3reg.h>
  116 
  117 #include <dev/eisa/eisareg.h>
  118 #include <dev/eisa/eisavar.h>
  119 #include <dev/eisa/eisadevs.h>
  120 
  121 static int      ep_eisa_match(struct device *, struct cfdata *, void *);
  122 static void     ep_eisa_attach(struct device *, struct device *, void *);
  123 
  124 CFATTACH_DECL(ep_eisa, sizeof(struct ep_softc),
  125     ep_eisa_match, ep_eisa_attach, NULL, NULL);
  126 
  127 /* XXX move these somewhere else */
  128 /* While attaching we need a few special EISA registers of the card,
  129    these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */
  130 #define EP_EISA_CFG_BASE        0x0c80
  131 #define EP_EISA_CFG_CONTROL     0x0004  /* 1 byte */
  132 #define EP_EISA_CFG_RESOURCE    0x0008  /* 2 byte */
  133 #define EP_EISA_CFG_SIZE        0x000a
  134 
  135 /* The generic driver backend only needs access to the standard ports,
  136    mapped at the beginning of the eisa slot space */
  137 #define EP_IOPORT_OFFSET        0x0000
  138 #define EP_IOPORT_SIZE          0x0020
  139 
  140 /* Bits for the eisa control register */
  141 #define EISA_RESET      0x04
  142 #define EISA_ERROR      0x02
  143 #define EISA_ENABLE     0x01
  144 
  145 static const struct ep_eisa_product {
  146         const char      *eep_eisaid;    /* EISA ID */
  147         u_short         eep_chipset;    /* 3Com chipset used */
  148         int             eep_flags;      /* initial softc flags */
  149         const char      *eep_name;      /* device name */
  150 } ep_eisa_products[] = {
  151         { "TCM5090",                    ELINK_CHIPSET_3C509,
  152           0,                            EISA_PRODUCT_TCM5090 },
  153         { "TCM5091",                    ELINK_CHIPSET_3C509,
  154           0,                            EISA_PRODUCT_TCM5091 },
  155         { "TCM5092",                    ELINK_CHIPSET_3C509,
  156           0,                            EISA_PRODUCT_TCM5092 },
  157         { "TCM5093",                    ELINK_CHIPSET_3C509,
  158           0,                            EISA_PRODUCT_TCM5093 },
  159         { "TCM5094",                    ELINK_CHIPSET_3C509,
  160           0,                            EISA_PRODUCT_TCM5094 },
  161         { "TCM5095",                    ELINK_CHIPSET_3C509,
  162           0,                            EISA_PRODUCT_TCM5095 },
  163         { "TCM5098",                    ELINK_CHIPSET_3C509,
  164           0,                            EISA_PRODUCT_TCM5098 },
  165 
  166         /*
  167          * Note: The 3c597 Fast Etherlink MII (TCM5972) is an
  168          * MII connector for an external PHY.  We treat it as
  169          * `manual' in the core driver.
  170          */
  171         { "TCM5920",                    ELINK_CHIPSET_VORTEX,
  172           0,                            EISA_PRODUCT_TCM5920 },
  173         { "TCM5970",                    ELINK_CHIPSET_VORTEX,
  174           0,                            EISA_PRODUCT_TCM5970 },
  175         { "TCM5971",                    ELINK_CHIPSET_VORTEX,
  176           0,                            EISA_PRODUCT_TCM5971 },
  177         { "TCM5972",                    ELINK_CHIPSET_VORTEX,
  178           0,                            EISA_PRODUCT_TCM5972 },
  179 
  180         { NULL,                         0,
  181           0,                            NULL },
  182 };
  183 
  184 static const struct ep_eisa_product *
  185 ep_eisa_lookup(const struct eisa_attach_args *ea)
  186 {
  187         const struct ep_eisa_product *eep;
  188 
  189         for (eep = ep_eisa_products; eep->eep_name != NULL; eep++)
  190                 if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0)
  191                         return (eep);
  192 
  193         return (NULL);
  194 }
  195 
  196 static int
  197 ep_eisa_match(struct device *parent, struct cfdata *match,
  198     void *aux)
  199 {
  200         struct eisa_attach_args *ea = aux;
  201 
  202         /* must match one of our known ID strings */
  203         if (ep_eisa_lookup(ea) != NULL)
  204                 return (1);
  205 
  206         return (0);
  207 }
  208 
  209 static void
  210 ep_eisa_attach(struct device *parent, struct device *self, void *aux)
  211 {
  212         struct ep_softc *sc = device_private(self);
  213         struct eisa_attach_args *ea = aux;
  214         bus_space_tag_t iot = ea->ea_iot;
  215         bus_space_handle_t ioh, ioh_cfg;
  216         eisa_chipset_tag_t ec = ea->ea_ec;
  217         eisa_intr_handle_t ih;
  218         const char *intrstr;
  219         const struct ep_eisa_product *eep;
  220         u_int irq;
  221 
  222         /* Map i/o space. */
  223         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_EISA_CFG_BASE,
  224             EP_EISA_CFG_SIZE, 0, &ioh_cfg)) {
  225                 printf("\n");
  226                 panic("ep_eisa_attach: can't map eisa cfg i/o space");
  227         }
  228         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_IOPORT_OFFSET,
  229             EP_IOPORT_SIZE, 0, &ioh)) {
  230                 printf("\n");
  231                 panic("ep_eisa_attach: can't map i/o space");
  232         }
  233 
  234         sc->sc_ioh = ioh;
  235         sc->sc_iot = iot;
  236 
  237         bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL, EISA_ENABLE);
  238         delay(4000);
  239 
  240         /* Read the IRQ from the card. */
  241         irq = bus_space_read_2(iot, ioh_cfg, EP_EISA_CFG_RESOURCE) >> 12;
  242 
  243         eep = ep_eisa_lookup(ea);
  244         if (eep == NULL) {
  245                 printf("\n");
  246                 panic("ep_eisa_attach: impossible");
  247         }
  248 
  249         /* we don't need access to the config registers any more, but
  250            noone else should be able to map this space, so keep it
  251            reserved? */
  252 #if 0
  253         bus_space_unmap(iot, ioh_cfg, EP_EISA_CFG_SIZE);
  254 #endif
  255 
  256         printf(": %s\n", eep->eep_name);
  257 
  258         sc->enable = NULL;
  259         sc->disable = NULL;
  260         sc->enabled = 1;
  261 
  262         sc->bustype = ELINK_BUS_EISA;
  263         sc->ep_flags = eep->eep_flags;
  264 
  265         if (eisa_intr_map(ec, irq, &ih)) {
  266                 printf("%s: couldn't map interrupt (%u)\n",
  267                     sc->sc_dev.dv_xname, irq);
  268                 return;
  269         }
  270         intrstr = eisa_intr_string(ec, ih);
  271         sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
  272             epintr, sc);
  273         if (sc->sc_ih == NULL) {
  274                 printf("%s: couldn't establish interrupt",
  275                     sc->sc_dev.dv_xname);
  276                 if (intrstr != NULL)
  277                         printf(" at %s", intrstr);
  278                 printf("\n");
  279                 return;
  280         }
  281         if (intrstr != NULL)
  282                 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
  283                     intrstr);
  284 
  285         epconfig(sc, eep->eep_chipset, NULL);
  286 }

Cache object: 37b3ed319ed188f003b9f6bc5b64d792


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