if_gem_pci.c revision 1.2.2.2 1 1.2.2.2 fvdl /* $NetBSD: if_gem_pci.c,v 1.2.2.2 2001/10/01 12:45:54 fvdl Exp $ */
2 1.2.2.2 fvdl
3 1.2.2.2 fvdl /*
4 1.2.2.2 fvdl *
5 1.2.2.2 fvdl * Copyright (C) 2001 Eduardo Horvath.
6 1.2.2.2 fvdl * All rights reserved.
7 1.2.2.2 fvdl *
8 1.2.2.2 fvdl *
9 1.2.2.2 fvdl * Redistribution and use in source and binary forms, with or without
10 1.2.2.2 fvdl * modification, are permitted provided that the following conditions
11 1.2.2.2 fvdl * are met:
12 1.2.2.2 fvdl * 1. Redistributions of source code must retain the above copyright
13 1.2.2.2 fvdl * notice, this list of conditions and the following disclaimer.
14 1.2.2.2 fvdl * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.2.2 fvdl * notice, this list of conditions and the following disclaimer in the
16 1.2.2.2 fvdl * documentation and/or other materials provided with the distribution.
17 1.2.2.2 fvdl *
18 1.2.2.2 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
19 1.2.2.2 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 1.2.2.2 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.2.2.2 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
22 1.2.2.2 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.2.2.2 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 1.2.2.2 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.2.2.2 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.2.2.2 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.2.2.2 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.2.2.2 fvdl * SUCH DAMAGE.
29 1.2.2.2 fvdl *
30 1.2.2.2 fvdl */
31 1.2.2.2 fvdl
32 1.2.2.2 fvdl /*
33 1.2.2.2 fvdl * PCI bindings for Sun GEM ethernet controllers.
34 1.2.2.2 fvdl */
35 1.2.2.2 fvdl
36 1.2.2.2 fvdl #include <sys/param.h>
37 1.2.2.2 fvdl #include <sys/systm.h>
38 1.2.2.2 fvdl #include <sys/malloc.h>
39 1.2.2.2 fvdl #include <sys/kernel.h>
40 1.2.2.2 fvdl #include <sys/socket.h>
41 1.2.2.2 fvdl #include <sys/errno.h>
42 1.2.2.2 fvdl #include <sys/device.h>
43 1.2.2.2 fvdl
44 1.2.2.2 fvdl #include <machine/endian.h>
45 1.2.2.2 fvdl
46 1.2.2.2 fvdl #include <uvm/uvm_extern.h>
47 1.2.2.2 fvdl
48 1.2.2.2 fvdl #include <net/if.h>
49 1.2.2.2 fvdl #include <net/if_dl.h>
50 1.2.2.2 fvdl #include <net/if_media.h>
51 1.2.2.2 fvdl #include <net/if_ether.h>
52 1.2.2.2 fvdl
53 1.2.2.2 fvdl #if NBPFILTER > 0
54 1.2.2.2 fvdl #include <net/bpf.h>
55 1.2.2.2 fvdl #endif
56 1.2.2.2 fvdl
57 1.2.2.2 fvdl #include <machine/bus.h>
58 1.2.2.2 fvdl #include <machine/intr.h>
59 1.2.2.2 fvdl
60 1.2.2.2 fvdl #include <dev/mii/mii.h>
61 1.2.2.2 fvdl #include <dev/mii/miivar.h>
62 1.2.2.2 fvdl #include <dev/mii/mii_bitbang.h>
63 1.2.2.2 fvdl
64 1.2.2.2 fvdl #include <dev/ic/gemreg.h>
65 1.2.2.2 fvdl #include <dev/ic/gemvar.h>
66 1.2.2.2 fvdl
67 1.2.2.2 fvdl #include <dev/pci/pcivar.h>
68 1.2.2.2 fvdl #include <dev/pci/pcireg.h>
69 1.2.2.2 fvdl #include <dev/pci/pcidevs.h>
70 1.2.2.2 fvdl
71 1.2.2.2 fvdl struct gem_pci_softc {
72 1.2.2.2 fvdl struct gem_softc gsc_gem; /* GEM device */
73 1.2.2.2 fvdl bus_space_tag_t gsc_memt;
74 1.2.2.2 fvdl bus_space_handle_t gsc_memh;
75 1.2.2.2 fvdl void *gsc_ih;
76 1.2.2.2 fvdl };
77 1.2.2.2 fvdl
78 1.2.2.2 fvdl int gem_match_pci __P((struct device *, struct cfdata *, void *));
79 1.2.2.2 fvdl void gem_attach_pci __P((struct device *, struct device *, void *));
80 1.2.2.2 fvdl
81 1.2.2.2 fvdl struct cfattach gem_pci_ca = {
82 1.2.2.2 fvdl sizeof(struct gem_pci_softc), gem_match_pci, gem_attach_pci
83 1.2.2.2 fvdl };
84 1.2.2.2 fvdl
85 1.2.2.2 fvdl /*
86 1.2.2.2 fvdl * Attach routines need to be split out to different bus-specific files.
87 1.2.2.2 fvdl */
88 1.2.2.2 fvdl
89 1.2.2.2 fvdl int
90 1.2.2.2 fvdl gem_match_pci(parent, cf, aux)
91 1.2.2.2 fvdl struct device *parent;
92 1.2.2.2 fvdl struct cfdata *cf;
93 1.2.2.2 fvdl void *aux;
94 1.2.2.2 fvdl {
95 1.2.2.2 fvdl struct pci_attach_args *pa = aux;
96 1.2.2.2 fvdl
97 1.2.2.2 fvdl if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
98 1.2.2.2 fvdl (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK ||
99 1.2.2.2 fvdl PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK))
100 1.2.2.2 fvdl return (1);
101 1.2.2.2 fvdl
102 1.2.2.2 fvdl if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
103 1.2.2.2 fvdl (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
104 1.2.2.2 fvdl PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2))
105 1.2.2.2 fvdl return (1);
106 1.2.2.2 fvdl
107 1.2.2.2 fvdl
108 1.2.2.2 fvdl return (0);
109 1.2.2.2 fvdl }
110 1.2.2.2 fvdl
111 1.2.2.2 fvdl void
112 1.2.2.2 fvdl gem_attach_pci(parent, self, aux)
113 1.2.2.2 fvdl struct device *parent, *self;
114 1.2.2.2 fvdl void *aux;
115 1.2.2.2 fvdl {
116 1.2.2.2 fvdl struct pci_attach_args *pa = aux;
117 1.2.2.2 fvdl struct gem_pci_softc *gsc = (void *)self;
118 1.2.2.2 fvdl struct gem_softc *sc = &gsc->gsc_gem;
119 1.2.2.2 fvdl pci_intr_handle_t intrhandle;
120 1.2.2.2 fvdl #ifdef __sparc__
121 1.2.2.2 fvdl /* XXX the following declarations should be elsewhere */
122 1.2.2.2 fvdl extern void myetheraddr __P((u_char *));
123 1.2.2.2 fvdl #endif
124 1.2.2.2 fvdl const char *intrstr;
125 1.2.2.2 fvdl int type;
126 1.2.2.2 fvdl char devinfo[256];
127 1.2.2.2 fvdl
128 1.2.2.2 fvdl pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
129 1.2.2.2 fvdl printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
130 1.2.2.2 fvdl
131 1.2.2.2 fvdl if (pa->pa_memt) {
132 1.2.2.2 fvdl type = PCI_MAPREG_TYPE_MEM;
133 1.2.2.2 fvdl sc->sc_bustag = pa->pa_memt;
134 1.2.2.2 fvdl } else {
135 1.2.2.2 fvdl type = PCI_MAPREG_TYPE_IO;
136 1.2.2.2 fvdl sc->sc_bustag = pa->pa_iot;
137 1.2.2.2 fvdl }
138 1.2.2.2 fvdl
139 1.2.2.2 fvdl sc->sc_dmatag = pa->pa_dmat;
140 1.2.2.2 fvdl
141 1.2.2.2 fvdl sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
142 1.2.2.2 fvdl
143 1.2.2.2 fvdl #define PCI_GEM_BASEADDR 0x10
144 1.2.2.2 fvdl if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0,
145 1.2.2.2 fvdl &gsc->gsc_memt, &gsc->gsc_memh, NULL, NULL) != 0)
146 1.2.2.2 fvdl {
147 1.2.2.2 fvdl printf(": could not map gem registers\n");
148 1.2.2.2 fvdl return;
149 1.2.2.2 fvdl }
150 1.2.2.2 fvdl
151 1.2.2.2 fvdl sc->sc_bustag = gsc->gsc_memt;
152 1.2.2.2 fvdl sc->sc_h = gsc->gsc_memh;
153 1.2.2.2 fvdl
154 1.2.2.2 fvdl #if 0
155 1.2.2.2 fvdl /* SBUS compatible stuff? */
156 1.2.2.2 fvdl sc->sc_seb = gsc->gsc_memh;
157 1.2.2.2 fvdl sc->sc_etx = gsc->gsc_memh + 0x2000;
158 1.2.2.2 fvdl sc->sc_erx = gsc->gsc_memh + 0x4000;
159 1.2.2.2 fvdl sc->sc_mac = gsc->gsc_memh + 0x6000;
160 1.2.2.2 fvdl sc->sc_mif = gsc->gsc_memh + 0x7000;
161 1.2.2.2 fvdl #endif
162 1.2.2.2 fvdl #ifdef __sparc__
163 1.2.2.2 fvdl myetheraddr(sc->sc_enaddr);
164 1.2.2.2 fvdl #endif
165 1.2.2.2 fvdl
166 1.2.2.2 fvdl sc->sc_burst = 16; /* XXX */
167 1.2.2.2 fvdl
168 1.2.2.2 fvdl /*
169 1.2.2.2 fvdl * call the main configure
170 1.2.2.2 fvdl */
171 1.2.2.2 fvdl gem_config(sc);
172 1.2.2.2 fvdl
173 1.2.2.2 fvdl if (pci_intr_map(pa, &intrhandle) != 0) {
174 1.2.2.2 fvdl printf("%s: couldn't map interrupt\n",
175 1.2.2.2 fvdl sc->sc_dev.dv_xname);
176 1.2.2.2 fvdl return; /* bus_unmap ? */
177 1.2.2.2 fvdl }
178 1.2.2.2 fvdl intrstr = pci_intr_string(pa->pa_pc, intrhandle);
179 1.2.2.2 fvdl gsc->gsc_ih = pci_intr_establish(pa->pa_pc,
180 1.2.2.2 fvdl intrhandle, IPL_NET, gem_intr, sc);
181 1.2.2.2 fvdl if (gsc->gsc_ih != NULL) {
182 1.2.2.2 fvdl printf("%s: using %s for interrupt\n",
183 1.2.2.2 fvdl sc->sc_dev.dv_xname,
184 1.2.2.2 fvdl intrstr ? intrstr : "unknown interrupt");
185 1.2.2.2 fvdl } else {
186 1.2.2.2 fvdl printf("%s: couldn't establish interrupt",
187 1.2.2.2 fvdl sc->sc_dev.dv_xname);
188 1.2.2.2 fvdl if (intrstr != NULL)
189 1.2.2.2 fvdl printf(" at %s", intrstr);
190 1.2.2.2 fvdl printf("\n");
191 1.2.2.2 fvdl return; /* bus_unmap ? */
192 1.2.2.2 fvdl }
193 1.2.2.2 fvdl }
194