Home | History | Annotate | Line # | Download | only in boot
nif_tlp.c revision 1.1
      1 /*	$NetBSD: nif_tlp.c,v 1.1 2007/10/30 15:07:08 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  * 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 <sys/param.h>
     40 #include <sys/socket.h>
     41 
     42 #include <lib/libsa/stand.h>
     43 #include <lib/libkern/libkern.h>
     44 
     45 #include <sys/socket.h>
     46 #include <net/if.h>
     47 #include <netinet/in.h>
     48 #include <netinet/in_systm.h>
     49 
     50 #include <lib/libsa/net.h>
     51 #include <lib/libsa/netif.h>
     52 #include <lib/libsa/dev_net.h>
     53 
     54 #include "boot.h"
     55 
     56 static int tlp_match(struct netif *, void *);
     57 static int tlp_probe(struct netif *, void *);
     58 static void tlp_attach(struct iodesc *, void *);
     59 static int tlp_get(struct iodesc *, void *, size_t, time_t);
     60 static int tlp_put(struct iodesc *, void *, size_t);
     61 static void tlp_end(struct netif *);
     62 
     63 #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
     64 
     65 static struct netif_stats tlp_stats[1];
     66 
     67 static struct netif_dif tlp_ifs[] = {
     68 	{ 0, 1, &tlp_stats[0], NULL, 0 },
     69 };
     70 
     71 struct netif_driver ether_tlp_driver = {
     72 	"tlp",
     73 	tlp_match,
     74 	tlp_probe,
     75 	tlp_attach,
     76 	tlp_get,
     77 	tlp_put,
     78 	tlp_end,
     79 	tlp_ifs,
     80 	1,
     81 };
     82 
     83 #ifdef DEBUG
     84 int debug = 1;		/* referred in various libsa net sources */
     85 #endif
     86 
     87 int
     88 tlp_match(struct netif *netif, void *hint)
     89 {
     90 
     91 	/* always match for onboard tlp */
     92 	return 1;
     93 }
     94 
     95 int
     96 tlp_probe(struct netif *netif, void *hint)
     97 {
     98 
     99 	/* XXX */
    100 	return 0;
    101 }
    102 
    103 void
    104 tlp_attach(struct iodesc *desc, void *hint)
    105 {
    106 	struct netif *nif = desc->io_netif;
    107 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    108 
    109 	dif->dif_private = tlp_init(&desc->myea);
    110 }
    111 
    112 int
    113 tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    114 {
    115 	int len;
    116 	struct netif *nif = desc->io_netif;
    117 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    118 	void *l = dif->dif_private;
    119 
    120 	len = tlp_recv(l, pkt, maxlen, timeout);
    121 	if (len == -1) {
    122 		printf("tlp: receive timeout\n");
    123 		/* XXX */
    124 	}
    125 
    126 	if (len < MIN_LEN)
    127 		len = -1;
    128 
    129 	return len;
    130 }
    131 
    132 int
    133 tlp_put(struct iodesc *desc, void *pkt, size_t len)
    134 {
    135 	struct netif *nif = desc->io_netif;
    136 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    137 	void *l = dif->dif_private;
    138 	int rv;
    139 	size_t sendlen;
    140 
    141 	sendlen = len;
    142 	if (sendlen < MIN_LEN)
    143 		sendlen = MIN_LEN;	/* XXX */
    144 
    145 	rv = tlp_send(l, pkt, sendlen);
    146 
    147 	return rv;
    148 }
    149 
    150 void
    151 tlp_end(struct netif *netif)
    152 {
    153 }
    154