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