xref: /titanic_44/usr/src/psm/promif/ieee1275/sun4/prom_macaddr.c (revision 4bc0a2ef2b7ba50a7a717e7ddbf31472ad28e358)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Return our machine address in the single argument.
31  */
32 
33 #include <sys/promif.h>
34 #include <sys/promimpl.h>
35 #include <sys/idprom.h>
36 
37 /*ARGSUSED*/
38 int
39 prom_getmacaddr(ihandle_t hd, caddr_t ea)
40 {
41 	idprom_t idprom;
42 	pnode_t macnodeid;
43 
44 	/*
45 	 * Look for the 'mac-address' property in the device node
46 	 * associated with the ihandle 'hd'. This handles the
47 	 * cases when we booted from the network device, using either
48 	 * the platform mac address or a local mac address. This
49 	 * code will always return whichever mac-address was used by the
50 	 * firmware (local or platform, depending on nvram settings).
51 	 */
52 	macnodeid = prom_getphandle(hd);
53 	if (macnodeid != OBP_BADNODE) {
54 		if (prom_getproplen(macnodeid, OBP_MAC_ADDR) != -1) {
55 			(void) prom_getprop(macnodeid, OBP_MAC_ADDR, ea);
56 			return (0);
57 		}
58 	}
59 
60 	/*
61 	 * The code above, should have taken care of the case
62 	 * when we booted from the device ... otherwise, as a fallback
63 	 * case, return the system mac address from the idprom.
64 	 * This code (idprom) is SMCC (and compatibles) platform-centric.
65 	 * This code always returns the platform mac address.
66 	 */
67 	if (prom_getidprom((caddr_t)&idprom, sizeof (idprom)) == 0) {
68 		char *f = (char *)idprom.id_ether;
69 		char *t = ea;
70 		int i;
71 
72 		for (i = 0; i < sizeof (idprom.id_ether); ++i)
73 			*t++ = *f++;
74 
75 		return (0);
76 	} else
77 		return (-1); /* our world must be starting to explode */
78 }
79