1999-04-02 07:19:08 +04:00
|
|
|
/* $NetBSD: if_prom.c,v 1.12 1999/04/02 03:19:09 cgd Exp $ */
|
1996-09-19 00:03:04 +04:00
|
|
|
|
|
|
|
/*
|
1997-01-18 03:34:01 +03:00
|
|
|
* Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
|
1996-09-19 00:03:04 +04:00
|
|
|
* Copyright (c) 1993 Adam Glass
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Adam Glass.
|
|
|
|
* 4. The name of the Author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
|
1997-09-06 18:08:27 +04:00
|
|
|
#include <lib/libsa/stand.h>
|
|
|
|
#include <lib/libsa/net.h>
|
1997-01-16 04:21:36 +03:00
|
|
|
#include <lib/libsa/netif.h>
|
1997-09-06 18:08:27 +04:00
|
|
|
#include <machine/prom.h>
|
1997-01-16 04:21:36 +03:00
|
|
|
#include <lib/libkern/libkern.h>
|
1996-09-19 00:03:04 +04:00
|
|
|
|
1997-09-06 18:08:27 +04:00
|
|
|
#include "stand/common/common.h"
|
1997-01-24 04:52:35 +03:00
|
|
|
#include "stand/common/bbinfo.h"
|
1997-01-18 03:34:01 +03:00
|
|
|
|
1996-09-19 00:03:04 +04:00
|
|
|
int prom_probe();
|
|
|
|
int prom_match();
|
|
|
|
void prom_init();
|
|
|
|
int prom_get();
|
|
|
|
int prom_put();
|
|
|
|
void prom_end();
|
|
|
|
|
|
|
|
extern struct netif_stats prom_stats[];
|
|
|
|
|
|
|
|
struct netif_dif prom_ifs[] = {
|
|
|
|
/* dif_unit dif_nsel dif_stats dif_private */
|
|
|
|
{ 0, 1, &prom_stats[0], 0, },
|
|
|
|
};
|
|
|
|
|
|
|
|
struct netif_stats prom_stats[NENTS(prom_ifs)];
|
|
|
|
|
1997-01-18 03:34:01 +03:00
|
|
|
struct netbbinfo netbbinfo = {
|
|
|
|
0xfeedbabedeadbeef, /* magic number */
|
|
|
|
0, /* set */
|
1997-09-06 18:08:27 +04:00
|
|
|
{0, 0, 0, 0, 0, 0}, /* ether address */
|
1997-01-18 03:34:01 +03:00
|
|
|
0, /* force */
|
|
|
|
{ 0, }, /* pad2 */
|
|
|
|
0, /* cksum */
|
|
|
|
0xfeedbeefdeadbabe, /* magic number */
|
|
|
|
};
|
|
|
|
|
1996-09-19 00:03:04 +04:00
|
|
|
struct netif_driver prom_netif_driver = {
|
|
|
|
"prom", /* netif_bname */
|
|
|
|
prom_match, /* netif_match */
|
|
|
|
prom_probe, /* netif_probe */
|
|
|
|
prom_init, /* netif_init */
|
|
|
|
prom_get, /* netif_get */
|
|
|
|
prom_put, /* netif_put */
|
|
|
|
prom_end, /* netif_end */
|
|
|
|
prom_ifs, /* netif_ifs */
|
|
|
|
NENTS(prom_ifs) /* netif_nifs */
|
|
|
|
};
|
|
|
|
|
1999-04-02 07:19:08 +04:00
|
|
|
int broken_firmware;
|
1996-09-19 00:03:04 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
prom_match(nif, machdep_hint)
|
|
|
|
struct netif *nif;
|
|
|
|
void *machdep_hint;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
prom_probe(nif, machdep_hint)
|
|
|
|
struct netif *nif;
|
|
|
|
void *machdep_hint;
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
prom_put(desc, pkt, len)
|
|
|
|
struct iodesc *desc;
|
|
|
|
void *pkt;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
|
1999-04-02 07:19:08 +04:00
|
|
|
prom_write(booted_dev_fd, len, pkt, 0);
|
1996-09-19 00:03:04 +04:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
prom_get(desc, pkt, len, timeout)
|
|
|
|
struct iodesc *desc;
|
|
|
|
void *pkt;
|
|
|
|
int len;
|
|
|
|
time_t timeout;
|
|
|
|
{
|
1996-10-03 01:18:45 +04:00
|
|
|
prom_return_t ret;
|
|
|
|
time_t t;
|
|
|
|
int cc;
|
1996-09-19 00:03:04 +04:00
|
|
|
char hate[2000];
|
|
|
|
|
1996-10-03 01:18:45 +04:00
|
|
|
t = getsecs();
|
|
|
|
cc = 0;
|
|
|
|
while (((getsecs() - t) < timeout) && !cc) {
|
1997-01-18 03:34:01 +03:00
|
|
|
if (broken_firmware)
|
1999-04-02 07:19:08 +04:00
|
|
|
ret.bits = prom_read(booted_dev_fd, 0, hate, 0);
|
1997-01-18 03:34:01 +03:00
|
|
|
else
|
1999-04-02 07:19:08 +04:00
|
|
|
ret.bits = prom_read(booted_dev_fd, sizeof hate, hate, 0);
|
1996-09-19 00:03:04 +04:00
|
|
|
if (ret.u.status == 0)
|
1997-01-18 03:34:01 +03:00
|
|
|
cc = ret.u.retval;
|
1996-10-03 01:18:45 +04:00
|
|
|
}
|
1997-01-18 03:34:01 +03:00
|
|
|
if (broken_firmware)
|
|
|
|
cc = min(cc, len);
|
|
|
|
else
|
|
|
|
cc = len;
|
1996-09-19 00:03:04 +04:00
|
|
|
bcopy(hate, pkt, cc);
|
|
|
|
|
1996-10-03 01:18:45 +04:00
|
|
|
return cc;
|
1996-09-19 00:03:04 +04:00
|
|
|
}
|
|
|
|
|
1996-09-23 08:30:56 +04:00
|
|
|
extern char *strchr();
|
|
|
|
|
1996-09-19 00:03:04 +04:00
|
|
|
void
|
|
|
|
prom_init(desc, machdep_hint)
|
|
|
|
struct iodesc *desc;
|
|
|
|
void *machdep_hint;
|
|
|
|
{
|
1999-04-02 07:19:08 +04:00
|
|
|
int i, netbbinfovalid;
|
|
|
|
const char *enet_addr;
|
1997-01-18 03:34:01 +03:00
|
|
|
u_int64_t *qp, csum;
|
|
|
|
|
|
|
|
broken_firmware = 0;
|
|
|
|
|
|
|
|
csum = 0;
|
|
|
|
for (i = 0, qp = (u_int64_t *)&netbbinfo;
|
|
|
|
i < (sizeof netbbinfo / sizeof (u_int64_t)); i++, qp++)
|
|
|
|
csum += *qp;
|
|
|
|
netbbinfovalid = (csum == 0);
|
|
|
|
if (netbbinfovalid)
|
|
|
|
netbbinfovalid = netbbinfo.set;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("netbbinfo ");
|
|
|
|
if (!netbbinfovalid)
|
|
|
|
printf("invalid\n");
|
|
|
|
else
|
|
|
|
printf("valid: force = %d, ea = %s\n", netbbinfo.force,
|
|
|
|
ether_sprintf(netbbinfo.ether_addr));
|
|
|
|
#endif
|
1996-09-19 00:03:04 +04:00
|
|
|
|
1996-09-23 08:30:56 +04:00
|
|
|
/* Ethernet address is the 9th component of the booted_dev string. */
|
1999-04-02 07:19:08 +04:00
|
|
|
enet_addr = booted_dev_name;
|
1996-09-23 08:30:56 +04:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
enet_addr = strchr(enet_addr, ' ');
|
|
|
|
if (enet_addr == NULL) {
|
1997-01-18 04:49:29 +03:00
|
|
|
printf("boot: boot device name does not contain ethernet address.\n");
|
1996-10-03 01:06:56 +04:00
|
|
|
goto punt;
|
1996-09-23 08:30:56 +04:00
|
|
|
}
|
|
|
|
enet_addr++;
|
|
|
|
}
|
|
|
|
if (enet_addr != NULL) {
|
|
|
|
int hv, lv;
|
|
|
|
|
|
|
|
#define dval(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
|
|
|
|
(((c) >= 'A' && (c) <= 'F') ? (10 + (c) - 'A') : \
|
|
|
|
(((c) >= 'a' && (c) <= 'f') ? (10 + (c) - 'a') : -1)))
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
hv = dval(*enet_addr); enet_addr++;
|
|
|
|
lv = dval(*enet_addr); enet_addr++;
|
|
|
|
enet_addr++;
|
|
|
|
|
|
|
|
if (hv == -1 || lv == -1) {
|
1997-01-18 04:49:29 +03:00
|
|
|
printf("boot: boot device name contains bogus ethernet address.\n");
|
1996-10-03 01:06:56 +04:00
|
|
|
goto punt;
|
1996-09-23 08:30:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
desc->myea[i] = (hv << 4) | lv;
|
|
|
|
}
|
|
|
|
#undef dval
|
|
|
|
}
|
|
|
|
|
1997-01-18 03:34:01 +03:00
|
|
|
if (netbbinfovalid && netbbinfo.force) {
|
1997-01-18 04:49:29 +03:00
|
|
|
printf("boot: using hard-coded ethernet address (forced).\n");
|
1997-01-18 03:34:01 +03:00
|
|
|
bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
|
|
|
|
}
|
|
|
|
|
|
|
|
gotit:
|
1996-10-03 01:06:56 +04:00
|
|
|
printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
|
|
|
|
return;
|
1996-09-19 00:03:04 +04:00
|
|
|
|
1996-10-03 01:06:56 +04:00
|
|
|
punt:
|
1997-01-18 03:34:01 +03:00
|
|
|
broken_firmware = 1;
|
|
|
|
if (netbbinfovalid) {
|
1997-01-18 04:49:29 +03:00
|
|
|
printf("boot: using hard-coded ethernet address.\n");
|
1997-01-18 03:34:01 +03:00
|
|
|
bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
|
|
|
|
goto gotit;
|
|
|
|
}
|
|
|
|
|
1997-01-18 04:49:29 +03:00
|
|
|
printf("\n");
|
1999-04-02 07:19:08 +04:00
|
|
|
printf("Boot device name was: \"%s\"\n", booted_dev_name);
|
1996-10-03 01:06:56 +04:00
|
|
|
printf("\n");
|
1997-01-18 03:34:01 +03:00
|
|
|
printf("Your firmware may be too old to network-boot NetBSD/Alpha,\n");
|
|
|
|
printf("or you might have to hard-code an ethernet address into\n");
|
|
|
|
printf("your network boot block with setnetbootinfo(8).\n");
|
1999-04-02 07:19:08 +04:00
|
|
|
|
|
|
|
booted_dev_close();
|
1996-10-03 01:06:56 +04:00
|
|
|
halt();
|
1996-09-19 00:03:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
prom_end(nif)
|
|
|
|
struct netif *nif;
|
|
|
|
{
|
|
|
|
|
1999-04-02 07:19:08 +04:00
|
|
|
/* nothing to do */
|
1999-03-27 12:01:27 +03:00
|
|
|
}
|