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