1*0f9891f1Sjsg /* $OpenBSD: if_ti_pci.c,v 1.8 2024/05/24 06:02:57 jsg Exp $ */
251d3a2bcSkettenis
351d3a2bcSkettenis /*
451d3a2bcSkettenis * Copyright (c) 1997, 1998, 1999
551d3a2bcSkettenis * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
651d3a2bcSkettenis *
751d3a2bcSkettenis * Redistribution and use in source and binary forms, with or without
851d3a2bcSkettenis * modification, are permitted provided that the following conditions
951d3a2bcSkettenis * are met:
1051d3a2bcSkettenis * 1. Redistributions of source code must retain the above copyright
1151d3a2bcSkettenis * notice, this list of conditions and the following disclaimer.
1251d3a2bcSkettenis * 2. Redistributions in binary form must reproduce the above copyright
1351d3a2bcSkettenis * notice, this list of conditions and the following disclaimer in the
1451d3a2bcSkettenis * documentation and/or other materials provided with the distribution.
1551d3a2bcSkettenis * 3. All advertising materials mentioning features or use of this software
1651d3a2bcSkettenis * must display the following acknowledgement:
1751d3a2bcSkettenis * This product includes software developed by Bill Paul.
1851d3a2bcSkettenis * 4. Neither the name of the author nor the names of any co-contributors
1951d3a2bcSkettenis * may be used to endorse or promote products derived from this software
2051d3a2bcSkettenis * without specific prior written permission.
2151d3a2bcSkettenis *
2251d3a2bcSkettenis * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2351d3a2bcSkettenis * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2451d3a2bcSkettenis * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2551d3a2bcSkettenis * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2651d3a2bcSkettenis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2751d3a2bcSkettenis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2851d3a2bcSkettenis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2951d3a2bcSkettenis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3051d3a2bcSkettenis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3151d3a2bcSkettenis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3251d3a2bcSkettenis * THE POSSIBILITY OF SUCH DAMAGE.
3351d3a2bcSkettenis *
3451d3a2bcSkettenis * $FreeBSD: src/sys/pci/if_ti.c,v 1.25 2000/01/18 00:26:29 wpaul Exp $
3551d3a2bcSkettenis */
3651d3a2bcSkettenis
3751d3a2bcSkettenis /*
3851d3a2bcSkettenis * Alteon Networks Tigon PCI gigabit ethernet driver for OpenBSD.
3951d3a2bcSkettenis *
4051d3a2bcSkettenis * Written by Bill Paul <wpaul@ctr.columbia.edu>
4151d3a2bcSkettenis * Electrical Engineering Department
4251d3a2bcSkettenis * Columbia University, New York City
4351d3a2bcSkettenis */
4451d3a2bcSkettenis
4551d3a2bcSkettenis /*
4651d3a2bcSkettenis * The Alteon Networks Tigon chip contains an embedded R4000 CPU,
4751d3a2bcSkettenis * gigabit MAC, dual DMA channels and a PCI interface unit. NICs
4851d3a2bcSkettenis * using the Tigon may have anywhere from 512K to 2MB of SRAM. The
4951d3a2bcSkettenis * Tigon supports hardware IP, TCP and UCP checksumming, multicast
5051d3a2bcSkettenis * filtering and jumbo (9014 byte) frames. The hardware is largely
5151d3a2bcSkettenis * controlled by firmware, which must be loaded into the NIC during
5251d3a2bcSkettenis * initialization.
5351d3a2bcSkettenis *
5451d3a2bcSkettenis * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware
5551d3a2bcSkettenis * revision, which supports new features such as extended commands,
564b1a56afSjsg * extended jumbo receive ring descriptors and a mini receive ring.
5751d3a2bcSkettenis *
5851d3a2bcSkettenis * Alteon Networks is to be commended for releasing such a vast amount
5951d3a2bcSkettenis * of development material for the Tigon NIC without requiring an NDA
6051d3a2bcSkettenis * (although they really should have done it a long time ago). With
6151d3a2bcSkettenis * any luck, the other vendors will finally wise up and follow Alteon's
6251d3a2bcSkettenis * stellar example.
6351d3a2bcSkettenis *
6451d3a2bcSkettenis * The following people deserve special thanks:
6551d3a2bcSkettenis * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board
6651d3a2bcSkettenis * for testing
6751d3a2bcSkettenis * - Raymond Lee of Netgear, for providing a pair of Netgear
6851d3a2bcSkettenis * GA620 Tigon 2 boards for testing
6951d3a2bcSkettenis * - Ulf Zimmermann, for bringing the GA260 to my attention and
7051d3a2bcSkettenis * convincing me to write this driver.
7151d3a2bcSkettenis * - Andrew Gallatin for providing FreeBSD/Alpha support.
7251d3a2bcSkettenis */
7351d3a2bcSkettenis
7451d3a2bcSkettenis #include <sys/param.h>
7551d3a2bcSkettenis #include <sys/device.h>
7651d3a2bcSkettenis #include <sys/systm.h>
7751d3a2bcSkettenis
7851d3a2bcSkettenis #include <net/if.h>
7951d3a2bcSkettenis #include <net/if_media.h>
8051d3a2bcSkettenis
8151d3a2bcSkettenis #include <netinet/in.h>
8251d3a2bcSkettenis #include <netinet/if_ether.h>
8351d3a2bcSkettenis
8451d3a2bcSkettenis #include <dev/pci/pcireg.h>
8551d3a2bcSkettenis #include <dev/pci/pcivar.h>
8651d3a2bcSkettenis #include <dev/pci/pcidevs.h>
8751d3a2bcSkettenis
8851d3a2bcSkettenis #include <dev/ic/tireg.h>
8951d3a2bcSkettenis #include <dev/ic/tivar.h>
9051d3a2bcSkettenis
9151d3a2bcSkettenis int ti_pci_match(struct device *, void *, void *);
9251d3a2bcSkettenis void ti_pci_attach(struct device *, struct device *, void *);
9351d3a2bcSkettenis
948d2c75e4Smpi const struct cfattach ti_pci_ca = {
9551d3a2bcSkettenis sizeof(struct ti_softc), ti_pci_match, ti_pci_attach
9651d3a2bcSkettenis };
9751d3a2bcSkettenis
9851d3a2bcSkettenis const struct pci_matchid ti_devices[] = {
9951d3a2bcSkettenis { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620 },
10051d3a2bcSkettenis { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620T },
10151d3a2bcSkettenis { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC },
10251d3a2bcSkettenis { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENICT },
10351d3a2bcSkettenis { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C985 },
10451d3a2bcSkettenis { PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON },
10551d3a2bcSkettenis { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_PN9000SX }
10651d3a2bcSkettenis };
10751d3a2bcSkettenis
10851d3a2bcSkettenis int
ti_pci_match(struct device * parent,void * match,void * aux)10951d3a2bcSkettenis ti_pci_match(struct device *parent, void *match, void *aux)
11051d3a2bcSkettenis {
11151d3a2bcSkettenis return (pci_matchbyid(aux, ti_devices, nitems(ti_devices)));
11251d3a2bcSkettenis }
11351d3a2bcSkettenis
11451d3a2bcSkettenis void
ti_pci_attach(struct device * parent,struct device * self,void * aux)11551d3a2bcSkettenis ti_pci_attach(struct device *parent, struct device *self, void *aux)
11651d3a2bcSkettenis {
11751d3a2bcSkettenis struct ti_softc *sc = (struct ti_softc *)self;
11851d3a2bcSkettenis struct pci_attach_args *pa = aux;
11951d3a2bcSkettenis pci_chipset_tag_t pc = pa->pa_pc;
12051d3a2bcSkettenis pci_intr_handle_t ih;
12151d3a2bcSkettenis const char *intrstr = NULL;
12251d3a2bcSkettenis bus_size_t size;
12351d3a2bcSkettenis
12451d3a2bcSkettenis /*
12551d3a2bcSkettenis * Map control/status registers.
12651d3a2bcSkettenis */
12751d3a2bcSkettenis if (pci_mapreg_map(pa, TI_PCI_LOMEM,
12851d3a2bcSkettenis PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
12951d3a2bcSkettenis &sc->ti_btag, &sc->ti_bhandle, NULL, &size, 0)) {
13051d3a2bcSkettenis printf(": can't map registers\n");
13151d3a2bcSkettenis return;
13251d3a2bcSkettenis }
13351d3a2bcSkettenis
13451d3a2bcSkettenis sc->sc_dmatag = pa->pa_dmat;
13551d3a2bcSkettenis
13651d3a2bcSkettenis if (pci_intr_map(pa, &ih)) {
13751d3a2bcSkettenis printf(": can't map interrupt\n");
13851d3a2bcSkettenis goto unmap;
13951d3a2bcSkettenis }
14051d3a2bcSkettenis intrstr = pci_intr_string(pc, ih);
14151d3a2bcSkettenis sc->ti_intrhand = pci_intr_establish(pc, ih, IPL_NET, ti_intr, sc,
14251d3a2bcSkettenis self->dv_xname);
14351d3a2bcSkettenis if (sc->ti_intrhand == NULL) {
14451d3a2bcSkettenis printf(": can't establish interrupt");
14551d3a2bcSkettenis if (intrstr != NULL)
14651d3a2bcSkettenis printf(" at %s", intrstr);
14751d3a2bcSkettenis printf("\n");
14851d3a2bcSkettenis goto unmap;
14951d3a2bcSkettenis }
15051d3a2bcSkettenis printf(": %s", intrstr);
15151d3a2bcSkettenis
15251d3a2bcSkettenis /*
15351d3a2bcSkettenis * We really need a better way to tell a 1000baseTX card
15451d3a2bcSkettenis * from a 1000baseSX one, since in theory there could be
15551d3a2bcSkettenis * OEMed 1000baseTX cards from lame vendors who aren't
15651d3a2bcSkettenis * clever enough to change the PCI ID. For the moment
15751d3a2bcSkettenis * though, the AceNIC is the only copper card available.
15851d3a2bcSkettenis */
15951d3a2bcSkettenis if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALTEON &&
16051d3a2bcSkettenis PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALTEON_ACENICT)
16151d3a2bcSkettenis sc->ti_copper = 1;
16251d3a2bcSkettenis /* Ok, it's not the only copper card available */
16351d3a2bcSkettenis if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETGEAR &&
16451d3a2bcSkettenis PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETGEAR_GA620T)
16551d3a2bcSkettenis sc->ti_copper = 1;
16651d3a2bcSkettenis
16751d3a2bcSkettenis if (ti_attach(sc) == 0)
16851d3a2bcSkettenis return;
16951d3a2bcSkettenis
17051d3a2bcSkettenis pci_intr_disestablish(pc, sc->ti_intrhand);
17151d3a2bcSkettenis
17251d3a2bcSkettenis unmap:
17351d3a2bcSkettenis bus_space_unmap(sc->ti_btag, sc->ti_bhandle, size);
17451d3a2bcSkettenis }
175