if_cfe.c revision 1.1
11.1Scgd/* $NetBSD: if_cfe.c,v 1.1 2002/11/09 06:20:42 cgd Exp $ */ 21.1Scgd 31.1Scgd/* 41.1Scgd * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. 51.1Scgd * Copyright (c) 1993 Adam Glass 61.1Scgd * All rights reserved. 71.1Scgd * 81.1Scgd * Redistribution and use in source and binary forms, with or without 91.1Scgd * modification, are permitted provided that the following conditions 101.1Scgd * are met: 111.1Scgd * 1. Redistributions of source code must retain the above copyright 121.1Scgd * notice, this list of conditions and the following disclaimer. 131.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 141.1Scgd * notice, this list of conditions and the following disclaimer in the 151.1Scgd * documentation and/or other materials provided with the distribution. 161.1Scgd * 3. All advertising materials mentioning features or use of this software 171.1Scgd * must display the following acknowledgement: 181.1Scgd * This product includes software developed by Adam Glass. 191.1Scgd * 4. The name of the Author may not be used to endorse or promote products 201.1Scgd * derived from this software without specific prior written permission. 211.1Scgd * 221.1Scgd * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND 231.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Scgd * SUCH DAMAGE. 331.1Scgd */ 341.1Scgd 351.1Scgd#include <sys/param.h> 361.1Scgd#include <sys/types.h> 371.1Scgd 381.1Scgd#include <netinet/in.h> 391.1Scgd#include <netinet/in_systm.h> 401.1Scgd 411.1Scgd#include <lib/libsa/stand.h> 421.1Scgd#include <lib/libsa/net.h> 431.1Scgd#include <lib/libsa/netif.h> 441.1Scgd#include <lib/libkern/libkern.h> 451.1Scgd 461.1Scgd#include "stand/common/common.h" 471.1Scgd#include "stand/common/bbinfo.h" 481.1Scgd#include "stand/common/cfe_api.h" 491.1Scgd#include "stand/common/cfe_ioctl.h" 501.1Scgd 511.1Scgdint cfenet_probe(struct netif *, void *); 521.1Scgdint cfenet_match(struct netif *, void *); 531.1Scgdvoid cfenet_init(struct iodesc *, void *); 541.1Scgdint cfenet_get(struct iodesc *, void *, size_t, time_t); 551.1Scgdint cfenet_put(struct iodesc *, void *, size_t); 561.1Scgdvoid cfenet_end(struct netif *); 571.1Scgd 581.1Scgdextern struct netif_stats cfenet_stats[]; 591.1Scgd 601.1Scgdstruct netif_dif cfenet_ifs[] = { 611.1Scgd/* dif_unit dif_nsel dif_stats dif_private */ 621.1Scgd{ 0, 1, &cfenet_stats[0], 0, }, 631.1Scgd}; 641.1Scgd 651.1Scgdstruct netif_stats cfenet_stats[NENTS(cfenet_ifs)]; 661.1Scgd 671.1Scgdstruct netif_driver prom_netif_driver = { 681.1Scgd "cfe", /* netif_bname */ 691.1Scgd cfenet_match, /* netif_match */ 701.1Scgd cfenet_probe, /* netif_probe */ 711.1Scgd cfenet_init, /* netif_init */ 721.1Scgd cfenet_get, /* netif_get */ 731.1Scgd cfenet_put, /* netif_put */ 741.1Scgd cfenet_end, /* netif_end */ 751.1Scgd cfenet_ifs, /* netif_ifs */ 761.1Scgd NENTS(cfenet_ifs) /* netif_nifs */ 771.1Scgd}; 781.1Scgd 791.1Scgdint 801.1Scgdcfenet_match(nif, machdep_hint) 811.1Scgd struct netif *nif; 821.1Scgd void *machdep_hint; 831.1Scgd{ 841.1Scgd 851.1Scgd return (1); 861.1Scgd} 871.1Scgd 881.1Scgdint 891.1Scgdcfenet_probe(nif, machdep_hint) 901.1Scgd struct netif *nif; 911.1Scgd void *machdep_hint; 921.1Scgd{ 931.1Scgd 941.1Scgd return 0; 951.1Scgd} 961.1Scgd 971.1Scgdint 981.1Scgdcfenet_put(desc, pkt, len) 991.1Scgd struct iodesc *desc; 1001.1Scgd void *pkt; 1011.1Scgd size_t len; 1021.1Scgd{ 1031.1Scgd 1041.1Scgd cfe_write(booted_dev_fd,pkt,len); 1051.1Scgd 1061.1Scgd return len; 1071.1Scgd} 1081.1Scgd 1091.1Scgd 1101.1Scgdint 1111.1Scgdcfenet_get(desc, pkt, len, timeout) 1121.1Scgd struct iodesc *desc; 1131.1Scgd void *pkt; 1141.1Scgd size_t len; 1151.1Scgd time_t timeout; 1161.1Scgd{ 1171.1Scgd time_t t; 1181.1Scgd int cc; 1191.1Scgd 1201.1Scgd t = getsecs(); 1211.1Scgd cc = 0; 1221.1Scgd while (((getsecs() - t) < timeout) && !cc) { 1231.1Scgd cc = cfe_read(booted_dev_fd,pkt,len); 1241.1Scgd if (cc < 0) break; 1251.1Scgd break; 1261.1Scgd } 1271.1Scgd 1281.1Scgd return cc; 1291.1Scgd} 1301.1Scgd 1311.1Scgdvoid 1321.1Scgdcfenet_init(desc, machdep_hint) 1331.1Scgd struct iodesc *desc; 1341.1Scgd void *machdep_hint; 1351.1Scgd{ 1361.1Scgd u_int8_t eaddr[6]; 1371.1Scgd int res; 1381.1Scgd 1391.1Scgd res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0); 1401.1Scgd 1411.1Scgd if (res < 0) { 1421.1Scgd printf("boot: boot device name does not contain ethernet address.\n"); 1431.1Scgd goto punt; 1441.1Scgd } 1451.1Scgd 1461.1Scgd bcopy(eaddr,desc->myea,6); 1471.1Scgd 1481.1Scgd printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea)); 1491.1Scgd return; 1501.1Scgd 1511.1Scgdpunt: 1521.1Scgd halt(); 1531.1Scgd 1541.1Scgd} 1551.1Scgd 1561.1Scgdvoid 1571.1Scgdcfenet_end(nif) 1581.1Scgd struct netif *nif; 1591.1Scgd{ 1601.1Scgd 1611.1Scgd /* nothing to do */ 1621.1Scgd} 163