1 /* $NetBSD: ether_if.c,v 1.2 2007/02/21 22:59:42 thorpej 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <lib/libsa/stand.h> 40 #include <lib/libkern/libkern.h> 41 42 #include <sys/socket.h> 43 #include <net/if.h> 44 #include <netinet/in.h> 45 #include <netinet/in_systm.h> 46 47 #include <lib/libsa/net.h> 48 #include <lib/libsa/netif.h> 49 #include <lib/libsa/bootp.h> 50 #include <lib/libsa/dev_net.h> 51 52 #include <machine/sbd.h> 53 #define _SBD_TR2A_PRIVATE 54 #include <machine/sbd_tr2a.h> /* getsecs. */ 55 56 #include "local.h" 57 58 struct devsw netdevsw = { 59 "net", net_strategy, net_open, net_close, net_ioctl 60 }; 61 62 int ether_match(struct netif *, void *); 63 int ether_probe(struct netif *, void *); 64 void ether_init(struct iodesc *, void *); 65 int ether_get(struct iodesc *, void *, size_t, time_t); 66 int ether_put(struct iodesc *, void *, size_t); 67 void ether_end(struct netif *); 68 69 extern bool lance_init(void); 70 extern void lance_eaddr(uint8_t *); 71 extern bool lance_get(void *, size_t); 72 extern bool lance_put(void *, size_t); 73 74 struct netif_stats ether_stats[1]; 75 76 struct netif_dif ether_ifs[] = { 77 { 0, 1, ðer_stats[0], 0, }, 78 }; 79 80 struct netif_driver __netif_driver = { 81 "ether", 82 ether_match, 83 ether_probe, 84 ether_init, 85 ether_get, 86 ether_put, 87 ether_end, 88 ether_ifs, 89 1, 90 }; 91 92 int debug = 1; 93 int n_netif_drivers = 1; 94 struct netif_driver *netif_drivers[1] = { &__netif_driver }; 95 96 int 97 ether_match(struct netif *netif, void *hint) 98 { 99 100 return SBD_INFO->machine == MACHINE_TR2A; 101 } 102 103 int 104 ether_probe(struct netif *netif, void *hint) 105 { 106 107 return 0; 108 } 109 110 void 111 ether_init(struct iodesc *iodesc, void *hint) 112 { 113 114 lance_init(); 115 lance_eaddr(iodesc->myea); 116 } 117 118 int 119 ether_get(struct iodesc *iodesc, void *pkt, size_t len, time_t timeout) 120 { 121 122 return lance_get(pkt, len) ? len : -1; 123 } 124 125 int 126 ether_put(struct iodesc *iodesc, void *pkt, size_t len) 127 { 128 129 return lance_put(pkt, len) ? len : -1; 130 } 131 132 void 133 ether_end(struct netif *netif) 134 { 135 136 } 137 138 void 139 _rtt(void) 140 { 141 142 while (/*CONSTCOND*/1) 143 ; 144 /* NOTREACHED */ 145 } 146 147 time_t 148 getsecs(void) 149 { 150 151 return (time_t)*(RTC_MK48T18_ADDR + 4); 152 } 153