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