xref: /openbsd-src/sys/dev/pci/if_ti_pci.c (revision 43003dfe3ad45d1698bed8a37f2b0f5b14f20d4f)
1 /*	$OpenBSD: if_ti_pci.c,v 1.1 2009/08/29 21:12:55 kettenis 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 desciptors 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/socket.h>
77 #include <sys/systm.h>
78 
79 #include <net/if.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
82 
83 #ifdef INET
84 #include <netinet/in.h>
85 #include <netinet/in_systm.h>
86 #include <netinet/in_var.h>
87 #include <netinet/ip.h>
88 #include <netinet/if_ether.h>
89 #endif
90 
91 #include <dev/pci/pcireg.h>
92 #include <dev/pci/pcivar.h>
93 #include <dev/pci/pcidevs.h>
94 
95 #include <dev/ic/tireg.h>
96 #include <dev/ic/tivar.h>
97 
98 int	ti_pci_match(struct device *, void *, void *);
99 void	ti_pci_attach(struct device *, struct device *, void *);
100 
101 struct cfattach ti_pci_ca = {
102 	sizeof(struct ti_softc), ti_pci_match, ti_pci_attach
103 };
104 
105 const struct pci_matchid ti_devices[] = {
106 	{ PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620 },
107 	{ PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620T },
108 	{ PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC },
109 	{ PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENICT },
110 	{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C985 },
111 	{ PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON },
112 	{ PCI_VENDOR_DEC, PCI_PRODUCT_DEC_PN9000SX }
113 };
114 
115 int
116 ti_pci_match(struct device *parent, void *match, void *aux)
117 {
118 	return (pci_matchbyid(aux, ti_devices, nitems(ti_devices)));
119 }
120 
121 void
122 ti_pci_attach(struct device *parent, struct device *self, void *aux)
123 {
124 	struct ti_softc *sc = (struct ti_softc *)self;
125 	struct pci_attach_args *pa = aux;
126 	pci_chipset_tag_t pc = pa->pa_pc;
127 	pci_intr_handle_t ih;
128 	const char *intrstr = NULL;
129 	bus_size_t size;
130 
131 	/*
132 	 * Map control/status registers.
133 	 */
134 	if (pci_mapreg_map(pa, TI_PCI_LOMEM,
135 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
136 	    &sc->ti_btag, &sc->ti_bhandle, NULL, &size, 0)) {
137  		printf(": can't map registers\n");
138 		return;
139  	}
140 
141 	sc->sc_dmatag = pa->pa_dmat;
142 
143 	if (pci_intr_map(pa, &ih)) {
144 		printf(": can't map interrupt\n");
145 		goto unmap;
146 	}
147 	intrstr = pci_intr_string(pc, ih);
148 	sc->ti_intrhand = pci_intr_establish(pc, ih, IPL_NET, ti_intr, sc,
149 	    self->dv_xname);
150 	if (sc->ti_intrhand == NULL) {
151 		printf(": can't establish interrupt");
152 		if (intrstr != NULL)
153 			printf(" at %s", intrstr);
154 		printf("\n");
155 		goto unmap;
156 	}
157 	printf(": %s", intrstr);
158 
159 	/*
160 	 * We really need a better way to tell a 1000baseTX card
161 	 * from a 1000baseSX one, since in theory there could be
162 	 * OEMed 1000baseTX cards from lame vendors who aren't
163 	 * clever enough to change the PCI ID. For the moment
164 	 * though, the AceNIC is the only copper card available.
165 	 */
166 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALTEON &&
167 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALTEON_ACENICT)
168 		sc->ti_copper = 1;
169 	/* Ok, it's not the only copper card available */
170 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETGEAR &&
171 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETGEAR_GA620T)
172 		sc->ti_copper = 1;
173 
174 	if (ti_attach(sc) == 0)
175 		return;
176 
177 	pci_intr_disestablish(pc, sc->ti_intrhand);
178 
179 unmap:
180 	bus_space_unmap(sc->ti_btag, sc->ti_bhandle, size);
181 }
182