[BACK]Return to if_fpa.c CVS log [TXT][DIR] Up to [local] / sys / dev / pci

Annotation of sys/dev/pci/if_fpa.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: if_fpa.c,v 1.24 2005/09/11 18:17:08 mickey Exp $      */
                      2: /*     $NetBSD: if_fpa.c,v 1.15 1996/10/21 22:56:40 thorpej Exp $      */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. The name of the author may not be used to endorse or promote products
                     14:  *    derived from this software without specific prior written permission
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     18:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     19:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     20:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     21:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     25:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  *
                     27:  * Id: if_fpa.c,v 1.8 1996/05/17 01:15:18 thomas Exp
                     28:  *
                     29:  */
                     30:
                     31: /*
                     32:  * DEC PDQ FDDI Controller; code for BSD derived operating systems
                     33:  *
                     34:  *   This module supports the DEC DEFPA PCI FDDI Controller
                     35:  */
                     36:
                     37:
                     38: #include <sys/param.h>
                     39: #include <sys/kernel.h>
                     40: #include <sys/mbuf.h>
                     41: #include <sys/protosw.h>
                     42: #include <sys/socket.h>
                     43: #include <sys/ioctl.h>
                     44: #include <sys/errno.h>
                     45: #include <sys/malloc.h>
                     46: #include <sys/device.h>
                     47:
                     48: #include <net/if.h>
                     49: #include <net/if_types.h>
                     50: #include <net/if_dl.h>
                     51: #include <net/route.h>
                     52:
                     53: #include "bpfilter.h"
                     54: #if NBPFILTER > 0
                     55: #include <net/bpf.h>
                     56: #endif
                     57:
                     58: #ifdef INET
                     59: #include <netinet/in.h>
                     60: #include <netinet/if_ether.h>
                     61: #endif
                     62: #include <net/if_fddi.h>
                     63:
                     64: #include <dev/pci/pcidevs.h>
                     65: #include <dev/pci/pcivar.h>
                     66: #include <dev/ic/pdqvar.h>
                     67: #include <dev/ic/pdqreg.h>
                     68:
                     69: #define        DEFPA_LATENCY   0x88
                     70: #define        DEFPA_CBMA      (PCI_MAPREG_START + 0)  /* Config Base Memory Address */
                     71: #define        DEFPA_CBIO      (PCI_MAPREG_START + 4)  /* Config Base I/O Address */
                     72:
                     73: int  pdq_pci_ifintr(void *);
                     74: int  pdq_pci_match(struct device *, void *, void *);
                     75: void pdq_pci_attach(struct device *, struct device *, void *aux);
                     76:
                     77: int
                     78: pdq_pci_ifintr(arg)
                     79:        void *arg;
                     80: {
                     81:        pdq_softc_t *sc = (pdq_softc_t *)arg;
                     82:        (void) pdq_interrupt(sc->sc_pdq);
                     83:        return (1);
                     84: }
                     85:
                     86: int
                     87: pdq_pci_match(parent, match, aux)
                     88:        struct device *parent;
                     89:        void *match;
                     90:        void *aux;
                     91: {
                     92:        struct pci_attach_args *pa = (struct pci_attach_args *)aux;
                     93:
                     94:        if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DEC &&
                     95:            PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DEC_DEFPA)
                     96:                return (1);
                     97:        return (0);
                     98: }
                     99:
                    100: void
                    101: pdq_pci_attach(parent, self, aux)
                    102:        struct device *parent;
                    103:        struct device *self;
                    104:        void *aux;
                    105: {
                    106:        pdq_softc_t *sc = (pdq_softc_t *)self;
                    107:        struct pci_attach_args *pa = (struct pci_attach_args *)aux;
                    108:        u_int32_t data;
                    109:        pci_intr_handle_t intrhandle;
                    110:        const char *intrstr;
                    111:        bus_size_t csrsize;
                    112:
                    113:        data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
                    114:        if (PCI_LATTIMER(data) < DEFPA_LATENCY) {
                    115:                data &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
                    116:                data |= (DEFPA_LATENCY & PCI_LATTIMER_MASK)
                    117:                    << PCI_LATTIMER_SHIFT;
                    118:                pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, data);
                    119:        }
                    120:
                    121:        bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
                    122:        sc->sc_if.if_flags = 0;
                    123:        sc->sc_if.if_softc = sc;
                    124:
                    125:        /*
                    126:         * NOTE: sc_bc is an alias for sc_csrtag and sc_membase is an
                    127:         * alias for sc_csrhandle.  sc_iobase is not used in this front-end.
                    128:         */
                    129: #ifdef PDQ_IOMAPPED
                    130:        if (pci_mapreg_map(pa, DEFPA_CBIO, PCI_MAPREG_TYPE_IO, 0,
                    131:            &sc->sc_csrtag, &sc->sc_csrhandle, NULL, &csrsize, 0)) {
                    132:                printf(": can't map I/O space!\n");
                    133:                return;
                    134:        }
                    135: #else
                    136:        if (pci_mapreg_map(pa, DEFPA_CBMA, PCI_MAPREG_TYPE_MEM, 0,
                    137:            &sc->sc_csrtag, &sc->sc_csrhandle, NULL, &csrsize, 0)) {
                    138:                printf(": can't map memory space!\n");
                    139:                return;
                    140:        }
                    141: #endif
                    142:
                    143:        if (pci_intr_map(pa, &intrhandle)) {
                    144:                printf(": couldn't map interrupt\n");
                    145:                bus_space_unmap(sc->sc_csrtag, sc->sc_csrhandle, csrsize);
                    146:                return;
                    147:        }
                    148:        intrstr = pci_intr_string(pa->pa_pc, intrhandle);
                    149:        sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET,
                    150:            pdq_pci_ifintr, sc, self->dv_xname);
                    151:        if (sc->sc_ih == NULL) {
                    152:                printf(": couldn't establish interrupt");
                    153:                if (intrstr != NULL)
                    154:                        printf(" at %s", intrstr);
                    155:                printf("\n");
                    156:                bus_space_unmap(sc->sc_csrtag, sc->sc_csrhandle, csrsize);
                    157:                return;
                    158:        }
                    159:        if (intrstr != NULL)
                    160:                printf(": %s\n", intrstr);
                    161:
                    162:        sc->sc_pdq = pdq_initialize(sc->sc_csrtag, sc->sc_csrhandle,
                    163:            sc->sc_if.if_xname, 0, (void *) sc, PDQ_DEFPA);
                    164:        if (sc->sc_pdq == NULL) {
                    165:                printf(": initialization failed\n");
                    166:                bus_space_unmap(sc->sc_csrtag, sc->sc_csrhandle, csrsize);
                    167:                return;
                    168:        }
                    169:
                    170:        bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes,
                    171:            sc->sc_arpcom.ac_enaddr, 6);
                    172:        pdq_ifattach(sc, NULL);
                    173:
                    174:        sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset,
                    175:            sc->sc_pdq);
                    176:        if (sc->sc_ats == NULL)
                    177:                printf("%s: warning: couldn't establish shutdown hook\n",
                    178:                    self->dv_xname);
                    179: }
                    180:
                    181: struct cfattach fpa_ca = {
                    182:        sizeof(pdq_softc_t), pdq_pci_match, pdq_pci_attach
                    183: };
                    184:
                    185: struct cfdriver fpa_cd = {
                    186:        0, "fpa", DV_IFNET
                    187: };

CVSweb