if_hme_pci.c revision 1.5 1 /* $NetBSD: if_hme_pci.c,v 1.5 2001/08/27 22:37:33 augustss 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/param.h>
36 #include <sys/systm.h>
37 #include <sys/syslog.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
40 #include <sys/socket.h>
41
42 #include <net/if.h>
43 #include <net/if_dl.h>
44 #include <net/if_ether.h>
45 #include <net/if_media.h>
46
47 #include <dev/mii/mii.h>
48 #include <dev/mii/miivar.h>
49
50 #include <machine/intr.h>
51
52 #include <dev/pci/pcivar.h>
53 #include <dev/pci/pcireg.h>
54 #include <dev/pci/pcidevs.h>
55
56 #include <dev/ic/hmevar.h>
57
58 struct hme_pci_softc {
59 struct hme_softc hsc_hme; /* HME device */
60 bus_space_tag_t hsc_memt;
61 bus_space_handle_t hsc_memh;
62 void *hsc_ih;
63 };
64
65 int hmematch_pci __P((struct device *, struct cfdata *, void *));
66 void hmeattach_pci __P((struct device *, struct device *, void *));
67
68 struct cfattach hme_pci_ca = {
69 sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci
70 };
71
72 int
73 hmematch_pci(parent, cf, aux)
74 struct device *parent;
75 struct cfdata *cf;
76 void *aux;
77 {
78 struct pci_attach_args *pa = aux;
79
80 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
81 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HMENETWORK)
82 return (1);
83
84 return (0);
85 }
86
87 void
88 hmeattach_pci(parent, self, aux)
89 struct device *parent, *self;
90 void *aux;
91 {
92 struct pci_attach_args *pa = aux;
93 struct hme_pci_softc *hsc = (void *)self;
94 struct hme_softc *sc = &hsc->hsc_hme;
95 pci_intr_handle_t intrhandle;
96 /* XXX the following declarations should be elsewhere */
97 extern void myetheraddr __P((u_char *));
98 pcireg_t csr;
99 const char *intrstr;
100 int type;
101
102 /*
103 * enable io/memory-space accesses. this is kinda of gross; but
104 # the hme comes up with neither IO space enabled, or memory space.
105 */
106 if (pa->pa_memt)
107 pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
108 if (pa->pa_iot)
109 pa->pa_flags |= PCI_FLAGS_IO_ENABLED;
110 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
111 if (pa->pa_memt) {
112 type = PCI_MAPREG_TYPE_MEM;
113 csr |= PCI_COMMAND_MEM_ENABLE;
114 sc->sc_bustag = pa->pa_memt;
115 } else {
116 type = PCI_MAPREG_TYPE_IO;
117 csr |= PCI_COMMAND_IO_ENABLE;
118 sc->sc_bustag = pa->pa_iot;
119 }
120 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
121 csr | PCI_COMMAND_MEM_ENABLE);
122
123 sc->sc_dmatag = pa->pa_dmat;
124
125 sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
126 /*
127 * Map five register banks:
128 *
129 * bank 0: HME SEB registers: +0x0000
130 * bank 1: HME ETX registers: +0x2000
131 * bank 2: HME ERX registers: +0x4000
132 * bank 3: HME MAC registers: +0x6000
133 * bank 4: HME MIF registers: +0x7000
134 *
135 */
136
137 #define PCI_HME_BASEADDR 0x10
138 if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0,
139 &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0)
140 {
141 printf(": could not map hme registers\n");
142 return;
143 }
144 sc->sc_seb = hsc->hsc_memh;
145 sc->sc_etx = hsc->hsc_memh + 0x2000;
146 sc->sc_erx = hsc->hsc_memh + 0x4000;
147 sc->sc_mac = hsc->hsc_memh + 0x6000;
148 sc->sc_mif = hsc->hsc_memh + 0x7000;
149
150 myetheraddr(sc->sc_enaddr);
151
152 #if 0
153 /*
154 * Get transfer burst size from PROM and pass it on
155 * to the back-end driver.
156 */
157 sbusburst = ((struct sbus_softc *)parent)->sc_burst;
158 if (sbusburst == 0)
159 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
160
161 burst = getpropint(node, "burst-sizes", -1);
162 if (burst == -1)
163 /* take SBus burst sizes */
164 burst = sbusburst;
165
166 /* Clamp at parent's burst sizes */
167 burst &= sbusburst;
168
169 /* Translate into plain numerical format */
170 sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
171 (burst & SBUS_BURST_16) ? 16 : 0;
172 #endif
173
174 sc->sc_burst = 16; /* XXX */
175
176 /*
177 * call the main configure
178 */
179 hme_config(sc);
180
181 #if 0
182 printf("%s: ", sc->sc_dev.dv_xname);
183 pci_conf_print(pa->pa_pc, pa->pa_tag, 0);
184 #endif
185
186 if (pci_intr_map(pa, &intrhandle) != 0) {
187 printf("%s: couldn't map interrupt\n",
188 sc->sc_dev.dv_xname);
189 return; /* bus_unmap ? */
190 }
191 intrstr = pci_intr_string(pa->pa_pc, intrhandle);
192 hsc->hsc_ih = pci_intr_establish(pa->pa_pc,
193 intrhandle, IPL_NET, hme_intr, sc);
194 if (hsc->hsc_ih != NULL) {
195 printf("%s: using %s for interrupt\n",
196 sc->sc_dev.dv_xname,
197 intrstr ? intrstr : "unknown interrupt");
198 } else {
199 printf("%s: couldn't establish interrupt",
200 sc->sc_dev.dv_xname);
201 if (intrstr != NULL)
202 printf(" at %s", intrstr);
203 printf("\n");
204 return; /* bus_unmap ? */
205 }
206 }
207