if_cfe.c revision 1.2
1/* $NetBSD: if_cfe.c,v 1.2 2003/03/13 13:59:11 drochner Exp $ */ 2 3/* 4 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. 5 * Copyright (c) 1993 Adam Glass 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Adam Glass. 19 * 4. The name of the Author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#include <sys/param.h> 36#include <sys/types.h> 37 38#include <netinet/in.h> 39#include <netinet/in_systm.h> 40 41#include <lib/libsa/stand.h> 42#include <lib/libsa/net.h> 43#include <lib/libsa/netif.h> 44#include <lib/libkern/libkern.h> 45 46#include "stand/common/common.h" 47#include "stand/common/bbinfo.h" 48#include "stand/common/cfe_api.h" 49#include "stand/common/cfe_ioctl.h" 50 51int cfenet_probe(struct netif *, void *); 52int cfenet_match(struct netif *, void *); 53void cfenet_init(struct iodesc *, void *); 54int cfenet_get(struct iodesc *, void *, size_t, time_t); 55int cfenet_put(struct iodesc *, void *, size_t); 56void cfenet_end(struct netif *); 57 58extern struct netif_stats cfenet_stats[]; 59 60struct netif_dif cfenet_ifs[] = { 61/* dif_unit dif_nsel dif_stats dif_private */ 62{ 0, 1, &cfenet_stats[0], 0, }, 63}; 64#define NCFENET_IFS (sizeof(cfenet_ifs) / sizeof(cfenet_ifs[0])) 65 66struct netif_stats cfenet_stats[NCFENET_IFS]; 67 68struct netif_driver prom_netif_driver = { 69 "cfe", /* netif_bname */ 70 cfenet_match, /* netif_match */ 71 cfenet_probe, /* netif_probe */ 72 cfenet_init, /* netif_init */ 73 cfenet_get, /* netif_get */ 74 cfenet_put, /* netif_put */ 75 cfenet_end, /* netif_end */ 76 cfenet_ifs, /* netif_ifs */ 77 NCFENET_IFS /* netif_nifs */ 78}; 79 80int 81cfenet_match(nif, machdep_hint) 82 struct netif *nif; 83 void *machdep_hint; 84{ 85 86 return (1); 87} 88 89int 90cfenet_probe(nif, machdep_hint) 91 struct netif *nif; 92 void *machdep_hint; 93{ 94 95 return 0; 96} 97 98int 99cfenet_put(desc, pkt, len) 100 struct iodesc *desc; 101 void *pkt; 102 size_t len; 103{ 104 105 cfe_write(booted_dev_fd,pkt,len); 106 107 return len; 108} 109 110 111int 112cfenet_get(desc, pkt, len, timeout) 113 struct iodesc *desc; 114 void *pkt; 115 size_t len; 116 time_t timeout; 117{ 118 time_t t; 119 int cc; 120 121 t = getsecs(); 122 cc = 0; 123 while (((getsecs() - t) < timeout) && !cc) { 124 cc = cfe_read(booted_dev_fd,pkt,len); 125 if (cc < 0) break; 126 break; 127 } 128 129 return cc; 130} 131 132void 133cfenet_init(desc, machdep_hint) 134 struct iodesc *desc; 135 void *machdep_hint; 136{ 137 u_int8_t eaddr[6]; 138 int res; 139 140 res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0); 141 142 if (res < 0) { 143 printf("boot: boot device name does not contain ethernet address.\n"); 144 goto punt; 145 } 146 147 bcopy(eaddr,desc->myea,6); 148 149 printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea)); 150 return; 151 152punt: 153 halt(); 154 155} 156 157void 158cfenet_end(nif) 159 struct netif *nif; 160{ 161 162 /* nothing to do */ 163} 164