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