xref: /netbsd-src/sys/dev/pci/if_ep_pci.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: if_ep_pci.c,v 1.13 1996/10/21 22:56:38 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org>
5  * 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 Herb Peyerl.
18  * 4. The name of Herb Peyerl may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "bpfilter.h"
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/mbuf.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
40 #include <sys/errno.h>
41 #include <sys/syslog.h>
42 #include <sys/select.h>
43 #include <sys/device.h>
44 
45 #include <net/if.h>
46 #include <net/if_dl.h>
47 #include <net/if_types.h>
48 
49 #ifdef INET
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/in_var.h>
53 #include <netinet/ip.h>
54 #include <netinet/if_ether.h>
55 #endif
56 
57 #ifdef NS
58 #include <netns/ns.h>
59 #include <netns/ns_if.h>
60 #endif
61 
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #include <net/bpfdesc.h>
65 #endif
66 
67 #include <machine/cpu.h>
68 #include <machine/bus.h>
69 #include <machine/intr.h>
70 
71 #include <dev/ic/elink3var.h>
72 #include <dev/ic/elink3reg.h>
73 
74 #include <dev/pci/pcivar.h>
75 #include <dev/pci/pcireg.h>
76 #include <dev/pci/pcidevs.h>
77 
78 /*
79  * PCI constants.
80  * XXX These should be in a common file!
81  */
82 #define PCI_CONN		0x48    /* Connector type */
83 #define PCI_CBIO		0x10    /* Configuration Base IO Address */
84 
85 int ep_pci_match __P((struct device *, void *, void *));
86 void ep_pci_attach __P((struct device *, struct device *, void *));
87 
88 struct cfattach ep_pci_ca = {
89 	sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
90 };
91 
92 int
93 ep_pci_match(parent, match, aux)
94 	struct device *parent;
95 	void *match, *aux;
96 {
97 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
98 
99 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
100 		return 0;
101 
102 	switch (PCI_PRODUCT(pa->pa_id)) {
103 	case PCI_PRODUCT_3COM_3C590:
104 	case PCI_PRODUCT_3COM_3C595TX:
105 	case PCI_PRODUCT_3COM_3C900COMBO:
106 	case PCI_PRODUCT_3COM_3C905TX:
107 		break;
108 	default:
109 		return 0;
110 	}
111 
112 	return 1;
113 }
114 
115 void
116 ep_pci_attach(parent, self, aux)
117 	struct device *parent, *self;
118 	void *aux;
119 {
120 	struct ep_softc *sc = (void *)self;
121 	struct pci_attach_args *pa = aux;
122 	pci_chipset_tag_t pc = pa->pa_pc;
123 	bus_space_tag_t iot = pa->pa_iot;
124 	bus_addr_t iobase;
125 	bus_size_t iosize;
126 	pci_intr_handle_t ih;
127 	u_short conn = 0;
128 	pcireg_t i;
129 	char *model;
130 	const char *intrstr = NULL;
131 
132 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)) {
133 		printf(": can't find i/o space\n");
134 		return;
135 	}
136 
137 	if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_ioh)) {
138 		printf(": can't map i/o space\n");
139 		return;
140 	}
141 
142 	sc->sc_iot = iot;
143 	sc->bustype = EP_BUS_PCI;
144 
145 	i = pci_conf_read(pc, pa->pa_tag, PCI_CONN);
146 
147 	/*
148 	 * Bits 13,12,9 of the isa adapter are the same as bits
149 	 * 5,4,3 of the pci adapter
150 	 */
151 	if (i & IS_PCI_AUI)
152 		conn |= IS_AUI;
153 	if (i & IS_PCI_BNC)
154 		conn |= IS_BNC;
155 	if (i & IS_PCI_UTP)
156 		conn |= IS_UTP;
157 
158 	GO_WINDOW(0);
159 
160 	switch (PCI_PRODUCT(pa->pa_id)) {
161 	case PCI_PRODUCT_3COM_3C590:
162 		model = "3Com 3C590 Ethernet";
163 		break;
164 	case PCI_PRODUCT_3COM_3C595TX:
165 		model = "3Com 3C595 Ethernet";
166 		break;
167 	case PCI_PRODUCT_3COM_3C900TPO:
168 		model = "3Com 3C900 Ethernet";
169 		break;
170 	case PCI_PRODUCT_3COM_3C900COMBO:
171 		model = "3Com 3C900 Ethernet";
172 		break;
173 	case PCI_PRODUCT_3COM_3C905TX:
174 		model = "3Com 3C905 Ethernet";
175 		break;
176 	default:
177 		model = "unknown model!";
178 		break;
179 	}
180 
181 	printf(": %s\n", model);
182 
183 	epconfig(sc, conn);
184 
185 	/* Enable the card. */
186 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
187 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
188 	    PCI_COMMAND_MASTER_ENABLE);
189 
190 	/* Map and establish the interrupt. */
191 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
192 	    pa->pa_intrline, &ih)) {
193 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
194 		return;
195 	}
196 	intrstr = pci_intr_string(pc, ih);
197 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
198 	if (sc->sc_ih == NULL) {
199 		printf("%s: couldn't establish interrupt",
200 		    sc->sc_dev.dv_xname);
201 		if (intrstr != NULL)
202 			printf(" at %s", intrstr);
203 		printf("\n");
204 		return;
205 	}
206 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
207 }
208