2 * $FreeBSD: src/sys/boot/alpha/libalpha/srmnet.c,v 1.4 1999/09/06 18:32:40 dfr Exp $
3 * $DragonFly: src/sys/boot/alpha/libalpha/Attic/srmnet.c,v 1.2 2003/06/17 04:28:16 dillon Exp $
4 * From: $NetBSD: if_prom.c,v 1.10 1997/09/06 14:08:33 drochner Exp $
8 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
9 * Copyright (c) 1993 Adam Glass
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Adam Glass.
23 * 4. The name of the Author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/param.h>
40 #include <sys/types.h>
42 #include <netinet/in.h>
43 #include <netinet/in_systm.h>
48 #include <machine/prom.h>
58 extern struct netif_stats prom_stats[];
60 struct netif_dif prom_ifs[] = {
61 /* dif_unit dif_nsel dif_stats dif_private */
62 { 0, 1, &prom_stats[0], 0, },
65 struct netif_stats prom_stats[NENTS(prom_ifs)];
67 struct netbbinfo netbbinfo = {
68 0xfeedbabedeadbeef, /* magic number */
70 {0, 0, 0, 0, 0, 0}, /* ether address */
74 0xfeedbeefdeadbabe, /* magic number */
77 struct netif_driver srmnet = {
78 "prom", /* netif_bname */
79 prom_match, /* netif_match */
80 prom_probe, /* netif_probe */
81 prom_init, /* netif_init */
82 prom_get, /* netif_get */
83 prom_put, /* netif_put */
84 prom_end, /* netif_end */
85 prom_ifs, /* netif_ifs */
86 NENTS(prom_ifs) /* netif_nifs */
89 int netfd = 0, broken_firmware;
92 prom_match(nif, machdep_hint)
101 prom_probe(nif, machdep_hint)
110 prom_put(desc, pkt, len)
116 prom_write(netfd, len, pkt, 0);
123 prom_get(desc, pkt, len, timeout)
136 while (((getsecs() - t) < timeout) && !cc) {
138 ret.bits = prom_read(netfd, 0, hate, 0);
140 ret.bits = prom_read(netfd, sizeof hate, hate, 0);
141 if (ret.u.status == 0)
148 bcopy(hate, pkt, cc);
153 extern char *strchr();
156 prom_init(desc, machdep_hint)
170 for (i = 0, qp = (u_int64_t *)&netbbinfo;
171 i < (sizeof netbbinfo / sizeof (u_int64_t)); i++, qp++)
173 netbbinfovalid = (csum == 0);
175 netbbinfovalid = netbbinfo.set;
178 printf("netbbinfo ");
182 printf("valid: force = %d, ea = %s\n", netbbinfo.force,
183 ether_sprintf(netbbinfo.ether_addr));
186 ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
187 devlen = ret.u.retval;
189 /* Ethernet address is the 9th component of the booted_dev string. */
191 for (i = 0; i < 8; i++) {
192 enet_addr = strchr(enet_addr, ' ');
193 if (enet_addr == NULL) {
194 printf("boot: boot device name does not contain ethernet address.\n");
199 if (enet_addr != NULL) {
202 #define dval(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
203 (((c) >= 'A' && (c) <= 'F') ? (10 + (c) - 'A') : \
204 (((c) >= 'a' && (c) <= 'f') ? (10 + (c) - 'a') : -1)))
206 for (i = 0; i < 6; i++) {
207 hv = dval(*enet_addr); enet_addr++;
208 lv = dval(*enet_addr); enet_addr++;
211 if (hv == -1 || lv == -1) {
212 printf("boot: boot device name contains bogus ethernet address.\n");
216 desc->myea[i] = (hv << 4) | lv;
221 if (netbbinfovalid && netbbinfo.force) {
222 printf("boot: using hard-coded ethernet address (forced).\n");
223 bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
227 printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
229 ret.bits = prom_open(devname, devlen + 1);
231 printf("prom_init: open failed: %d\n", ret.u.status);
234 netfd = ret.u.retval;
239 if (netbbinfovalid) {
240 printf("boot: using hard-coded ethernet address.\n");
241 bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
247 printf("Boot device name was: \"%s\"\n", devname);
249 printf("Your firmware may be too old to network-boot FreeBSD/alpha,\n");
250 printf("or you might have to hard-code an ethernet address into\n");
251 printf("your network boot block with setnetbootinfo(8).\n");