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

Annotation of sys/dev/pci/if_en_pci.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: if_en_pci.c,v 1.11 2005/09/11 18:17:08 mickey Exp $   */
        !             2:
        !             3: /*
        !             4:  *
        !             5:  * Copyright (c) 1996 Charles D. Cranor and Washington University.
        !             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. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. All advertising materials mentioning features or use of this software
        !            17:  *    must display the following acknowledgement:
        !            18:  *      This product includes software developed by Charles D. Cranor and
        !            19:  *     Washington University.
        !            20:  * 4. The name of the author may not be used to endorse or promote products
        !            21:  *    derived from this software without specific prior written permission.
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            24:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            25:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            26:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            27:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            28:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            29:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            30:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            31:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            32:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            33:  */
        !            34:
        !            35: /*
        !            36:  *
        !            37:  * i f _ e n _ p c i . c
        !            38:  *
        !            39:  * author: Chuck Cranor <chuck@ccrc.wustl.edu>
        !            40:  * started: spring, 1996.
        !            41:  *
        !            42:  * PCI glue for the eni155p card.
        !            43:  */
        !            44:
        !            45: #include <sys/param.h>
        !            46: #include <sys/systm.h>
        !            47: #include <sys/device.h>
        !            48: #include <sys/mbuf.h>
        !            49: #include <sys/socket.h>
        !            50: #include <sys/socketvar.h>
        !            51:
        !            52: #include <net/if.h>
        !            53:
        !            54: #include <dev/pci/pcivar.h>
        !            55: #include <dev/pci/pcireg.h>
        !            56: #include <dev/pci/pcidevs.h>
        !            57:
        !            58: #include <dev/ic/midwayreg.h>
        !            59: #include <dev/ic/midwayvar.h>
        !            60:
        !            61:
        !            62: /*
        !            63:  * local structures
        !            64:  */
        !            65:
        !            66: struct en_pci_softc {
        !            67:   /* bus independent stuff */
        !            68:   struct en_softc esc;         /* includes "device" structure */
        !            69:
        !            70:   /* PCI bus glue */
        !            71:   void *sc_ih;                 /* interrupt handle */
        !            72:   pci_chipset_tag_t en_pc;     /* for PCI calls */
        !            73:
        !            74: };
        !            75:
        !            76: /*
        !            77:  * local defines (PCI specific stuff)
        !            78:  */
        !            79:
        !            80: /*
        !            81:  * address of config base memory address register in PCI config space
        !            82:  * (this is card specific)
        !            83:  */
        !            84:
        !            85: #define PCI_CBMA        0x10
        !            86:
        !            87: /*
        !            88:  * tonga (pci bridge).   ENI cards only!
        !            89:  */
        !            90:
        !            91: #define EN_TONGA        0x60            /* PCI config addr of tonga reg */
        !            92:
        !            93: #define TONGA_SWAP_DMA  0x80            /* endian swap control */
        !            94: #define TONGA_SWAP_BYTE 0x40
        !            95: #define TONGA_SWAP_WORD 0x20
        !            96:
        !            97: /*
        !            98:  * adaptec pci bridge.   ADP cards only!
        !            99:  */
        !           100:
        !           101: #define ADP_PCIREG     0x050040        /* PCI control register */
        !           102:
        !           103: #define ADP_PCIREG_RESET       0x1     /* reset card */
        !           104: #define ADP_PCIREG_IENABLE     0x2     /* interrupt enable */
        !           105: #define ADP_PCIREG_SWAP_WORD   0x4     /* swap byte on slave access */
        !           106: #define ADP_PCIREG_SWAP_DMA    0x8     /* swap bytes on DMA */
        !           107:
        !           108: /*
        !           109:  * prototypes
        !           110:  */
        !           111:
        !           112: static int en_pci_match(struct device *, void *, void *);
        !           113: static void en_pci_attach(struct device *, struct device *, void *);
        !           114:
        !           115: /*
        !           116:  * PCI autoconfig attachments
        !           117:  */
        !           118:
        !           119: struct cfattach en_pci_ca = {
        !           120:     sizeof(struct en_pci_softc), en_pci_match, en_pci_attach,
        !           121: };
        !           122:
        !           123: #if !defined(MIDWAY_ENIONLY)
        !           124:
        !           125: static void adp_busreset(void *);
        !           126:
        !           127: /*
        !           128:  * bus specific reset function [ADP only!]
        !           129:  */
        !           130:
        !           131: static void adp_busreset(v)
        !           132:
        !           133: void *v;
        !           134:
        !           135: {
        !           136:   struct en_softc *sc = (struct en_softc *) v;
        !           137:   u_int32_t dummy;
        !           138:
        !           139:   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG, ADP_PCIREG_RESET);
        !           140:   DELAY(1000);  /* let it reset */
        !           141:   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
        !           142:   bus_space_write_4(sc->en_memt, sc->en_base, ADP_PCIREG,
        !           143:                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA|ADP_PCIREG_IENABLE));
        !           144:   dummy = bus_space_read_4(sc->en_memt, sc->en_base, ADP_PCIREG);
        !           145:   if ((dummy & (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA)) !=
        !           146:                 (ADP_PCIREG_SWAP_WORD|ADP_PCIREG_SWAP_DMA))
        !           147:     printf("adp_busreset: Adaptec ATM did NOT reset!\n");
        !           148:
        !           149: }
        !           150: #endif
        !           151:
        !           152: /***********************************************************************/
        !           153:
        !           154: /*
        !           155:  * autoconfig stuff
        !           156:  */
        !           157:
        !           158: static int en_pci_match(parent, match, aux)
        !           159:
        !           160: struct device *parent;
        !           161: void *match;
        !           162: void *aux;
        !           163:
        !           164: {
        !           165:   struct pci_attach_args *pa = (struct pci_attach_args *) aux;
        !           166:
        !           167: #if !defined(MIDWAY_ADPONLY)
        !           168:   if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_EFFICIENTNETS &&
        !           169:       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PF ||
        !           170:        PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_EFFICIENTNETS_ENI155PA))
        !           171:     return 1;
        !           172: #endif
        !           173:
        !           174: #if !defined(MIDWAY_ENIONLY)
        !           175:   if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADP &&
        !           176:       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADP_AIC5900 ||
        !           177:        PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADP_AIC5905))
        !           178:     return 1;
        !           179: #endif
        !           180:
        !           181:   return 0;
        !           182: }
        !           183:
        !           184:
        !           185: static void en_pci_attach(parent, self, aux)
        !           186:
        !           187: struct device *parent, *self;
        !           188: void *aux;
        !           189:
        !           190: {
        !           191:   struct en_softc *sc = (void *)self;
        !           192:   struct en_pci_softc *scp = (void *)self;
        !           193:   struct pci_attach_args *pa = aux;
        !           194:   pci_intr_handle_t ih;
        !           195:   const char *intrstr;
        !           196:   int retval;
        !           197:
        !           198:   sc->is_adaptec = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADP) ? 1 : 0;
        !           199:   scp->en_pc = pa->pa_pc;
        !           200:
        !           201:   /*
        !           202:    * interrupt map
        !           203:    */
        !           204:
        !           205:   if (pci_intr_map(pa, &ih)) {
        !           206:     printf(": couldn't map interrupt\n");
        !           207:     return;
        !           208:   }
        !           209:   intrstr = pci_intr_string(scp->en_pc, ih);
        !           210:   scp->sc_ih = pci_intr_establish(scp->en_pc, ih, IPL_NET, en_intr, sc,
        !           211:       sc->sc_dev.dv_xname);
        !           212:   if (scp->sc_ih == NULL) {
        !           213:     printf(": couldn't establish interrupt");
        !           214:     if (intrstr != NULL)
        !           215:       printf(" at %s", intrstr);
        !           216:     printf("\n");
        !           217:     return;
        !           218:   }
        !           219:   sc->ipl = 1; /* XXX */
        !           220:
        !           221:   /*
        !           222:    * memory map
        !           223:    */
        !           224:
        !           225:   retval = pci_mapreg_map(pa, PCI_CBMA, PCI_MAPREG_TYPE_MEM, 0,
        !           226:     &sc->en_memt, &sc->en_base, NULL, &sc->en_obmemsz, 0);
        !           227:
        !           228:   if (retval) {
        !           229:     printf(": couldn't map memory\n");
        !           230:     return;
        !           231:   }
        !           232:
        !           233:   printf(": %s\n", intrstr);
        !           234:
        !           235:   /*
        !           236:    * set up pci bridge
        !           237:    */
        !           238:
        !           239: #if !defined(MIDWAY_ENIONLY)
        !           240:   if (sc->is_adaptec) {
        !           241:     sc->en_busreset = adp_busreset;
        !           242:     adp_busreset(sc);
        !           243:   }
        !           244: #endif
        !           245:
        !           246: #if !defined(MIDWAY_ADPONLY)
        !           247:   if (!sc->is_adaptec) {
        !           248:     sc->en_busreset = NULL;
        !           249:     pci_conf_write(scp->en_pc, pa->pa_tag, EN_TONGA,
        !           250:                  (TONGA_SWAP_DMA|TONGA_SWAP_WORD));
        !           251:   }
        !           252: #endif
        !           253:
        !           254:   /*
        !           255:    * done PCI specific stuff
        !           256:    */
        !           257:
        !           258:   en_attach(sc);
        !           259:
        !           260: }

CVSweb