Home | History | Annotate | Line # | Download | only in common
ether_if.c revision 1.5
      1 /*	$NetBSD: ether_if.c,v 1.5 2009/01/12 11:32:43 tsutsui 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 <machine/sbd.h>
     46 #define	_SBD_TR2A_PRIVATE
     47 #include <machine/sbd_tr2a.h>	/* getsecs. */
     48 
     49 #include "local.h"
     50 
     51 struct devsw netdevsw = {
     52 	"net", net_strategy, net_open, net_close, net_ioctl
     53 };
     54 
     55 int ether_match(struct netif *, void *);
     56 int ether_probe(struct netif *, void *);
     57 void ether_init(struct iodesc *, void *);
     58 int ether_get(struct iodesc *, void *, size_t, saseconds_t);
     59 int ether_put(struct iodesc *, void *, size_t);
     60 void ether_end(struct netif *);
     61 
     62 extern bool lance_init(void);
     63 extern void lance_eaddr(uint8_t *);
     64 extern bool lance_get(void *, size_t);
     65 extern bool lance_put(void *, size_t);
     66 
     67 struct netif_stats ether_stats[1];
     68 
     69 struct netif_dif ether_ifs[] = {
     70 	{ 0, 1, &ether_stats[0], 0, },
     71 };
     72 
     73 struct netif_driver __netif_driver = {
     74 	"ether",
     75 	ether_match,
     76 	ether_probe,
     77 	ether_init,
     78 	ether_get,
     79 	ether_put,
     80 	ether_end,
     81 	ether_ifs,
     82 	1,
     83 };
     84 
     85 int debug = 1;
     86 int n_netif_drivers = 1;
     87 struct netif_driver *netif_drivers[1] = { &__netif_driver };
     88 
     89 int
     90 ether_match(struct netif *netif, void *hint)
     91 {
     92 
     93 	return SBD_INFO->machine == MACHINE_TR2A;
     94 }
     95 
     96 int
     97 ether_probe(struct netif *netif, void *hint)
     98 {
     99 
    100 	return 0;
    101 }
    102 
    103 void
    104 ether_init(struct iodesc *iodesc, void *hint)
    105 {
    106 
    107 	lance_init();
    108 	lance_eaddr(iodesc->myea);
    109 }
    110 
    111 int
    112 ether_get(struct iodesc *iodesc, void *pkt, size_t len, saseconds_t timeout)
    113 {
    114 
    115 	return lance_get(pkt, len) ? len : -1;
    116 }
    117 
    118 int
    119 ether_put(struct iodesc *iodesc, void *pkt, size_t len)
    120 {
    121 
    122 	return lance_put(pkt, len) ? len : -1;
    123 }
    124 
    125 void
    126 ether_end(struct netif *netif)
    127 {
    128 
    129 }
    130 
    131 void
    132 _rtt(void)
    133 {
    134 
    135 	while (/*CONSTCOND*/1)
    136 		;
    137 	/* NOTREACHED */
    138 }
    139 
    140 satime_t
    141 getsecs(void)
    142 {
    143 	volatile uint8_t *mkclock;
    144 	u_int t;
    145 
    146 	mkclock = RTC_MK48T18_ADDR;
    147 	t =  bcdtobin(*(mkclock +  4));
    148 	t += bcdtobin(*(mkclock +  8)) * 60;
    149 	t += bcdtobin(*(mkclock + 12)) * 60 * 60;
    150 
    151 	return (satime_t)t;
    152 }
    153