if_epic_pci.c revision 1.1 1 /* $NetBSD: if_epic_pci.c,v 1.1 1998/06/02 01:29:41 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * PCI bus front-end for the Standard Microsystems Corp. 83C170
42 * Ethernet PCI Integrated Controller (EPIC/100) driver.
43 */
44
45 #include "bpfilter.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/mbuf.h>
50 #include <sys/malloc.h>
51 #include <sys/kernel.h>
52 #include <sys/socket.h>
53 #include <sys/ioctl.h>
54 #include <sys/errno.h>
55 #include <sys/device.h>
56
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_ether.h>
61
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #endif
65
66 #ifdef INET
67 #include <netinet/in.h>
68 #include <netinet/if_inarp.h>
69 #endif
70
71 #ifdef NS
72 #include <netns/ns.h>
73 #include <netns/ns_if.h>
74 #endif
75
76 #include <machine/bus.h>
77 #include <machine/intr.h>
78
79 #include <dev/ic/smc83c170reg.h>
80 #include <dev/ic/smc83c170var.h>
81
82 #include <dev/pci/pcivar.h>
83 #include <dev/pci/pcireg.h>
84 #include <dev/pci/pcidevs.h>
85
86 /*
87 * PCI configuration space registers used by the EPIC.
88 */
89 #define EPIC_PCI_IOBA 0x10 /* i/o mapped base */
90 #define EPIC_PCI_MMBA 0x14 /* memory mapped base */
91
92 struct epic_pci_softc {
93 struct epic_softc sc_epic; /* real EPIC softc */
94
95 /* PCI-specific goo. */
96 void *sc_ih; /* interrupt handle */
97 };
98
99 #ifdef __BROKEN_INDIRECT_CONFIG
100 int epic_pci_match __P((struct device *, void *, void *));
101 #else
102 int epic_pci_match __P((struct device *, struct cfdata *, void *));
103 #endif
104 void epic_pci_attach __P((struct device *, struct device *, void *));
105
106 struct cfattach epic_pci_ca = {
107 sizeof(struct epic_pci_softc), epic_pci_match, epic_pci_attach,
108 };
109
110 int
111 epic_pci_match(parent, match, aux)
112 struct device *parent;
113 #ifdef __BROKEN_INDIRECT_CONFIG
114 void *match;
115 #else
116 struct cfdata *match;
117 #endif
118 void *aux;
119 {
120 struct pci_attach_args *pa = aux;
121
122 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SMC &&
123 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SMC_83C170)
124 return (1);
125
126 return (0);
127 }
128
129 void
130 epic_pci_attach(parent, self, aux)
131 struct device *parent, *self;
132 void *aux;
133 {
134 struct epic_pci_softc *psc = (struct epic_pci_softc *)self;
135 struct epic_softc *sc = &psc->sc_epic;
136 struct pci_attach_args *pa = aux;
137 pci_chipset_tag_t pc = pa->pa_pc;
138 pci_intr_handle_t ih;
139 const char *intrstr = NULL;
140 bus_space_tag_t iot, memt;
141 bus_space_handle_t ioh, memh;
142 int ioh_valid, memh_valid;
143
144 /*
145 * Map the device.
146 */
147 ioh_valid = (pci_mapreg_map(pa, EPIC_PCI_IOBA,
148 PCI_MAPREG_TYPE_IO, 0,
149 &iot, &ioh, NULL, NULL) == 0);
150 memh_valid = (pci_mapreg_map(pa, EPIC_PCI_MMBA,
151 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
152 &memt, &memh, NULL, NULL) == 0);
153
154 if (memh_valid) {
155 sc->sc_st = memt;
156 sc->sc_sh = memh;
157 } else if (ioh_valid) {
158 sc->sc_st = iot;
159 sc->sc_sh = ioh;
160 } else {
161 printf(": unable to map device registers\n");
162 return;
163 }
164
165 sc->sc_dmat = pa->pa_dmat;
166
167 printf(": SMC EPIC/100 Fast Ethernet\n");
168
169 /*
170 * Map and establish our interrupt.
171 */
172 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
173 pa->pa_intrline, &ih)) {
174 printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
175 return;
176 }
177 intrstr = pci_intr_string(pc, ih);
178 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epic_intr, sc);
179 if (psc->sc_ih == NULL) {
180 printf("%s: unable to establish interrupt",
181 sc->sc_dev.dv_xname);
182 if (intrstr != NULL)
183 printf(" at %s", intrstr);
184 printf("\n");
185 return;
186 }
187 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
188
189 /*
190 * Finish off the attach.
191 */
192 epic_attach(sc);
193 }
194