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