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