1 /* $NetBSD: if_prom.c,v 1.19 2003/03/13 14:15:58 drochner Exp $ */
4 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1993 Adam Glass
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Adam Glass.
19 * 4. The name of the Author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/param.h>
36 #include <sys/types.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
41 #include <lib/libsa/stand.h>
42 #include <lib/libsa/net.h>
43 #include <lib/libsa/netif.h>
44 #include <machine/prom.h>
45 #include <lib/libkern/libkern.h>
47 #include "stand/common/common.h"
48 #include "stand/common/bbinfo.h"
50 extern struct netif_stats prom_stats
[];
52 struct netif_dif prom_ifs
[] = {
53 /* dif_unit dif_nsel dif_stats dif_private */
54 { 0, 1, &prom_stats
[0], 0, },
56 #define NPROM_IFS (sizeof(prom_ifs) / sizeof(prom_ifs[0]))
58 struct netif_stats prom_stats
[NPROM_IFS
];
60 struct netbbinfo netbbinfo
= {
61 0xfeedbabedeadbeef, /* magic number */
63 {0, 0, 0, 0, 0, 0}, /* ether address */
67 0xfeedbeefdeadbabe, /* magic number */
73 prom_match(struct netif
*nif
, void *machdep_hint
)
80 prom_probe(struct netif
*nif
, void *machdep_hint
)
87 prom_put(struct iodesc
*desc
, void *pkt
, size_t len
)
90 prom_write(booted_dev_fd
, len
, pkt
, 0);
96 prom_get(struct iodesc
*desc
, void *pkt
, size_t len
, saseconds_t timeout
)
105 while (((getsecs() - t
) < timeout
) && !cc
) {
107 ret
.bits
= prom_read(booted_dev_fd
, 0, hate
, 0);
109 ret
.bits
= prom_read(booted_dev_fd
, sizeof hate
, hate
, 0);
110 if (ret
.u
.status
== 0)
117 memcpy(pkt
, hate
, cc
);
123 prom_init(struct iodesc
*desc
, void *machdep_hint
)
125 int i
, netbbinfovalid
;
126 const char *enet_addr
;
132 for (i
= 0, qp
= (u_int64_t
*)&netbbinfo
;
133 i
< (sizeof netbbinfo
/ sizeof (u_int64_t
)); i
++, qp
++)
135 netbbinfovalid
= (csum
== 0);
137 netbbinfovalid
= netbbinfo
.set
;
140 printf("netbbinfo ");
144 printf("valid: force = %d, ea = %s\n", netbbinfo
.force
,
145 ether_sprintf(netbbinfo
.ether_addr
));
148 /* Ethernet address is the 9th component of the booted_dev string. */
149 enet_addr
= booted_dev_name
;
150 for (i
= 0; i
< 8; i
++) {
151 enet_addr
= strchr(enet_addr
, ' ');
152 if (enet_addr
== NULL
) {
153 printf("boot: boot device name does not contain ethernet address.\n");
158 if (enet_addr
!= NULL
) {
161 #define dval(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
162 (((c) >= 'A' && (c) <= 'F') ? (10 + (c) - 'A') : \
163 (((c) >= 'a' && (c) <= 'f') ? (10 + (c) - 'a') : -1)))
165 for (i
= 0; i
< 6; i
++) {
166 hv
= dval(*enet_addr
); enet_addr
++;
167 lv
= dval(*enet_addr
); enet_addr
++;
170 if (hv
== -1 || lv
== -1) {
171 printf("boot: boot device name contains bogus ethernet address.\n");
175 desc
->myea
[i
] = (hv
<< 4) | lv
;
180 if (netbbinfovalid
&& netbbinfo
.force
) {
181 printf("boot: using hard-coded ethernet address (forced).\n");
182 memcpy(desc
->myea
, netbbinfo
.ether_addr
, sizeof desc
->myea
);
186 printf("boot: ethernet address: %s\n", ether_sprintf(desc
->myea
));
191 if (netbbinfovalid
) {
192 printf("boot: using hard-coded ethernet address.\n");
193 memcpy(desc
->myea
, netbbinfo
.ether_addr
, sizeof desc
->myea
);
198 printf("Boot device name was: \"%s\"\n", booted_dev_name
);
200 printf("Your firmware may be too old to network-boot NetBSD/alpha,\n");
201 printf("or you might have to hard-code an ethernet address into\n");
202 printf("your network boot block with setnetbootinfo(8).\n");
209 prom_end(struct netif
*nif
)
215 struct netif_driver prom_netif_driver
= {
216 "prom", /* netif_bname */
217 prom_match
, /* netif_match */
218 prom_probe
, /* netif_probe */
219 prom_init
, /* netif_init */
220 prom_get
, /* netif_get */
221 prom_put
, /* netif_put */
222 prom_end
, /* netif_end */
223 prom_ifs
, /* netif_ifs */
224 NPROM_IFS
/* netif_nifs */