1 /* $NetBSD: ether_if.c,v 1.6 2014/11/21 00:53:19 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <lib/libsa/stand.h>
33 #include <lib/libkern/libkern.h>
34
35 #include <sys/socket.h>
36 #include <net/if.h>
37 #include <netinet/in.h>
38 #include <netinet/in_systm.h>
39
40 #include <lib/libsa/net.h>
41 #include <lib/libsa/netif.h>
42 #include <lib/libsa/bootp.h>
43 #include <lib/libsa/dev_net.h>
44
45 #include <dev/clock_subr.h>
46
47 #include <machine/sbd.h>
48 #define _SBD_TR2A_PRIVATE
49 #include <machine/sbd_tr2a.h> /* getsecs. */
50
51 #include "local.h"
52
53 struct devsw netdevsw = {
54 "net", net_strategy, net_open, net_close, net_ioctl
55 };
56
57 int ether_match(struct netif *, void *);
58 int ether_probe(struct netif *, void *);
59 void ether_init(struct iodesc *, void *);
60 int ether_get(struct iodesc *, void *, size_t, saseconds_t);
61 int ether_put(struct iodesc *, void *, size_t);
62 void ether_end(struct netif *);
63
64 extern bool lance_init(void);
65 extern void lance_eaddr(uint8_t *);
66 extern bool lance_get(void *, size_t);
67 extern bool lance_put(void *, size_t);
68
69 struct netif_stats ether_stats[1];
70
71 struct netif_dif ether_ifs[] = {
72 { 0, 1, ðer_stats[0], 0, },
73 };
74
75 struct netif_driver __netif_driver = {
76 "ether",
77 ether_match,
78 ether_probe,
79 ether_init,
80 ether_get,
81 ether_put,
82 ether_end,
83 ether_ifs,
84 1,
85 };
86
87 int debug = 1;
88 int n_netif_drivers = 1;
89 struct netif_driver *netif_drivers[1] = { &__netif_driver };
90
91 int
ether_match(struct netif * netif,void * hint)92 ether_match(struct netif *netif, void *hint)
93 {
94
95 return SBD_INFO->machine == MACHINE_TR2A;
96 }
97
98 int
ether_probe(struct netif * netif,void * hint)99 ether_probe(struct netif *netif, void *hint)
100 {
101
102 return 0;
103 }
104
105 void
ether_init(struct iodesc * iodesc,void * hint)106 ether_init(struct iodesc *iodesc, void *hint)
107 {
108
109 lance_init();
110 lance_eaddr(iodesc->myea);
111 }
112
113 int
ether_get(struct iodesc * iodesc,void * pkt,size_t len,saseconds_t timeout)114 ether_get(struct iodesc *iodesc, void *pkt, size_t len, saseconds_t timeout)
115 {
116
117 return lance_get(pkt, len) ? len : -1;
118 }
119
120 int
ether_put(struct iodesc * iodesc,void * pkt,size_t len)121 ether_put(struct iodesc *iodesc, void *pkt, size_t len)
122 {
123
124 return lance_put(pkt, len) ? len : -1;
125 }
126
127 void
ether_end(struct netif * netif)128 ether_end(struct netif *netif)
129 {
130
131 }
132
133 void
_rtt(void)134 _rtt(void)
135 {
136
137 while (/*CONSTCOND*/1)
138 ;
139 /* NOTREACHED */
140 }
141
142 satime_t
getsecs(void)143 getsecs(void)
144 {
145 volatile uint8_t *mkclock;
146 u_int t;
147
148 mkclock = RTC_MK48T18_ADDR;
149 t = bcdtobin(*(mkclock + 4));
150 t += bcdtobin(*(mkclock + 8)) * 60;
151 t += bcdtobin(*(mkclock + 12)) * 60 * 60;
152
153 return (satime_t)t;
154 }
155