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