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