This source file includes following definitions.
- hmematch_pci
- hme_pci_enaddr
- hmeattach_pci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/syslog.h>
39 #include <sys/device.h>
40 #include <sys/malloc.h>
41 #include <sys/socket.h>
42
43 #include <net/if.h>
44 #include <net/if_dl.h>
45 #include <net/if_media.h>
46
47 #ifdef INET
48 #include <netinet/in.h>
49 #include <netinet/in_systm.h>
50 #include <netinet/in_var.h>
51 #include <netinet/ip.h>
52 #include <netinet/if_ether.h>
53 #endif
54
55 #include <dev/mii/mii.h>
56 #include <dev/mii/miivar.h>
57
58 #ifdef __sparc64__
59 #include <machine/autoconf.h>
60 #include <dev/ofw/openfirm.h>
61 #endif
62 #include <machine/cpu.h>
63
64 #include <dev/pci/pcivar.h>
65 #include <dev/pci/pcireg.h>
66 #include <dev/pci/pcidevs.h>
67
68 #include <dev/ic/hmevar.h>
69
70 struct hme_pci_softc {
71 struct hme_softc hsc_hme;
72 bus_space_tag_t hsc_memt;
73 bus_space_handle_t hsc_memh;
74 void *hsc_ih;
75 };
76
77 int hmematch_pci(struct device *, void *, void *);
78 void hmeattach_pci(struct device *, struct device *, void *);
79 int hme_pci_enaddr(struct hme_softc *, struct pci_attach_args *);
80
81 struct cfattach hme_pci_ca = {
82 sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci
83 };
84
85 int
86 hmematch_pci(parent, vcf, aux)
87 struct device *parent;
88 void *vcf;
89 void *aux;
90 {
91 struct pci_attach_args *pa = aux;
92
93 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
94 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HME)
95 return (1);
96
97 return (0);
98 }
99
100 #define PCI_EBUS2_BOOTROM 0x10
101 #define PROMHDR_PTR_DATA 0x18
102 #define PROMDATA_PTR_VPD 0x08
103 #define PROMDATA_DATA2 0x0a
104
105 static const u_int8_t hme_promhdr[] = { 0x55, 0xaa };
106 static const u_int8_t hme_promdat[] = {
107 'P', 'C', 'I', 'R',
108 PCI_VENDOR_SUN & 0xff, PCI_VENDOR_SUN >> 8,
109 PCI_PRODUCT_SUN_HME & 0xff, PCI_PRODUCT_SUN_HME >> 8
110 };
111 static const u_int8_t hme_promdat2[] = {
112 0x18, 0x00,
113 0x00,
114 0x00,
115 PCI_SUBCLASS_NETWORK_ETHERNET,
116 PCI_CLASS_NETWORK
117 };
118
119 int
120 hme_pci_enaddr(struct hme_softc *sc, struct pci_attach_args *hpa)
121 {
122 struct pci_attach_args epa;
123 struct pci_vpd *vpd;
124 pcireg_t cl, id;
125 bus_space_handle_t romh;
126 bus_space_tag_t romt;
127 bus_size_t romsize = 0;
128 u_int8_t buf[32];
129 int dataoff, vpdoff;
130
131
132
133
134
135
136
137
138
139
140 epa = *hpa;
141 epa.pa_tag = pci_make_tag(hpa->pa_pc, hpa->pa_bus, hpa->pa_device, 0);
142 cl = pci_conf_read(epa.pa_pc, epa.pa_tag, PCI_CLASS_REG);
143 id = pci_conf_read(epa.pa_pc, epa.pa_tag, PCI_ID_REG);
144
145 if (PCI_CLASS(cl) != PCI_CLASS_BRIDGE ||
146 PCI_PRODUCT(id) != PCI_PRODUCT_SUN_EBUS)
147 goto fail;
148
149 if (pci_mapreg_map(&epa, PCI_EBUS2_BOOTROM, PCI_MAPREG_TYPE_MEM, 0,
150 &romt, &romh, 0, &romsize, 0))
151 goto fail;
152
153 bus_space_read_region_1(romt, romh, 0, buf, sizeof(buf));
154 if (bcmp(buf, hme_promhdr, sizeof(hme_promhdr)))
155 goto fail;
156
157 dataoff = buf[PROMHDR_PTR_DATA] | (buf[PROMHDR_PTR_DATA + 1] << 8);
158 if (dataoff < 0x1c)
159 goto fail;
160
161 bus_space_read_region_1(romt, romh, dataoff, buf, sizeof(buf));
162 if (bcmp(buf, hme_promdat, sizeof(hme_promdat)) ||
163 bcmp(buf + PROMDATA_DATA2, hme_promdat2, sizeof(hme_promdat2)))
164 goto fail;
165
166 vpdoff = buf[PROMDATA_PTR_VPD] | (buf[PROMDATA_PTR_VPD + 1] << 8);
167 if (vpdoff < 0x1c)
168 goto fail;
169
170
171
172
173
174
175 bus_space_read_region_1(romt, romh, vpdoff, buf, sizeof(buf));
176
177
178 vpd = (struct pci_vpd *)(buf + 3);
179 if (!PCI_VPDRES_ISLARGE(buf[0]) ||
180 PCI_VPDRES_LARGE_NAME(buf[0]) != PCI_VPDRES_TYPE_VPD)
181 goto fail;
182 if (vpd->vpd_key0 != 'N' || vpd->vpd_key1 != 'A')
183 goto fail;
184
185 bcopy(buf + 6, sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN);
186 sc->sc_arpcom.ac_enaddr[5] += hpa->pa_device;
187 bus_space_unmap(romt, romh, romsize);
188 return (0);
189
190 fail:
191 if (romsize != 0)
192 bus_space_unmap(romt, romh, romsize);
193 return (-1);
194 }
195
196 void
197 hmeattach_pci(parent, self, aux)
198 struct device *parent, *self;
199 void *aux;
200 {
201 struct pci_attach_args *pa = aux;
202 struct hme_pci_softc *hsc = (void *)self;
203 struct hme_softc *sc = &hsc->hsc_hme;
204 pci_intr_handle_t ih;
205
206 extern void myetheraddr(u_char *);
207 pcireg_t csr;
208 const char *intrstr = NULL;
209 bus_size_t size;
210 int type, gotenaddr = 0;
211
212
213
214
215
216 if (pa->pa_memt)
217 pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
218 if (pa->pa_iot)
219 pa->pa_flags |= PCI_FLAGS_IO_ENABLED;
220 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
221 if (pa->pa_memt) {
222 type = PCI_MAPREG_TYPE_MEM;
223 csr |= PCI_COMMAND_MEM_ENABLE;
224 sc->sc_bustag = pa->pa_memt;
225 } else {
226 type = PCI_MAPREG_TYPE_IO;
227 csr |= PCI_COMMAND_IO_ENABLE;
228 sc->sc_bustag = pa->pa_iot;
229 }
230 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
231 csr | PCI_COMMAND_MEM_ENABLE);
232
233 sc->sc_dmatag = pa->pa_dmat;
234
235 sc->sc_pci = 1;
236
237
238
239
240
241
242
243
244
245
246
247 #define PCI_HME_BASEADDR 0x10
248 if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0,
249 &hsc->hsc_memt, &hsc->hsc_memh, NULL, &size, 0) != 0) {
250 printf(": could not map hme registers\n");
251 return;
252 }
253 sc->sc_seb = hsc->hsc_memh;
254 bus_space_subregion(sc->sc_bustag, hsc->hsc_memh, 0x2000, 0x2000,
255 &sc->sc_etx);
256 bus_space_subregion(sc->sc_bustag, hsc->hsc_memh, 0x4000, 0x2000,
257 &sc->sc_erx);
258 bus_space_subregion(sc->sc_bustag, hsc->hsc_memh, 0x6000, 0x1000,
259 &sc->sc_mac);
260 bus_space_subregion(sc->sc_bustag, hsc->hsc_memh, 0x7000, 0x1000,
261 &sc->sc_mif);
262
263 if (hme_pci_enaddr(sc, pa) == 0)
264 gotenaddr = 1;
265
266 #ifdef __sparc64__
267 if (!gotenaddr) {
268 if (OF_getprop(PCITAG_NODE(pa->pa_tag), "local-mac-address",
269 sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN) <= 0)
270 myetheraddr(sc->sc_arpcom.ac_enaddr);
271 gotenaddr = 1;
272 }
273 #endif
274 #ifdef __powerpc__
275 if (!gotenaddr) {
276 pci_ether_hw_addr(pa->pa_pc, sc->sc_arpcom.ac_enaddr);
277 gotenaddr = 1;
278 }
279 #endif
280
281 sc->sc_burst = 16;
282
283 if (pci_intr_map(pa, &ih) != 0) {
284 printf(": couldn't map interrupt\n");
285 bus_space_unmap(hsc->hsc_memt, hsc->hsc_memh, size);
286 return;
287 }
288 intrstr = pci_intr_string(pa->pa_pc, ih);
289 hsc->hsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET,
290 hme_intr, sc, self->dv_xname);
291 if (hsc->hsc_ih == NULL) {
292 printf(": couldn't establish interrupt");
293 if (intrstr != NULL)
294 printf(" at %s", intrstr);
295 printf("\n");
296 bus_space_unmap(hsc->hsc_memt, hsc->hsc_memh, size);
297 return;
298 }
299
300 printf(": %s", intrstr);
301
302
303
304
305 hme_config(sc);
306 }