1/* $OpenBSD: if_ti_pci.c,v 1.8 2024/05/24 06:02:57 jsg Exp $ */ 2 3/* 4 * Copyright (c) 1997, 1998, 1999 5 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Bill Paul. 18 * 4. Neither the name of the author nor the names of any co-contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * $FreeBSD: src/sys/pci/if_ti.c,v 1.25 2000/01/18 00:26:29 wpaul Exp $ 35 */ 36 37/* 38 * Alteon Networks Tigon PCI gigabit ethernet driver for OpenBSD. 39 * 40 * Written by Bill Paul <wpaul@ctr.columbia.edu> 41 * Electrical Engineering Department 42 * Columbia University, New York City 43 */ 44 45/* 46 * The Alteon Networks Tigon chip contains an embedded R4000 CPU, 47 * gigabit MAC, dual DMA channels and a PCI interface unit. NICs 48 * using the Tigon may have anywhere from 512K to 2MB of SRAM. The 49 * Tigon supports hardware IP, TCP and UCP checksumming, multicast 50 * filtering and jumbo (9014 byte) frames. The hardware is largely 51 * controlled by firmware, which must be loaded into the NIC during 52 * initialization. 53 * 54 * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware 55 * revision, which supports new features such as extended commands, 56 * extended jumbo receive ring descriptors and a mini receive ring. 57 * 58 * Alteon Networks is to be commended for releasing such a vast amount 59 * of development material for the Tigon NIC without requiring an NDA 60 * (although they really should have done it a long time ago). With 61 * any luck, the other vendors will finally wise up and follow Alteon's 62 * stellar example. 63 * 64 * The following people deserve special thanks: 65 * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board 66 * for testing 67 * - Raymond Lee of Netgear, for providing a pair of Netgear 68 * GA620 Tigon 2 boards for testing 69 * - Ulf Zimmermann, for bringing the GA260 to my attention and 70 * convincing me to write this driver. 71 * - Andrew Gallatin for providing FreeBSD/Alpha support. 72 */ 73 74#include <sys/param.h> 75#include <sys/device.h> 76#include <sys/systm.h> 77 78#include <net/if.h> 79#include <net/if_media.h> 80 81#include <netinet/in.h> 82#include <netinet/if_ether.h> 83 84#include <dev/pci/pcireg.h> 85#include <dev/pci/pcivar.h> 86#include <dev/pci/pcidevs.h> 87 88#include <dev/ic/tireg.h> 89#include <dev/ic/tivar.h> 90 91int ti_pci_match(struct device *, void *, void *); 92void ti_pci_attach(struct device *, struct device *, void *); 93 94const struct cfattach ti_pci_ca = { 95 sizeof(struct ti_softc), ti_pci_match, ti_pci_attach 96}; 97 98const struct pci_matchid ti_devices[] = { 99 { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620 }, 100 { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620T }, 101 { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC }, 102 { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENICT }, 103 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C985 }, 104 { PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON }, 105 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_PN9000SX } 106}; 107 108int 109ti_pci_match(struct device *parent, void *match, void *aux) 110{ 111 return (pci_matchbyid(aux, ti_devices, nitems(ti_devices))); 112} 113 114void 115ti_pci_attach(struct device *parent, struct device *self, void *aux) 116{ 117 struct ti_softc *sc = (struct ti_softc *)self; 118 struct pci_attach_args *pa = aux; 119 pci_chipset_tag_t pc = pa->pa_pc; 120 pci_intr_handle_t ih; 121 const char *intrstr = NULL; 122 bus_size_t size; 123 124 /* 125 * Map control/status registers. 126 */ 127 if (pci_mapreg_map(pa, TI_PCI_LOMEM, 128 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, 129 &sc->ti_btag, &sc->ti_bhandle, NULL, &size, 0)) { 130 printf(": can't map registers\n"); 131 return; 132 } 133 134 sc->sc_dmatag = pa->pa_dmat; 135 136 if (pci_intr_map(pa, &ih)) { 137 printf(": can't map interrupt\n"); 138 goto unmap; 139 } 140 intrstr = pci_intr_string(pc, ih); 141 sc->ti_intrhand = pci_intr_establish(pc, ih, IPL_NET, ti_intr, sc, 142 self->dv_xname); 143 if (sc->ti_intrhand == NULL) { 144 printf(": can't establish interrupt"); 145 if (intrstr != NULL) 146 printf(" at %s", intrstr); 147 printf("\n"); 148 goto unmap; 149 } 150 printf(": %s", intrstr); 151 152 /* 153 * We really need a better way to tell a 1000baseTX card 154 * from a 1000baseSX one, since in theory there could be 155 * OEMed 1000baseTX cards from lame vendors who aren't 156 * clever enough to change the PCI ID. For the moment 157 * though, the AceNIC is the only copper card available. 158 */ 159 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALTEON && 160 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALTEON_ACENICT) 161 sc->ti_copper = 1; 162 /* Ok, it's not the only copper card available */ 163 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETGEAR && 164 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETGEAR_GA620T) 165 sc->ti_copper = 1; 166 167 if (ti_attach(sc) == 0) 168 return; 169 170 pci_intr_disestablish(pc, sc->ti_intrhand); 171 172unmap: 173 bus_space_unmap(sc->ti_btag, sc->ti_bhandle, size); 174} 175