if_epic_pci.c revision 1.2 1 /* $NetBSD: if_epic_pci.c,v 1.2 1998/06/08 06:55:55 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 int epic_pci_match __P((struct device *, struct cfdata *, void *));
100 void epic_pci_attach __P((struct device *, struct device *, void *));
101
102 struct cfattach epic_pci_ca = {
103 sizeof(struct epic_pci_softc), epic_pci_match, epic_pci_attach,
104 };
105
106 int
107 epic_pci_match(parent, match, aux)
108 struct device *parent;
109 struct cfdata *match;
110 void *aux;
111 {
112 struct pci_attach_args *pa = aux;
113
114 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SMC &&
115 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SMC_83C170)
116 return (1);
117
118 return (0);
119 }
120
121 void
122 epic_pci_attach(parent, self, aux)
123 struct device *parent, *self;
124 void *aux;
125 {
126 struct epic_pci_softc *psc = (struct epic_pci_softc *)self;
127 struct epic_softc *sc = &psc->sc_epic;
128 struct pci_attach_args *pa = aux;
129 pci_chipset_tag_t pc = pa->pa_pc;
130 pci_intr_handle_t ih;
131 const char *intrstr = NULL;
132 bus_space_tag_t iot, memt;
133 bus_space_handle_t ioh, memh;
134 int ioh_valid, memh_valid;
135
136 /*
137 * Map the device.
138 */
139 ioh_valid = (pci_mapreg_map(pa, EPIC_PCI_IOBA,
140 PCI_MAPREG_TYPE_IO, 0,
141 &iot, &ioh, NULL, NULL) == 0);
142 memh_valid = (pci_mapreg_map(pa, EPIC_PCI_MMBA,
143 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
144 &memt, &memh, NULL, NULL) == 0);
145
146 if (memh_valid) {
147 sc->sc_st = memt;
148 sc->sc_sh = memh;
149 } else if (ioh_valid) {
150 sc->sc_st = iot;
151 sc->sc_sh = ioh;
152 } else {
153 printf(": unable to map device registers\n");
154 return;
155 }
156
157 sc->sc_dmat = pa->pa_dmat;
158
159 printf(": SMC EPIC/100 Fast Ethernet\n");
160
161 /*
162 * Map and establish our interrupt.
163 */
164 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
165 pa->pa_intrline, &ih)) {
166 printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
167 return;
168 }
169 intrstr = pci_intr_string(pc, ih);
170 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epic_intr, sc);
171 if (psc->sc_ih == NULL) {
172 printf("%s: unable to establish interrupt",
173 sc->sc_dev.dv_xname);
174 if (intrstr != NULL)
175 printf(" at %s", intrstr);
176 printf("\n");
177 return;
178 }
179 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
180
181 /*
182 * Finish off the attach.
183 */
184 epic_attach(sc);
185 }
186