Home | History | Annotate | Line # | Download | only in boot
if_ne.c revision 1.1.2.2
      1 /* $NetBSD: if_ne.c,v 1.1.2.2 2012/10/30 17:20:31 yamt Exp $ */
      2 /* Id: if_ne.c,v 1.28 2011/10/05 13:17:06 isaki Exp  */
      3 
      4 /*
      5  * Copyright (c) 2003 Tetsuya Isaki. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/systm.h>
     31 
     32 #include <net/if.h>
     33 #include <net/if_ether.h>
     34 #include <netinet/in.h>
     35 #include <netinet/in_systm.h>
     36 
     37 #include <lib/libsa/stand.h>
     38 #include <lib/libsa/net.h>
     39 #include <lib/libsa/netif.h>
     40 
     41 #include "ne.h"
     42 #include "dp8390.h"
     43 
     44 extern int badbaddr(void *);
     45 
     46 static int  ne_match(struct netif *, void *);
     47 static int  ne_probe(struct netif *, void *);
     48 static void ne_init(struct iodesc *, void *);
     49 static int  ne_get(struct iodesc *, void *, size_t, saseconds_t);
     50 static int  ne_put(struct iodesc *, void *, size_t);
     51 static void ne_end(struct netif *);
     52 
     53 uint neaddr_conf[] = {
     54 	0xece200,	/* Neptune-X at ISA addr 0x300 */
     55 	0xece300,	/* Nereid #1 */
     56 	0xeceb00,	/* Nereid #2 */
     57 };
     58 uint neaddr;
     59 
     60 
     61 static int
     62 ne_match(struct netif *nif, void *machdep_hint)
     63 {
     64 	int i;
     65 
     66 	for (i = 0; i < sizeof(neaddr_conf) / sizeof(neaddr_conf[0]); i++) {
     67 		if (!badbaddr((void *)neaddr_conf[i])) {
     68 			neaddr = neaddr_conf[i];
     69 			return 1;
     70 		}
     71 	}
     72 	printf("ne_match: no match\n");
     73 	return 0;
     74 }
     75 
     76 static int
     77 ne_probe(struct netif *nif, void *machdep_hint)
     78 {
     79 
     80 	return 0;
     81 }
     82 
     83 static void
     84 ne_init(struct iodesc *desc, void *machdep_hint)
     85 {
     86 
     87 #ifdef DEBUG
     88 	printf("ne_init\n");
     89 #endif
     90 	if (EtherInit(desc->myea) == 0) {
     91 		printf("EtherInit failed?\n");
     92 		exit(1);
     93 	}
     94 
     95 	printf("ethernet address = %s\n", ether_sprintf(desc->myea));
     96 }
     97 
     98 static int
     99 ne_get(struct iodesc *desc, void *pkt, size_t maxlen, saseconds_t timeout)
    100 {
    101 	int len = 0;
    102 	saseconds_t t;
    103 
    104 	t = getsecs() + timeout;
    105 	while (getsecs() < t) {
    106 		len = EtherReceive(pkt, maxlen);
    107 		if (len)
    108 			break;
    109 	}
    110 
    111 	return len;
    112 }
    113 
    114 static int
    115 ne_put(struct iodesc *desc, void *pkt, size_t len)
    116 {
    117 #ifdef DEBUG
    118  	struct ether_header *eh;
    119 
    120  	eh = pkt;
    121  	printf("dst:  %s\n", ether_sprintf(eh->ether_dhost));
    122  	printf("src:  %s\n", ether_sprintf(eh->ether_shost));
    123  	printf("type: 0x%x\n", eh->ether_type & 0xffff);
    124 #endif
    125 
    126 	return EtherSend(pkt, len);
    127 }
    128 
    129 static void
    130 ne_end(struct netif *nif)
    131 {
    132 
    133 #ifdef DEBUG
    134 	printf("ne_end\n");
    135 #endif
    136 
    137 	EtherStop();
    138 }
    139 
    140 
    141 struct netif_stats ne_stats;
    142 struct netif_dif ne_ifs[] = {
    143 	{ 0, 1, &ne_stats, 0, 0, },
    144 };
    145 
    146 struct netif_driver ne_netif_driver = {
    147 	"ne",
    148 	ne_match,
    149 	ne_probe,
    150 	ne_init,
    151 	ne_get,
    152 	ne_put,
    153 	ne_end,
    154 	ne_ifs,
    155 	sizeof(ne_ifs) / sizeof(ne_ifs[0]),
    156 };
    157