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