diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2000-10-19 04:53:07 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2000-10-19 04:53:07 +0000 |
commit | dfb85655ce8ef4ef4a7fada878ab09453688a593 (patch) | |
tree | 2b78cafdf13ecbcdcd9586b805e91d402fde8216 /sys | |
parent | 3547485115c7da68cfa55b8d0f728e1fda51887f (diff) |
Changes to pci and if_gm to support obtaining the ethernet hardware address
from the pci bus. This is in preference to adding openfirmware code to
the device drivers. If there was a known way of obtaining the ethernet
hardware address from a eeprom or other methods that would be used, but
the only known way to get this information for the Apple machines with
if_gm is via openfirmware.
This modifies a previous mechanism that was used to obtain similar information
from different openfirmware systems, however the old mechanism would create
information such as media type. This information was hardcoded into
that code. Now the code only returns the actual address which is the
only informatin that openfirmware provides.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/powerpc/mac/if_gm.c | 34 | ||||
-rw-r--r-- | sys/arch/powerpc/pci/mpcpcibus.c | 96 | ||||
-rw-r--r-- | sys/arch/powerpc/pci/pci_machdep.h | 10 | ||||
-rw-r--r-- | sys/arch/powerpc/pci/pcibrvar.h | 3 |
4 files changed, 67 insertions, 76 deletions
diff --git a/sys/arch/powerpc/mac/if_gm.c b/sys/arch/powerpc/mac/if_gm.c index e346156da91..acab31afb1b 100644 --- a/sys/arch/powerpc/mac/if_gm.c +++ b/sys/arch/powerpc/mac/if_gm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gm.c,v 1.8 2000/10/18 23:24:42 drahn Exp $ */ +/* $OpenBSD: if_gm.c,v 1.9 2000/10/19 04:53:05 drahn Exp $ */ /* $NetBSD: if_gm.c,v 1.2 2000/03/04 11:17:00 tsubai Exp $ */ /*- @@ -171,7 +171,7 @@ gmac_attach(parent, self, aux) bus_size_t iosize; bus_addr_t membase; bus_size_t memsize; -#if 0 +#ifdef __NetBSD__ int node; #endif int i; @@ -180,7 +180,7 @@ gmac_attach(parent, self, aux) u_int32_t reg[10]; u_char laddr[6]; -#if 0 +#ifdef __NetBSD__ node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag); if (node == 0) { printf(": cannot find gmac node\n"); @@ -189,13 +189,12 @@ gmac_attach(parent, self, aux) OF_getprop(node, "local-mac-address", laddr, sizeof laddr); OF_getprop(node, "assigned-addresses", reg, sizeof reg); - #endif - -#ifdef __NetBSD__ bcopy(laddr, sc->sc_laddr, sizeof laddr); sc->sc_reg = reg[2]; -#endif /* !__OpenBSD */ +#endif #ifdef __OpenBSD__ + pci_ether_hw_addr(pc, laddr); + /* proper pci configuration */ { u_int32_t command; @@ -251,7 +250,7 @@ gmac_attach(parent, self, aux) } #endif #if 1 - sprintf(intrstrbuf, "irq %d\n", pa->pa_intrline); + sprintf(intrstrbuf, "irq %d", pa->pa_intrline); intrstr = intrstrbuf; /* if (pci_intr_establish(pa->pa_pc, pa->pa_intrline, IPL_NET, @@ -300,24 +299,9 @@ gmac_attach(parent, self, aux) dp++; p += 2048; } + #ifdef __OpenBSD__ - { - /* rather than call openfirmware, expect that ethernet - * is already intialized, read the address - * from the device -- hack? - */ - u_int reg; - reg = gmac_read_reg(sc, GMAC_MACADDRESS0); - laddr[5] = reg & 0xff; - laddr[4] = (reg >> 8) & 0xff; - reg = gmac_read_reg(sc, GMAC_MACADDRESS1); - laddr[3] = reg & 0xff; - laddr[2] = (reg >> 8) & 0xff; - reg = gmac_read_reg(sc, GMAC_MACADDRESS2); - laddr[1] = reg & 0xff; - laddr[0] = (reg >> 8) & 0xff; - bcopy(laddr, sc->arpcom.ac_enaddr, 6); - } + bcopy(laddr, sc->sc_enaddr, 6); #endif /* __OpenBSD__ */ printf(": %s, address %s\n", intrstr, ether_sprintf(laddr)); diff --git a/sys/arch/powerpc/pci/mpcpcibus.c b/sys/arch/powerpc/pci/mpcpcibus.c index f1d796381e2..b2309155132 100644 --- a/sys/arch/powerpc/pci/mpcpcibus.c +++ b/sys/arch/powerpc/pci/mpcpcibus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpcpcibus.c,v 1.21 2000/09/06 02:09:18 rahnds Exp $ */ +/* $OpenBSD: mpcpcibus.c,v 1.22 2000/10/19 04:53:06 drahn Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -79,7 +79,8 @@ const char *mpc_intr_string __P((void *, pci_intr_handle_t)); void *mpc_intr_establish __P((void *, pci_intr_handle_t, int, int (*func)(void *), void *, char *)); void mpc_intr_disestablish __P((void *, void *)); -int mpc_ether_hw_addr __P((u_int8_t *, u_int8_t, u_int8_t)); +int mpc_ether_hw_addr __P((struct ppc_pci_chipset *, u_int8_t *)); +int of_ether_hw_addr __P((struct ppc_pci_chipset *, u_int8_t *)); struct cfattach mpcpcibr_ca = { sizeof(struct pcibr_softc), mpcpcibrmatch, mpcpcibrattach, @@ -109,7 +110,7 @@ struct { int config_type; } config_offsets[] = { {"grackle", 0x00c00cf8, 0x00e00cfc, 0 }, - {"bandit", 0x00c00cf8, 0x00e00cfc, 0 }, + {"bandit", 0x00800000, 0x00c00000, 0 }, {"uni-north", 0x00800000, 0x00c00000, 3 }, {"legacy", 0x00000cf8, 0x00000cfc, 0 }, {"IBM,27-82660", 0x00000cf8, 0x00000cfc, 0 }, @@ -331,6 +332,7 @@ mpcpcibrattach(parent, self, aux) /* scan the children of the root of the openfirmware * tree to locate all nodes with device_type of "pci" */ + if (ca->ca_node == 0) { printf("invalid node on mpcpcibr config\n"); return; @@ -475,6 +477,7 @@ mpcpcibrattach(parent, self, aux) of_node = ca->ca_node; + lcp->node = ca->ca_node; lcp->lc_pc.pc_conf_v = lcp; lcp->lc_pc.pc_attach_hook = mpc_attach_hook; lcp->lc_pc.pc_bus_maxdevs = mpc_bus_maxdevs; @@ -482,7 +485,7 @@ mpcpcibrattach(parent, self, aux) lcp->lc_pc.pc_decompose_tag = mpc_decompose_tag; lcp->lc_pc.pc_conf_read = mpc_conf_read; lcp->lc_pc.pc_conf_write = mpc_conf_write; - lcp->lc_pc.pc_ether_hw_addr = mpc_ether_hw_addr; + lcp->lc_pc.pc_ether_hw_addr = of_ether_hw_addr; lcp->lc_iot = &sc->sc_iobus_space; lcp->lc_memt = &sc->sc_membus_space; @@ -694,47 +697,52 @@ mpc_attach_hook(parent, self, pba) } int -mpc_ether_hw_addr(p, b, s) - u_int8_t *p, b, s; +of_ether_hw_addr(struct ppc_pci_chipset *lcpc, u_int8_t *oaddr) +{ + u_int8_t laddr[6]; + struct pcibr_config *lcp = lcpc->pc_conf_v; + int of_node = lcp->node; + int node, nn; + for (node = OF_child(of_node); node; node = nn) + { + char name[32]; + int len; + len = OF_getprop(node, "name", name, + sizeof(name)); + name[len] = 0; + if (sizeof (laddr) == + OF_getprop(node, "local-mac-address", laddr, + sizeof laddr)) + { + bcopy (laddr, oaddr, sizeof laddr); + return 1; + + } + + /* iterate section */ + if ((nn = OF_child(node)) != 0) { + continue; + } + while ((nn = OF_peer(node)) == 0) { + node = OF_parent(node); + if (node == of_node) { + nn = 0; /* done */ + break; + } + } + } + oaddr[0] = oaddr[1] = oaddr[2] = 0xff; + oaddr[3] = oaddr[4] = oaddr[5] = 0xff; + return 0; +} + +int +mpc_ether_hw_addr(p, s) + struct ppc_pci_chipset *p; + u_int8_t *s; { - int i; - - for(i = 0; i < 128; i++) - p[i] = 0x00; - p[18] = 0x03; /* Srom version. */ - p[19] = 0x01; /* One chip. */ - /* Next six, ethernet address. */ - bcopy(ofw_eth_addr, &p[20], 6); - - p[26] = 0x00; /* Chip 0 device number */ - p[27] = 30; /* Descriptor offset */ - p[28] = 00; - p[29] = 00; /* MBZ */ - /* Descriptor */ - p[30] = 0x00; /* Autosense. */ - p[31] = 0x08; - p[32] = 0xff; /* GP cntrl */ - p[33] = 0x01; /* Block cnt */ -#define GPR_LEN 0 -#define RES_LEN 0 - p[34] = 0x80 + 12 + GPR_LEN + RES_LEN; - p[35] = 0x01; /* MII PHY type */ - p[36] = 0x00; /* PHY number 0 */ - p[37] = 0x00; /* GPR Length */ - p[38] = 0x00; /* Reset Length */ - p[39] = 0x00; /* Media capabilities */ - p[40] = 0x78; /* Media capabilities */ - p[41] = 0x00; /* Autoneg advertisment */ - p[42] = 0x78; /* Autoneg advertisment */ - p[43] = 0x00; /* Full duplex map */ - p[44] = 0x50; /* Full duplex map */ - p[45] = 0x00; /* Treshold map */ - p[46] = 0x18; /* Treshold map */ - - i = (srom_crc32(p, 126) & 0xFFFF) ^ 0xFFFF; - p[126] = i; - p[127] = i >> 8; - return(1); + printf("mpc_ether_hw_addr not supported\n"); + return(0); } int diff --git a/sys/arch/powerpc/pci/pci_machdep.h b/sys/arch/powerpc/pci/pci_machdep.h index 01ed387d78d..4cfcd352634 100644 --- a/sys/arch/powerpc/pci/pci_machdep.h +++ b/sys/arch/powerpc/pci/pci_machdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_machdep.h,v 1.5 1999/11/08 23:49:00 rahnds Exp $ */ +/* $OpenBSD: pci_machdep.h,v 1.6 2000/10/19 04:53:06 drahn Exp $ */ /* * Copyright (c) 1996 Carnegie-Mellon University. @@ -60,11 +60,9 @@ struct ppc_pci_chipset { void *(*pc_intr_establish) __P((void *, pci_intr_handle_t, int, int (*)(void *), void *, char *)); void (*pc_intr_disestablish) __P((void *, void *)); - int (*pc_ether_hw_addr) __P((u_int8_t *, u_int8_t, u_int8_t)); + int (*pc_ether_hw_addr) __P((struct ppc_pci_chipset *, u_int8_t *)); }; -#define NEED_PCI_ETHER_HW_ADDR_FUNC /* srom less pci ether adapter */ - /* * Functions provided to machine-independent PCI code. */ @@ -88,8 +86,8 @@ struct ppc_pci_chipset { (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm)) #define pci_intr_disestablish(c, iv) \ (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) -#define pci_ether_hw_addr(c, p, b, s) \ - (*(c)->pc_ether_hw_addr)((p), (b), (s)) +#define pci_ether_hw_addr(c, s) \ + (*(c)->pc_ether_hw_addr)((c), (s)) vm_offset_t vtophys __P((void *)); diff --git a/sys/arch/powerpc/pci/pcibrvar.h b/sys/arch/powerpc/pci/pcibrvar.h index 21b2ebb9de7..f99ebbc95b4 100644 --- a/sys/arch/powerpc/pci/pcibrvar.h +++ b/sys/arch/powerpc/pci/pcibrvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcibrvar.h,v 1.5 2000/03/20 07:10:51 rahnds Exp $ */ +/* $OpenBSD: pcibrvar.h,v 1.6 2000/10/19 04:53:06 drahn Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom @@ -41,6 +41,7 @@ struct pcibr_config { int config_type; int bus; int pci_init_done; + int node; }; struct pcibr_softc { |