| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_gem_pci.c,v 1.49 2020/03/01 05:51:46 thorpej Exp $ */ | | 1 | /* $NetBSD: if_gem_pci.c,v 1.50 2020/03/02 06:38:06 msaitoh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * | | 4 | * |
5 | * Copyright (C) 2001 Eduardo Horvath. | | 5 | * Copyright (C) 2001 Eduardo Horvath. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 26 | * LIABILITY, 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 | | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 | * SUCH DAMAGE. | | 28 | * SUCH DAMAGE. |
29 | * | | 29 | * |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * PCI bindings for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers | | 33 | * PCI bindings for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __KERNEL_RCSID(0, "$NetBSD: if_gem_pci.c,v 1.49 2020/03/01 05:51:46 thorpej Exp $"); | | 37 | __KERNEL_RCSID(0, "$NetBSD: if_gem_pci.c,v 1.50 2020/03/02 06:38:06 msaitoh Exp $"); |
38 | | | 38 | |
39 | #include <sys/param.h> | | 39 | #include <sys/param.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/malloc.h> | | 41 | #include <sys/malloc.h> |
42 | #include <sys/kernel.h> | | 42 | #include <sys/kernel.h> |
43 | #include <sys/socket.h> | | 43 | #include <sys/socket.h> |
44 | #include <sys/errno.h> | | 44 | #include <sys/errno.h> |
45 | #include <sys/device.h> | | 45 | #include <sys/device.h> |
46 | | | 46 | |
47 | #include <machine/endian.h> | | 47 | #include <machine/endian.h> |
48 | | | 48 | |
49 | #include <net/if.h> | | 49 | #include <net/if.h> |
50 | #include <net/if_dl.h> | | 50 | #include <net/if_dl.h> |
| @@ -95,27 +95,27 @@ int | | | @@ -95,27 +95,27 @@ int |
95 | gem_pci_match(device_t parent, cfdata_t cf, void *aux) | | 95 | gem_pci_match(device_t parent, cfdata_t cf, void *aux) |
96 | { | | 96 | { |
97 | struct pci_attach_args *pa = aux; | | 97 | struct pci_attach_args *pa = aux; |
98 | | | 98 | |
99 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN && | | 99 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN && |
100 | (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK || | | 100 | (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK || |
101 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK)) | | 101 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK)) |
102 | return (1); | | 102 | return (1); |
103 | | | 103 | |
104 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE && | | 104 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE && |
105 | (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC || | | 105 | (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC || |
106 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 || | | 106 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2 || |
107 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 || | | 107 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC3 || |
108 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC || | | 108 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC || |
109 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC || | | 109 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_K2_GMAC || |
110 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC || | | 110 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC || |
111 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC)) | | 111 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC)) |
112 | return (1); | | 112 | return (1); |
113 | | | 113 | |
114 | | | 114 | |
115 | return (0); | | 115 | return (0); |
116 | } | | 116 | } |
117 | | | 117 | |
118 | static inline int | | 118 | static inline int |
119 | gempromvalid(u_int8_t* buf) | | 119 | gempromvalid(u_int8_t* buf) |
120 | { | | 120 | { |
121 | return buf[0] == 0x18 && buf[1] == 0x00 && /* structure length */ | | 121 | return buf[0] == 0x18 && buf[1] == 0x00 && /* structure length */ |
| @@ -209,55 +209,57 @@ gem_pci_attach(device_t parent, device_t | | | @@ -209,55 +209,57 @@ gem_pci_attach(device_t parent, device_t |
209 | | | 209 | |
210 | if (sc->sc_variant == GEM_UNKNOWN) { | | 210 | if (sc->sc_variant == GEM_UNKNOWN) { |
211 | aprint_error_dev(sc->sc_dev, "unknown adaptor\n"); | | 211 | aprint_error_dev(sc->sc_dev, "unknown adaptor\n"); |
212 | return; | | 212 | return; |
213 | } | | 213 | } |
214 | | | 214 | |
215 | #define PCI_GEM_BASEADDR (PCI_MAPREG_START + 0x00) | | 215 | #define PCI_GEM_BASEADDR (PCI_MAPREG_START + 0x00) |
216 | | | 216 | |
217 | /* XXX Need to check for a 64-bit mem BAR? */ | | 217 | /* XXX Need to check for a 64-bit mem BAR? */ |
218 | if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, | | 218 | if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, |
219 | PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, | | 219 | PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, |
220 | &sc->sc_bustag, &sc->sc_h1, NULL, &sc->sc_size) != 0) | | 220 | &sc->sc_bustag, &sc->sc_h1, NULL, &sc->sc_size) != 0) |
221 | { | | 221 | { |
222 | aprint_error_dev(sc->sc_dev, "unable to map device registers\n"); | | 222 | aprint_error_dev(sc->sc_dev, |
| | | 223 | "unable to map device registers\n"); |
223 | return; | | 224 | return; |
224 | } | | 225 | } |
225 | if (bus_space_subregion(sc->sc_bustag, sc->sc_h1, | | 226 | if (bus_space_subregion(sc->sc_bustag, sc->sc_h1, |
226 | GEM_PCI_BANK2_OFFSET, GEM_PCI_BANK2_SIZE, &sc->sc_h2)) { | | 227 | GEM_PCI_BANK2_OFFSET, GEM_PCI_BANK2_SIZE, &sc->sc_h2)) { |
227 | aprint_error_dev(sc->sc_dev, "unable to create bank 2 subregion\n"); | | 228 | aprint_error_dev(sc->sc_dev, |
| | | 229 | "unable to create bank 2 subregion\n"); |
228 | return; | | 230 | return; |
229 | } | | 231 | } |
230 | | | 232 | |
231 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), | | 233 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), |
232 | "mac-address")) != NULL) { | | 234 | "mac-address")) != NULL) { |
233 | memcpy(enaddr, prop_data_data_nocopy(data), ETHER_ADDR_LEN); | | 235 | memcpy(enaddr, prop_data_data_nocopy(data), ETHER_ADDR_LEN); |
234 | got_addr = 1; | | 236 | got_addr = 1; |
235 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), | | 237 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), |
236 | "shared-pins")) != NULL) { | | 238 | "shared-pins")) != NULL) { |
237 | memcpy(buf, prop_data_data_nocopy(data), | | 239 | memcpy(buf, prop_data_data_nocopy(data), |
238 | prop_data_size(data)); | | 240 | prop_data_size(data)); |
239 | if (isserdes(buf)) { | | 241 | if (isserdes(buf)) { |
240 | sc->sc_flags |= GEM_SERDES; | | 242 | sc->sc_flags |= GEM_SERDES; |
241 | } | | 243 | } |
242 | } | | 244 | } |
243 | } else { | | 245 | } else { |
244 | /* | | 246 | /* |
245 | * Dig out VPD (vital product data) and acquire Ethernet address. | | 247 | * Dig out VPD (vital product data) and acquire Ethernet |
246 | * The VPD of gem resides in the PCI PROM (PCI FCode). | | 248 | * address. The VPD of gem resides in the PCI PROM (PCI FCode). |
247 | */ | | 249 | */ |
248 | /* | | 250 | /* |
249 | * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and later) | | 251 | * ``Writing FCode 3.x Programs'' (newer ones, dated 1997 and |
250 | * chapter 2 describes the data structure. | | 252 | * later) chapter 2 describes the data structure. |
251 | */ | | 253 | */ |
252 | | | 254 | |
253 | enp = NULL; | | 255 | enp = NULL; |
254 | | | 256 | |
255 | if (sc->sc_variant == GEM_SUN_GEM && | | 257 | if (sc->sc_variant == GEM_SUN_GEM && |
256 | (bus_space_subregion(sc->sc_bustag, sc->sc_h1, | | 258 | (bus_space_subregion(sc->sc_bustag, sc->sc_h1, |
257 | GEM_PCI_ROM_OFFSET, GEM_PCI_ROM_SIZE, &romh)) == 0) { | | 259 | GEM_PCI_ROM_OFFSET, GEM_PCI_ROM_SIZE, &romh)) == 0) { |
258 | | | 260 | |
259 | /* read PCI Expansion PROM Header */ | | 261 | /* read PCI Expansion PROM Header */ |
260 | bus_space_read_region_1(sc->sc_bustag, | | 262 | bus_space_read_region_1(sc->sc_bustag, |
261 | romh, 0, buf, sizeof buf); | | 263 | romh, 0, buf, sizeof buf); |
262 | | | 264 | |
263 | /* Check for "shared-pins = serdes" in FCode. */ | | 265 | /* Check for "shared-pins = serdes" in FCode. */ |
| @@ -269,28 +271,28 @@ gem_pci_attach(device_t parent, device_t | | | @@ -269,28 +271,28 @@ gem_pci_attach(device_t parent, device_t |
269 | serdes = 1; | | 271 | serdes = 1; |
270 | } else { | | 272 | } else { |
271 | if (isshared_pins(&buf[i])) | | 273 | if (isshared_pins(&buf[i])) |
272 | serdes = 2; | | 274 | serdes = 2; |
273 | } | | 275 | } |
274 | if (serdes == 2) { | | 276 | if (serdes == 2) { |
275 | sc->sc_flags |= GEM_SERDES; | | 277 | sc->sc_flags |= GEM_SERDES; |
276 | break; | | 278 | break; |
277 | } | | 279 | } |
278 | i++; | | 280 | i++; |
279 | } | | 281 | } |
280 | #ifdef GEM_DEBUG | | 282 | #ifdef GEM_DEBUG |
281 | /* PROM dump */ | | 283 | /* PROM dump */ |
282 | printf("%s: PROM dump (0x0000 to %04zx)\n", device_xname(sc->sc_dev), | | 284 | printf("%s: PROM dump (0x0000 to %04zx)\n", |
283 | (sizeof buf) - 1); | | 285 | device_xname(sc->sc_dev), (sizeof buf) - 1); |
284 | i = 0; | | 286 | i = 0; |
285 | j = 0; | | 287 | j = 0; |
286 | printf(" %04x ", i); | | 288 | printf(" %04x ", i); |
287 | while (i < sizeof buf) { | | 289 | while (i < sizeof buf) { |
288 | printf("%02x ", buf[i]); | | 290 | printf("%02x ", buf[i]); |
289 | if (i && !(i % 8)) | | 291 | if (i && !(i % 8)) |
290 | printf(" "); | | 292 | printf(" "); |
291 | if (i && !(i % 16)) { | | 293 | if (i && !(i % 16)) { |
292 | printf(" "); | | 294 | printf(" "); |
293 | while (j < i) { | | 295 | while (j < i) { |
294 | if (buf[j] > 31 && buf[j] < 128) | | 296 | if (buf[j] > 31 && buf[j] < 128) |
295 | printf("%c", buf[j]); | | 297 | printf("%c", buf[j]); |
296 | else | | 298 | else |
| @@ -300,66 +302,68 @@ gem_pci_attach(device_t parent, device_t | | | @@ -300,66 +302,68 @@ gem_pci_attach(device_t parent, device_t |
300 | j = i; | | 302 | j = i; |
301 | printf("\n %04x ", i); | | 303 | printf("\n %04x ", i); |
302 | } | | 304 | } |
303 | i++; | | 305 | i++; |
304 | } | | 306 | } |
305 | printf("\n"); | | 307 | printf("\n"); |
306 | #endif | | 308 | #endif |
307 | | | 309 | |
308 | if (memcmp(buf, promhdr, sizeof promhdr) == 0 && | | 310 | if (memcmp(buf, promhdr, sizeof promhdr) == 0 && |
309 | (dataoff = (buf[PROMHDR_PTR_DATA] | | | 311 | (dataoff = (buf[PROMHDR_PTR_DATA] | |
310 | (buf[PROMHDR_PTR_DATA + 1] << 8))) >= 0x1c) { | | 312 | (buf[PROMHDR_PTR_DATA + 1] << 8))) >= 0x1c) { |
311 | | | 313 | |
312 | /* read PCI Expansion PROM Data */ | | 314 | /* read PCI Expansion PROM Data */ |
313 | bus_space_read_region_1(sc->sc_bustag, romh, dataoff, | | 315 | bus_space_read_region_1(sc->sc_bustag, romh, |
314 | buf, 64); | | 316 | dataoff, buf, 64); |
315 | if (memcmp(buf, promdat, sizeof promdat) == 0 && | | 317 | if (memcmp(buf, promdat, sizeof promdat) == 0 && |
316 | gempromvalid(buf + PROMDATA_DATA2) && | | 318 | gempromvalid(buf + PROMDATA_DATA2) && |
317 | (vpdoff = (buf[PROMDATA_PTR_VPD] | | | 319 | (vpdoff = (buf[PROMDATA_PTR_VPD] | |
318 | (buf[PROMDATA_PTR_VPD + 1] << 8))) >= 0x1c) { | | 320 | (buf[PROMDATA_PTR_VPD + 1] << 8))) >= 0x1c) { |
319 | | | 321 | |
320 | /* | | 322 | /* |
321 | * The VPD of gem is not in PCI 2.2 standard | | 323 | * The VPD of gem is not in PCI 2.2 |
322 | * format. The length in the resource header | | 324 | * standard format. The length in the |
323 | * is in big endian, and resources are not | | 325 | * resource header is in big endian, |
324 | * properly terminated (only one resource | | 326 | * and resources are not properly |
325 | * and no end tag). | | 327 | * terminated (only one resource and no |
| | | 328 | * end tag). |
326 | */ | | 329 | */ |
327 | /* read PCI VPD */ | | 330 | /* read PCI VPD */ |
328 | bus_space_read_region_1(sc->sc_bustag, romh, | | 331 | bus_space_read_region_1(sc->sc_bustag, |
329 | vpdoff, buf, 64); | | 332 | romh, vpdoff, buf, 64); |
330 | vpd = (void *)(buf + 3); | | 333 | vpd = (void *)(buf + 3); |
331 | if (PCI_VPDRES_ISLARGE(buf[0]) && | | 334 | if (PCI_VPDRES_ISLARGE(buf[0]) && |
332 | PCI_VPDRES_LARGE_NAME(buf[0]) | | 335 | PCI_VPDRES_LARGE_NAME(buf[0]) |
333 | == PCI_VPDRES_TYPE_VPD && | | 336 | == PCI_VPDRES_TYPE_VPD && |
334 | vpd->vpd_key0 == 0x4e /* N */ && | | 337 | vpd->vpd_key0 == 0x4e /* N */ && |
335 | vpd->vpd_key1 == 0x41 /* A */ && | | 338 | vpd->vpd_key1 == 0x41 /* A */ && |
336 | vpd->vpd_len == ETHER_ADDR_LEN) { | | 339 | vpd->vpd_len == ETHER_ADDR_LEN) { |
337 | /* | | 340 | /* |
338 | * Ethernet address found | | 341 | * Ethernet address found |
339 | */ | | 342 | */ |
340 | enp = buf + 6; | | 343 | enp = buf + 6; |
341 | } | | 344 | } |
342 | } | | 345 | } |
343 | } | | 346 | } |
344 | } | | 347 | } |
345 | | | 348 | |
346 | if (enp) { | | 349 | if (enp) { |
347 | memcpy(enaddr, enp, ETHER_ADDR_LEN); | | 350 | memcpy(enaddr, enp, ETHER_ADDR_LEN); |
348 | got_addr = 1; | | 351 | got_addr = 1; |
349 | } | | 352 | } |
350 | } | | 353 | } |
351 | if (!got_addr) { | | 354 | if (!got_addr) { |
352 | printf("%s: no Ethernet address found\n", device_xname(sc->sc_dev)); | | 355 | printf("%s: no Ethernet address found\n", |
| | | 356 | device_xname(sc->sc_dev)); |
353 | /* should we bail here? */ | | 357 | /* should we bail here? */ |
354 | } | | 358 | } |
355 | | | 359 | |
356 | if (pci_intr_map(pa, &gsc->gsc_handle) != 0) { | | 360 | if (pci_intr_map(pa, &gsc->gsc_handle) != 0) { |
357 | aprint_error_dev(sc->sc_dev, "unable to map interrupt\n"); | | 361 | aprint_error_dev(sc->sc_dev, "unable to map interrupt\n"); |
358 | return; | | 362 | return; |
359 | } | | 363 | } |
360 | gsc->gsc_pc = pa->pa_pc; | | 364 | gsc->gsc_pc = pa->pa_pc; |
361 | gem_pci_estintr(gsc); | | 365 | gem_pci_estintr(gsc); |
362 | | | 366 | |
363 | /* Finish off the attach. */ | | 367 | /* Finish off the attach. */ |
364 | gem_attach(sc, enaddr); | | 368 | gem_attach(sc, enaddr); |
365 | | | 369 | |
| @@ -381,27 +385,28 @@ gem_pci_suspend(device_t self, const pmf | | | @@ -381,27 +385,28 @@ gem_pci_suspend(device_t self, const pmf |
381 | gsc->gsc_ih = NULL; | | 385 | gsc->gsc_ih = NULL; |
382 | } | | 386 | } |
383 | | | 387 | |
384 | return true; | | 388 | return true; |
385 | } | | 389 | } |
386 | | | 390 | |
387 | static bool | | 391 | static bool |
388 | gem_pci_estintr(struct gem_pci_softc *gsc) | | 392 | gem_pci_estintr(struct gem_pci_softc *gsc) |
389 | { | | 393 | { |
390 | struct gem_softc *sc = &gsc->gsc_gem; | | 394 | struct gem_softc *sc = &gsc->gsc_gem; |
391 | const char *intrstr; | | 395 | const char *intrstr; |
392 | char intrbuf[PCI_INTRSTR_LEN]; | | 396 | char intrbuf[PCI_INTRSTR_LEN]; |
393 | | | 397 | |
394 | intrstr = pci_intr_string(gsc->gsc_pc, gsc->gsc_handle, intrbuf, sizeof(intrbuf)); | | 398 | intrstr = pci_intr_string(gsc->gsc_pc, gsc->gsc_handle, intrbuf, |
| | | 399 | sizeof(intrbuf)); |
395 | gsc->gsc_ih = pci_intr_establish_xname(gsc->gsc_pc, gsc->gsc_handle, | | 400 | gsc->gsc_ih = pci_intr_establish_xname(gsc->gsc_pc, gsc->gsc_handle, |
396 | IPL_NET, gem_intr, sc, device_xname(sc->sc_dev)); | | 401 | IPL_NET, gem_intr, sc, device_xname(sc->sc_dev)); |
397 | if (gsc->gsc_ih == NULL) { | | 402 | if (gsc->gsc_ih == NULL) { |
398 | aprint_error_dev(sc->sc_dev, "unable to establish interrupt"); | | 403 | aprint_error_dev(sc->sc_dev, "unable to establish interrupt"); |
399 | if (intrstr != NULL) | | 404 | if (intrstr != NULL) |
400 | aprint_error(" at %s", intrstr); | | 405 | aprint_error(" at %s", intrstr); |
401 | aprint_error("\n"); | | 406 | aprint_error("\n"); |
402 | return false; | | 407 | return false; |
403 | } | | 408 | } |
404 | aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr); | | 409 | aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr); |
405 | return true; | | 410 | return true; |
406 | } | | 411 | } |
407 | | | 412 | |