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/mca/if_tr_mca.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_tr_mca.c,v 1.10 2002/10/02 16:34:12 thorpej Exp $ */
    2 
    3 /*_
    4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Gregory McGarry <g.mcgarry@ieee.org>.
    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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
   27  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   28  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   29  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   31  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   35  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   36  */
   37 
   38 #include <sys/cdefs.h>
   39 __KERNEL_RCSID(0, "$NetBSD: if_tr_mca.c,v 1.10 2002/10/02 16:34:12 thorpej Exp $");
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/socket.h>
   44 #include <sys/device.h>
   45 
   46 #include <dev/mca/mcareg.h>
   47 #include <dev/mca/mcavar.h>
   48 #include <dev/mca/mcadevs.h>
   49 
   50 #include <net/if.h>
   51 #include <net/if_media.h>
   52 #include <net/if_ether.h>
   53 
   54 #include <dev/ic/tropicreg.h>
   55 #include <dev/ic/tropicvar.h>
   56 
   57 #ifdef DEBUG
   58 #define DPRINTF(x) printf x
   59 #else
   60 #define DPRINTF(x)
   61 #endif
   62 
   63 #define TR_PRI_IOADDR 0x0a20
   64 #define TR_ALT_IOADDR 0x0a24
   65 #define TR_PIOSIZE 4
   66 #define TR_MMIOSIZE 8192
   67 #define TR_MBPS_4 0
   68 #define TR_MBPS_16 1
   69 
   70 int     tr_mca_probe __P((struct device *, struct cfdata *, void *));
   71 void    tr_mca_attach __P((struct device *, struct device *, void *));
   72 
   73 CFATTACH_DECL(tr_mca, sizeof(struct tr_softc),
   74     tr_mca_probe, tr_mca_attach, NULL, NULL);
   75 
   76 /* supported products */
   77 static const struct tr_mca_product {
   78         u_int32_t tr_id;
   79         const char *tr_name;
   80 } tr_mca_products[] = {
   81         { MCA_PRODUCT_ITR, "IBM Token Ring 16/4 Adapter/A" },
   82         { 0, NULL },
   83 };
   84 
   85 static const struct tr_mca_product *tr_mca_lookup __P((int));
   86 
   87 static const struct tr_mca_product *
   88 tr_mca_lookup(id)
   89         int id;
   90 {
   91         const struct tr_mca_product *trp;
   92 
   93         for(trp = tr_mca_products; trp->tr_name; trp++)
   94                 if (trp->tr_id == id)
   95                         return (trp);
   96 
   97         return (NULL);
   98 }
   99 
  100 int
  101 tr_mca_probe(parent, match, aux)
  102         struct device  *parent;
  103         struct cfdata  *match;
  104         void           *aux;
  105 {
  106         struct mca_attach_args *ma = aux;
  107 
  108         if (tr_mca_lookup(ma->ma_id) != NULL)
  109                 return (1);
  110 
  111         return (0);
  112 }
  113 
  114 
  115 void
  116 tr_mca_attach(parent, self, aux)
  117         struct device  *parent, *self;
  118         void           *aux;
  119 {
  120         struct tr_softc *sc = (void *) self;
  121         struct mca_attach_args *ma = aux;
  122         bus_space_handle_t pioh, mmioh, sramh;
  123         int iobase, irq, sram_size, sram_addr, rom_addr;
  124         int pos2, pos3, pos4, pos5;
  125         const struct tr_mca_product *tp;
  126 
  127         pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
  128         pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
  129         pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
  130         pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
  131 
  132         /*
  133          * POS register 2: (adf pos0)
  134          * 
  135          * 7 6 5 4 3 2 1 0
  136          * \___________/ \__ enable: 0=adapter disabled, 1=adapter enabled
  137          *       \__________ RAM addr: pos2&0xfe
  138          * 
  139          * POS register 3: (adf pos1)
  140          * 
  141          * 7 6 5 4 3 2 1 0
  142          * | \___/ | | | \__ port address: 1=0x0a24-0x0a27, 0=0x0a20-0x0a23
  143          * |   |   \ / \____ speed: 0=4Mbps, 1=16Mbps
  144          * |   |    \_______ RAM size: 00=8kb, 01=16kb, 10=32kb, 11=64kb
  145          * |   \____________ reserved: 010
  146          * \________________ irq component: 0=2, 1=3 (see also pos4)
  147          * 
  148          * POS register 4: (adf pos2)
  149          * 
  150          * 7 6 5 4 3 2 1 0
  151          * \___________/ \__ interrupt controller: 0=1st, 1=2nd
  152          *       \__________ ROM address: pos4&0xfe
  153          * 
  154          * POS register 5: (adf pos3)
  155          * 
  156          * 7 6 5 4 3 2 1 0
  157          * | | \_____/ 
  158          * | |    \_____ reserved: 0x0
  159          * | \__________ autosense: 0=off, 1=on
  160          * \____________ boot rom: 0=enabled, 1=disabled
  161          */
  162 
  163         if (pos3 & 0x01)
  164                 iobase = TR_ALT_IOADDR;
  165         else
  166                 iobase = TR_PRI_IOADDR;
  167 
  168         irq = 2 + (pos3 >> 7) + ((pos4 & 0x01) << 3);
  169         if (irq == 2)
  170                 irq = 9;
  171 
  172         tp = tr_mca_lookup(ma->ma_id);
  173 
  174         printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, tp->tr_name);
  175 
  176         sram_size = 8 << (((pos3 & 0x0c) >> 2) + 10);
  177         sram_addr = (pos2 & 0xfe) << 12;
  178 
  179         rom_addr = (pos4 & 0xfe) << 12;
  180 
  181         /* map the pio registers */
  182         if (bus_space_map(ma->ma_iot, iobase, TR_PIOSIZE, 0, &pioh)) {
  183                 printf("%s: unable to map PIO space\n", sc->sc_dev.dv_xname);
  184                 return;
  185         }
  186 
  187         /* map the mmio registers */
  188         if (bus_space_map(ma->ma_memt, rom_addr, TR_MMIOSIZE, 0, &mmioh)) {
  189                 printf("%s: unable to map MMIO space\n", sc->sc_dev.dv_xname);
  190                 return;
  191         }
  192 
  193         /* map the sram space */
  194         if (bus_space_map(ma->ma_memt, sram_addr, sram_size, 0, &sramh)) {
  195                 printf("%s: unable to map SRAM space\n", sc->sc_dev.dv_xname);
  196                 return;
  197         }
  198 
  199         sc->sc_piot = ma->ma_iot;
  200         sc->sc_pioh = pioh;
  201         sc->sc_memt = ma->ma_memt;
  202         sc->sc_mmioh = mmioh;
  203         sc->sc_sramh = sramh;
  204 
  205         /* set ACA offset */
  206         sc->sc_aca = TR_ACA_OFFSET;
  207         sc->sc_memwinsz = sram_size;
  208         sc->sc_maddr = sram_addr;
  209 
  210         /*
  211          * Determine total RAM on adapter and decide how much to use.
  212          * XXX Since we don't use RAM paging, use sc_memwinsz for now.
  213          */
  214         sc->sc_memsize = sc->sc_memwinsz;
  215         sc->sc_memreserved = 0;
  216 
  217         if (tr_reset(sc) != 0)
  218                 return;
  219 
  220         /* XXX not implemented (yet) */
  221         sc->sc_mediastatus = NULL;
  222         sc->sc_mediachange = NULL;
  223 
  224         /* do generic attach */
  225         if (tr_attach(sc) != 0)
  226                 return;
  227 
  228         /* establish interrupt handler */
  229         sc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, tr_intr, sc);
  230         if (sc->sc_ih == NULL) {
  231                 printf("%s: couldn't establish interrupt handler\n",
  232                        sc->sc_dev.dv_xname);
  233                 return;
  234         }
  235 
  236 }

Cache object: 345cb31a4f4ca89fe66d92cf1363d7a5


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