Home | History | Annotate | Line # | Download | only in netboot
      1 /* $NetBSD: if_cfe.c,v 1.2 2017/07/24 10:34:55 mrg 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/sbmips/common/common.h"
     47 #include "stand/sbmips/common/bbinfo.h"
     48 #include "stand/sbmips/common/cfe_api.h"
     49 #include "stand/sbmips/common/cfe_ioctl.h"
     50 
     51 int cfenet_probe(struct netif *, void *);
     52 int cfenet_match(struct netif *, void *);
     53 void cfenet_init(struct iodesc *, void *);
     54 int cfenet_get(struct iodesc *, void *, size_t, saseconds_t);
     55 int cfenet_put(struct iodesc *, void *, size_t);
     56 void cfenet_end(struct netif *);
     57 
     58 extern struct netif_stats	cfenet_stats[];
     59 
     60 struct 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 
     66 struct netif_stats cfenet_stats[NCFENET_IFS];
     67 
     68 struct 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 
     80 int
     81 cfenet_match(struct netif *nif, void *machdep_hint)
     82 {
     83 
     84 	return (1);
     85 }
     86 
     87 int
     88 cfenet_probe(struct netif *nif, void *machdep_hint)
     89 {
     90 
     91 	return 0;
     92 }
     93 
     94 int
     95 cfenet_put(struct iodesc *desc, void *pkt, size_t len)
     96 {
     97 
     98     cfe_write(booted_dev_fd,pkt,len);
     99 
    100     return len;
    101 }
    102 
    103 
    104 int
    105 cfenet_get(struct iodesc *desc, void *pkt, size_t len, saseconds_t timeout)
    106 {
    107 	satime_t t;
    108 	int cc;
    109 
    110 	t = getsecs();
    111 	cc = 0;
    112 	while (((getsecs() - t) < timeout) && !cc) {
    113 	    cc = cfe_read(booted_dev_fd,pkt,len);
    114 	    if (cc < 0) break;
    115 	    break;
    116 	}
    117 
    118 	return cc;
    119 }
    120 
    121 void
    122 cfenet_init(struct iodesc *desc, void *machdep_hint)
    123 {
    124 	u_int8_t eaddr[6];
    125 	int res;
    126 
    127 	res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0);
    128 
    129 	if (res < 0) {
    130 	    printf("boot: boot device name does not contain ethernet address.\n");
    131 	    goto punt;
    132 	    }
    133 
    134 	memcpy(desc->myea, eaddr,6);
    135 
    136 	printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
    137 	return;
    138 
    139 punt:
    140 	halt();
    141 
    142 }
    143 
    144 void
    145 cfenet_end(struct netif *nif)
    146 {
    147 
    148 	/* nothing to do */
    149 }
    150