if_ep_pci.c revision 1.18 1 /* $NetBSD: if_ep_pci.c,v 1.18 1997/02/18 10:51:12 jonathan Exp $ */
2
3 /*
4 * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) 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 #ifdef __BROKEN_INDIRECT_CONFIG
86 int ep_pci_match __P((struct device *, void *, void *));
87 #else
88 int ep_pci_match __P((struct device *, struct cfdata *, void *));
89 #endif
90 void ep_pci_attach __P((struct device *, struct device *, void *));
91
92 struct cfattach ep_pci_ca = {
93 sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
94 };
95
96 int
97 ep_pci_match(parent, match, aux)
98 struct device *parent;
99 #ifdef __BROKEN_INDIRECT_CONFIG
100 void *match;
101 #else
102 struct cfdata *match;
103 #endif
104 void *aux;
105 {
106 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
107
108 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
109 return 0;
110
111 switch (PCI_PRODUCT(pa->pa_id)) {
112 case PCI_PRODUCT_3COM_3C590:
113 case PCI_PRODUCT_3COM_3C595TX:
114 case PCI_PRODUCT_3COM_3C900COMBO:
115 case PCI_PRODUCT_3COM_3C905TX:
116 break;
117 default:
118 return 0;
119 }
120
121 return 1;
122 }
123
124 void
125 ep_pci_attach(parent, self, aux)
126 struct device *parent, *self;
127 void *aux;
128 {
129 struct ep_softc *sc = (void *)self;
130 struct pci_attach_args *pa = aux;
131 pci_chipset_tag_t pc = pa->pa_pc;
132 bus_space_tag_t iot = pa->pa_iot;
133 bus_addr_t iobase;
134 bus_size_t iosize;
135 pci_intr_handle_t ih;
136 char *model;
137 const char *intrstr = NULL;
138
139 if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)) {
140 printf(": can't find i/o space\n");
141 return;
142 }
143
144 if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_ioh)) {
145 printf(": can't map i/o space\n");
146 return;
147 }
148
149 sc->sc_iot = iot;
150 sc->bustype = EP_BUS_PCI;
151
152 switch (PCI_PRODUCT(pa->pa_id)) {
153 case PCI_PRODUCT_3COM_3C590:
154 model = "3Com 3C590 Ethernet";
155 break;
156 case PCI_PRODUCT_3COM_3C595TX:
157 case PCI_PRODUCT_3COM_3C595T4:
158 case PCI_PRODUCT_3COM_3C595MII:
159 model = "3Com 3C595 Ethernet";
160 break;
161 case PCI_PRODUCT_3COM_3C900TPO:
162 model = "3Com 3C900 Ethernet";
163 break;
164 case PCI_PRODUCT_3COM_3C900COMBO:
165 model = "3Com 3C900 Ethernet";
166 break;
167 case PCI_PRODUCT_3COM_3C905TX:
168 model = "3Com 3C905 Ethernet";
169 break;
170 default:
171 model = "unknown model!";
172 break;
173 }
174
175 printf(": %s\n", model);
176
177 epconfig(sc, EP_CHIPSET_VORTEX);
178
179 /* Enable the card. */
180 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
181 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
182 PCI_COMMAND_MASTER_ENABLE);
183
184 /* Map and establish the interrupt. */
185 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
186 pa->pa_intrline, &ih)) {
187 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
188 return;
189 }
190 intrstr = pci_intr_string(pc, ih);
191 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
192 if (sc->sc_ih == NULL) {
193 printf("%s: couldn't establish interrupt",
194 sc->sc_dev.dv_xname);
195 if (intrstr != NULL)
196 printf(" at %s", intrstr);
197 printf("\n");
198 return;
199 }
200 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
201 }
202