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