if_cfe.c revision 1.2
11.2Sdrochner/* $NetBSD: if_cfe.c,v 1.2 2003/03/13 13:59:11 drochner 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.2Sdrochner#define NCFENET_IFS (sizeof(cfenet_ifs) / sizeof(cfenet_ifs[0])) 651.1Scgd 661.2Sdrochnerstruct netif_stats cfenet_stats[NCFENET_IFS]; 671.1Scgd 681.1Scgdstruct netif_driver prom_netif_driver = { 691.1Scgd "cfe", /* netif_bname */ 701.1Scgd cfenet_match, /* netif_match */ 711.1Scgd cfenet_probe, /* netif_probe */ 721.1Scgd cfenet_init, /* netif_init */ 731.1Scgd cfenet_get, /* netif_get */ 741.1Scgd cfenet_put, /* netif_put */ 751.1Scgd cfenet_end, /* netif_end */ 761.1Scgd cfenet_ifs, /* netif_ifs */ 771.2Sdrochner NCFENET_IFS /* netif_nifs */ 781.1Scgd}; 791.1Scgd 801.1Scgdint 811.1Scgdcfenet_match(nif, machdep_hint) 821.1Scgd struct netif *nif; 831.1Scgd void *machdep_hint; 841.1Scgd{ 851.1Scgd 861.1Scgd return (1); 871.1Scgd} 881.1Scgd 891.1Scgdint 901.1Scgdcfenet_probe(nif, machdep_hint) 911.1Scgd struct netif *nif; 921.1Scgd void *machdep_hint; 931.1Scgd{ 941.1Scgd 951.1Scgd return 0; 961.1Scgd} 971.1Scgd 981.1Scgdint 991.1Scgdcfenet_put(desc, pkt, len) 1001.1Scgd struct iodesc *desc; 1011.1Scgd void *pkt; 1021.1Scgd size_t len; 1031.1Scgd{ 1041.1Scgd 1051.1Scgd cfe_write(booted_dev_fd,pkt,len); 1061.1Scgd 1071.1Scgd return len; 1081.1Scgd} 1091.1Scgd 1101.1Scgd 1111.1Scgdint 1121.1Scgdcfenet_get(desc, pkt, len, timeout) 1131.1Scgd struct iodesc *desc; 1141.1Scgd void *pkt; 1151.1Scgd size_t len; 1161.1Scgd time_t timeout; 1171.1Scgd{ 1181.1Scgd time_t t; 1191.1Scgd int cc; 1201.1Scgd 1211.1Scgd t = getsecs(); 1221.1Scgd cc = 0; 1231.1Scgd while (((getsecs() - t) < timeout) && !cc) { 1241.1Scgd cc = cfe_read(booted_dev_fd,pkt,len); 1251.1Scgd if (cc < 0) break; 1261.1Scgd break; 1271.1Scgd } 1281.1Scgd 1291.1Scgd return cc; 1301.1Scgd} 1311.1Scgd 1321.1Scgdvoid 1331.1Scgdcfenet_init(desc, machdep_hint) 1341.1Scgd struct iodesc *desc; 1351.1Scgd void *machdep_hint; 1361.1Scgd{ 1371.1Scgd u_int8_t eaddr[6]; 1381.1Scgd int res; 1391.1Scgd 1401.1Scgd res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0); 1411.1Scgd 1421.1Scgd if (res < 0) { 1431.1Scgd printf("boot: boot device name does not contain ethernet address.\n"); 1441.1Scgd goto punt; 1451.1Scgd } 1461.1Scgd 1471.1Scgd bcopy(eaddr,desc->myea,6); 1481.1Scgd 1491.1Scgd printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea)); 1501.1Scgd return; 1511.1Scgd 1521.1Scgdpunt: 1531.1Scgd halt(); 1541.1Scgd 1551.1Scgd} 1561.1Scgd 1571.1Scgdvoid 1581.1Scgdcfenet_end(nif) 1591.1Scgd struct netif *nif; 1601.1Scgd{ 1611.1Scgd 1621.1Scgd /* nothing to do */ 1631.1Scgd} 164