if_hme_pci.c revision 1.9 1 /* $NetBSD: if_hme_pci.c,v 1.9 2001/11/13 07:48:43 lukem Exp $ */
2
3 /*
4 * Copyright (c) 2000 Matthew R. Green
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. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 /*
32 * PCI front-end device driver for the HME ethernet device.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: if_hme_pci.c,v 1.9 2001/11/13 07:48:43 lukem Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/syslog.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/socket.h>
44
45 #include <net/if.h>
46 #include <net/if_dl.h>
47 #include <net/if_ether.h>
48 #include <net/if_media.h>
49
50 #include <dev/mii/mii.h>
51 #include <dev/mii/miivar.h>
52
53 #include <machine/intr.h>
54
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcidevs.h>
58
59 #include <dev/ic/hmevar.h>
60
61 struct hme_pci_softc {
62 struct hme_softc hsc_hme; /* HME device */
63 bus_space_tag_t hsc_memt;
64 bus_space_handle_t hsc_memh;
65 void *hsc_ih;
66 };
67
68 int hmematch_pci __P((struct device *, struct cfdata *, void *));
69 void hmeattach_pci __P((struct device *, struct device *, void *));
70
71 struct cfattach hme_pci_ca = {
72 sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci
73 };
74
75 int
76 hmematch_pci(parent, cf, aux)
77 struct device *parent;
78 struct cfdata *cf;
79 void *aux;
80 {
81 struct pci_attach_args *pa = aux;
82
83 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
84 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HMENETWORK)
85 return (1);
86
87 return (0);
88 }
89
90 void
91 hmeattach_pci(parent, self, aux)
92 struct device *parent, *self;
93 void *aux;
94 {
95 struct pci_attach_args *pa = aux;
96 struct hme_pci_softc *hsc = (void *)self;
97 struct hme_softc *sc = &hsc->hsc_hme;
98 pci_intr_handle_t ih;
99 pcireg_t csr;
100 const char *intrstr;
101 int type;
102
103 /* XXX the following declarations should be elsewhere */
104 extern void myetheraddr __P((u_char *));
105
106 printf(": Sun Happy Meal Ethernet, rev. %d\n",
107 PCI_REVISION(pa->pa_class));
108
109 /*
110 * enable io/memory-space accesses. this is kinda of gross; but
111 # the hme comes up with neither IO space enabled, or memory space.
112 */
113 if (pa->pa_memt)
114 pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
115 if (pa->pa_iot)
116 pa->pa_flags |= PCI_FLAGS_IO_ENABLED;
117 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
118 if (pa->pa_memt) {
119 type = PCI_MAPREG_TYPE_MEM;
120 csr |= PCI_COMMAND_MEM_ENABLE;
121 sc->sc_bustag = pa->pa_memt;
122 } else {
123 type = PCI_MAPREG_TYPE_IO;
124 csr |= PCI_COMMAND_IO_ENABLE;
125 sc->sc_bustag = pa->pa_iot;
126 }
127 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
128 csr | PCI_COMMAND_MEM_ENABLE);
129
130 sc->sc_dmatag = pa->pa_dmat;
131
132 sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
133 /*
134 * Map five register banks:
135 *
136 * bank 0: HME SEB registers: +0x0000
137 * bank 1: HME ETX registers: +0x2000
138 * bank 2: HME ERX registers: +0x4000
139 * bank 3: HME MAC registers: +0x6000
140 * bank 4: HME MIF registers: +0x7000
141 *
142 */
143
144 #define PCI_HME_BASEADDR 0x10
145 if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0,
146 &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0)
147 {
148 printf("%s: unable to map device registers\n",
149 sc->sc_dev.dv_xname);
150 return;
151 }
152 sc->sc_seb = hsc->hsc_memh;
153 if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x2000,
154 0x1000, &sc->sc_etx)) {
155 printf("%s: unable to subregion ETX registers\n",
156 sc->sc_dev.dv_xname);
157 return;
158 }
159 if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x4000,
160 0x1000, &sc->sc_erx)) {
161 printf("%s: unable to subregion ERX registers\n",
162 sc->sc_dev.dv_xname);
163 return;
164 }
165 if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x6000,
166 0x1000, &sc->sc_mac)) {
167 printf("%s: unable to subregion MAC registers\n",
168 sc->sc_dev.dv_xname);
169 return;
170 }
171 if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x7000,
172 0x1000, &sc->sc_mif)) {
173 printf("%s: unable to subregion MIF registers\n",
174 sc->sc_dev.dv_xname);
175 return;
176 }
177
178 myetheraddr(sc->sc_enaddr);
179
180 /*
181 * Map and establish our interrupt.
182 */
183 if (pci_intr_map(pa, &ih) != 0) {
184 printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
185 return;
186 }
187 intrstr = pci_intr_string(pa->pa_pc, ih);
188 hsc->hsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, hme_intr, sc);
189 if (hsc->hsc_ih == NULL) {
190 printf("%s: unable to establish interrupt",
191 sc->sc_dev.dv_xname);
192 if (intrstr != NULL)
193 printf(" at %s", intrstr);
194 printf("\n");
195 return;
196 }
197 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
198
199 sc->sc_burst = 16; /* XXX */
200
201 /* Finish off the attach. */
202 hme_config(sc);
203 }
204