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

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

1.1       nbrk        1: /*     $OpenBSD: if_fxp_pci.c,v 1.49 2006/11/05 02:47:01 brad Exp $    */
                      2:
                      3: /*
                      4:  * Copyright (c) 1995, David Greenman
                      5:  * All rights reserved.
                      6:  *
                      7:  * Modifications to support NetBSD:
                      8:  * Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
                      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 unmodified, this list of conditions, and the following
                     15:  *    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:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     Id: if_fxp.c,v 1.55 1998/08/04 08:53:12 dg Exp
                     33:  */
                     34:
                     35: /*
                     36:  * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
                     37:  */
                     38:
                     39: #include "bpfilter.h"
                     40:
                     41: #include <sys/param.h>
                     42: #include <sys/systm.h>
                     43: #include <sys/mbuf.h>
                     44: #include <sys/malloc.h>
                     45: #include <sys/kernel.h>
                     46: #include <sys/socket.h>
                     47: #include <sys/timeout.h>
                     48: #include <sys/syslog.h>
                     49:
                     50: #include <net/if.h>
                     51: #include <net/if_dl.h>
                     52: #include <net/if_media.h>
                     53: #include <net/if_types.h>
                     54:
                     55: #ifdef INET
                     56: #include <netinet/in.h>
                     57: #include <netinet/in_systm.h>
                     58: #include <netinet/in_var.h>
                     59: #include <netinet/ip.h>
                     60: #endif
                     61:
                     62: #include <sys/ioctl.h>
                     63: #include <sys/errno.h>
                     64: #include <sys/device.h>
                     65:
                     66: #include <netinet/if_ether.h>
                     67:
                     68: #include <machine/cpu.h>
                     69: #include <machine/bus.h>
                     70: #include <machine/intr.h>
                     71:
                     72: #include <dev/mii/miivar.h>
                     73:
                     74: #include <dev/ic/fxpreg.h>
                     75: #include <dev/ic/fxpvar.h>
                     76:
                     77: #include <dev/pci/pcivar.h>
                     78: #include <dev/pci/pcireg.h>
                     79: #include <dev/pci/pcidevs.h>
                     80:
                     81: int fxp_pci_match(struct device *, void *, void *);
                     82: void fxp_pci_attach(struct device *, struct device *, void *);
                     83:
                     84: struct cfattach fxp_pci_ca = {
                     85:        sizeof(struct fxp_softc), fxp_pci_match, fxp_pci_attach
                     86: };
                     87:
                     88: const struct pci_matchid fxp_pci_devices[] = {
                     89:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_8255x },
                     90:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559 },
                     91:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559ER },
                     92:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562 },
                     93:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_0 },
                     94:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_1 },
                     95:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_2 },
                     96:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_0 },
                     97:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 },
                     98:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 },
                     99:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 },
                    100:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_4 },
                    101:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_5 },
                    102:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_6 },
                    103:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_7 },
                    104:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_8 },
                    105:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 },
                    106:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 },
                    107:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 },
                    108:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 },
                    109:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_4 },
                    110:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_5 },
                    111:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_6 },
                    112:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_7 },
                    113:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_8 },
                    114:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_9 },
                    115:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_10 },
                    116:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_11 },
                    117:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_12 },
                    118:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_13 },
                    119:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_14 },
                    120:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_15 },
                    121:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_16 },
                    122:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_17 },
                    123:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_18 },
                    124:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_19 },
                    125:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_M },
                    126:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100 },
                    127:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LAN },
                    128:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_1 },
                    129:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_2 },
                    130:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN },
                    131:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN_2 },
                    132:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LAN },
                    133:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN },
                    134:        { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN_2 },
                    135: };
                    136:
                    137: int
                    138: fxp_pci_match(struct device *parent, void *match, void *aux)
                    139: {
                    140:        return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices,
                    141:            sizeof(fxp_pci_devices)/sizeof(fxp_pci_devices[0])));
                    142: }
                    143:
                    144: void
                    145: fxp_pci_attach(struct device *parent, struct device *self, void *aux)
                    146: {
                    147:        struct fxp_softc *sc = (struct fxp_softc *)self;
                    148:        struct pci_attach_args *pa = aux;
                    149:        pci_chipset_tag_t pc = pa->pa_pc;
                    150:        pci_intr_handle_t ih;
                    151:        const char *chipname = NULL;
                    152:        const char *intrstr = NULL;
                    153:        bus_size_t iosize;
                    154:
                    155:        if (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0,
                    156:            &sc->sc_st, &sc->sc_sh, NULL, &iosize, 0)) {
                    157:                printf(": can't map i/o space\n");
                    158:                return;
                    159:        }
                    160:        sc->sc_dmat = pa->pa_dmat;
                    161:
                    162:        sc->sc_revision = PCI_REVISION(pa->pa_class);
                    163:
                    164:        /*
                    165:         * Allocate our interrupt.
                    166:         */
                    167:        if (pci_intr_map(pa, &ih)) {
                    168:                printf(": couldn't map interrupt\n");
                    169:                bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
                    170:                return;
                    171:        }
                    172:
                    173:        intrstr = pci_intr_string(pc, ih);
                    174:        sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc,
                    175:            self->dv_xname);
                    176:        if (sc->sc_ih == NULL) {
                    177:                printf(": couldn't establish interrupt");
                    178:                if (intrstr != NULL)
                    179:                        printf(" at %s", intrstr);
                    180:                printf("\n");
                    181:                bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
                    182:                return;
                    183:        }
                    184:
                    185:        switch (PCI_PRODUCT(pa->pa_id)) {
                    186:        case PCI_PRODUCT_INTEL_8255x:
                    187:        case PCI_PRODUCT_INTEL_82559:
                    188:        case PCI_PRODUCT_INTEL_82559ER:
                    189:        {
                    190:                chipname = "i82557";
                    191:                if (sc->sc_revision >= FXP_REV_82558_A4)
                    192:                        chipname = "i82558";
                    193:                if (sc->sc_revision >= FXP_REV_82559_A0)
                    194:                        chipname = "i82559";
                    195:                if (sc->sc_revision >= FXP_REV_82559S_A)
                    196:                        chipname = "i82559S";
                    197:                if (sc->sc_revision >= FXP_REV_82550)
                    198:                        chipname = "i82550";
                    199:                if (sc->sc_revision >= FXP_REV_82551_E)
                    200:                        chipname = "i82551";
                    201:                break;
                    202:        }
                    203:                break;
                    204:        default:
                    205:                chipname = "i82562";
                    206:                break;
                    207:        }
                    208:
                    209:        if (chipname != NULL)
                    210:                printf(", %s", chipname);
                    211:
                    212:        /*
                    213:         * Cards for which we should WRITE TO THE EEPROM
                    214:         * to turn off dynamic standby mode to avoid
                    215:         * a problem where the card will fail to resume when
                    216:         * entering the IDLE state. We use this nasty if statement
                    217:         * and corresponding pci dev numbers directly so that people
                    218:         * know not to add new cards to this unless you are really
                    219:         * certain what you are doing and are not going to end up
                    220:         * killing people's eeproms.
                    221:         */
                    222:        if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) &&
                    223:            (PCI_PRODUCT(pa->pa_id) == 0x2449 ||
                    224:            (PCI_PRODUCT(pa->pa_id) > 0x1030 &&
                    225:            PCI_PRODUCT(pa->pa_id) < 0x1039) ||
                    226:            (PCI_PRODUCT(pa->pa_id) == 0x1229 &&
                    227:            (sc->sc_revision >= 8 && sc->sc_revision <= 16))))
                    228:                sc->sc_flags |= FXPF_DISABLE_STANDBY;
                    229:
                    230:        /*
                    231:         * enable PCI Memory Write and Invalidate command
                    232:         */
                    233:        if (sc->sc_revision >= FXP_REV_82558_A4)
                    234:                if (PCI_CACHELINE(pci_conf_read(pa->pa_pc, pa->pa_tag,
                    235:                    PCI_BHLC_REG))) {
                    236:                        pci_conf_write(pa->pa_pc, pa->pa_tag,
                    237:                            PCI_COMMAND_STATUS_REG,
                    238:                            PCI_COMMAND_INVALIDATE_ENABLE |
                    239:                            pci_conf_read(pa->pa_pc, pa->pa_tag,
                    240:                            PCI_COMMAND_STATUS_REG));
                    241:                        sc->sc_flags |= FXPF_MWI_ENABLE;
                    242:                }
                    243:
                    244:        /* Do generic parts of attach. */
                    245:        if (fxp_attach(sc, intrstr)) {
                    246:                /* Failed! */
                    247:                pci_intr_disestablish(pc, sc->sc_ih);
                    248:                bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
                    249:                return;
                    250:        }
                    251: }

CVSweb