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