Home | History | Annotate | Line # | Download | only in boot
nif_tlp.c revision 1.1.14.2
      1 /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad 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 /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad Exp $	*/
    155 
    156 /*-
    157  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    158  * All rights reserved.
    159  *
    160  * This code is derived from software contributed to The NetBSD Foundation
    161  * by UCHIYAMA Yasushi.
    162  *
    163  * Redistribution and use in source and binary forms, with or without
    164  * modification, are permitted provided that the following conditions
    165  * are met:
    166  * 1. Redistributions of source code must retain the above copyright
    167  *    notice, this list of conditions and the following disclaimer.
    168  * 2. Redistributions in binary form must reproduce the above copyright
    169  *    notice, this list of conditions and the following disclaimer in the
    170  *    documentation and/or other materials provided with the distribution.
    171  * 3. All advertising materials mentioning features or use of this software
    172  *    must display the following acknowledgement:
    173  *        This product includes software developed by the NetBSD
    174  *        Foundation, Inc. and its contributors.
    175  * 4. Neither the name of The NetBSD Foundation nor the names of its
    176  *    contributors may be used to endorse or promote products derived
    177  *    from this software without specific prior written permission.
    178  *
    179  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
    180  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    181  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    182  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
    183  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    184  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    185  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    186  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    187  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    188  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    189  * POSSIBILITY OF SUCH DAMAGE.
    190  */
    191 
    192 #include <sys/param.h>
    193 #include <sys/socket.h>
    194 
    195 #include <lib/libsa/stand.h>
    196 #include <lib/libkern/libkern.h>
    197 
    198 #include <sys/socket.h>
    199 #include <net/if.h>
    200 #include <netinet/in.h>
    201 #include <netinet/in_systm.h>
    202 
    203 #include <lib/libsa/net.h>
    204 #include <lib/libsa/netif.h>
    205 #include <lib/libsa/dev_net.h>
    206 
    207 #include "boot.h"
    208 
    209 static int tlp_match(struct netif *, void *);
    210 static int tlp_probe(struct netif *, void *);
    211 static void tlp_attach(struct iodesc *, void *);
    212 static int tlp_get(struct iodesc *, void *, size_t, time_t);
    213 static int tlp_put(struct iodesc *, void *, size_t);
    214 static void tlp_end(struct netif *);
    215 
    216 #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
    217 
    218 static struct netif_stats tlp_stats[1];
    219 
    220 static struct netif_dif tlp_ifs[] = {
    221 	{ 0, 1, &tlp_stats[0], NULL, 0 },
    222 };
    223 
    224 struct netif_driver ether_tlp_driver = {
    225 	"tlp",
    226 	tlp_match,
    227 	tlp_probe,
    228 	tlp_attach,
    229 	tlp_get,
    230 	tlp_put,
    231 	tlp_end,
    232 	tlp_ifs,
    233 	1,
    234 };
    235 
    236 #ifdef DEBUG
    237 int debug = 1;		/* referred in various libsa net sources */
    238 #endif
    239 
    240 int
    241 tlp_match(struct netif *netif, void *hint)
    242 {
    243 
    244 	/* always match for onboard tlp */
    245 	return 1;
    246 }
    247 
    248 int
    249 tlp_probe(struct netif *netif, void *hint)
    250 {
    251 
    252 	/* XXX */
    253 	return 0;
    254 }
    255 
    256 void
    257 tlp_attach(struct iodesc *desc, void *hint)
    258 {
    259 	struct netif *nif = desc->io_netif;
    260 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    261 
    262 	dif->dif_private = tlp_init(&desc->myea);
    263 }
    264 
    265 int
    266 tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    267 {
    268 	int len;
    269 	struct netif *nif = desc->io_netif;
    270 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    271 	void *l = dif->dif_private;
    272 
    273 	len = tlp_recv(l, pkt, maxlen, timeout);
    274 	if (len == -1) {
    275 		printf("tlp: receive timeout\n");
    276 		/* XXX */
    277 	}
    278 
    279 	if (len < MIN_LEN)
    280 		len = -1;
    281 
    282 	return len;
    283 }
    284 
    285 int
    286 tlp_put(struct iodesc *desc, void *pkt, size_t len)
    287 {
    288 	struct netif *nif = desc->io_netif;
    289 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    290 	void *l = dif->dif_private;
    291 	int rv;
    292 	size_t sendlen;
    293 
    294 	sendlen = len;
    295 	if (sendlen < MIN_LEN)
    296 		sendlen = MIN_LEN;	/* XXX */
    297 
    298 	rv = tlp_send(l, pkt, sendlen);
    299 
    300 	return rv;
    301 }
    302 
    303 void
    304 tlp_end(struct netif *netif)
    305 {
    306 }
    307 /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad Exp $	*/
    308 
    309 /*-
    310  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    311  * All rights reserved.
    312  *
    313  * This code is derived from software contributed to The NetBSD Foundation
    314  * by UCHIYAMA Yasushi.
    315  *
    316  * Redistribution and use in source and binary forms, with or without
    317  * modification, are permitted provided that the following conditions
    318  * are met:
    319  * 1. Redistributions of source code must retain the above copyright
    320  *    notice, this list of conditions and the following disclaimer.
    321  * 2. Redistributions in binary form must reproduce the above copyright
    322  *    notice, this list of conditions and the following disclaimer in the
    323  *    documentation and/or other materials provided with the distribution.
    324  * 3. All advertising materials mentioning features or use of this software
    325  *    must display the following acknowledgement:
    326  *        This product includes software developed by the NetBSD
    327  *        Foundation, Inc. and its contributors.
    328  * 4. Neither the name of The NetBSD Foundation nor the names of its
    329  *    contributors may be used to endorse or promote products derived
    330  *    from this software without specific prior written permission.
    331  *
    332  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
    333  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    334  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    335  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
    336  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    337  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    338  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    339  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    340  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    341  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    342  * POSSIBILITY OF SUCH DAMAGE.
    343  */
    344 
    345 #include <sys/param.h>
    346 #include <sys/socket.h>
    347 
    348 #include <lib/libsa/stand.h>
    349 #include <lib/libkern/libkern.h>
    350 
    351 #include <sys/socket.h>
    352 #include <net/if.h>
    353 #include <netinet/in.h>
    354 #include <netinet/in_systm.h>
    355 
    356 #include <lib/libsa/net.h>
    357 #include <lib/libsa/netif.h>
    358 #include <lib/libsa/dev_net.h>
    359 
    360 #include "boot.h"
    361 
    362 static int tlp_match(struct netif *, void *);
    363 static int tlp_probe(struct netif *, void *);
    364 static void tlp_attach(struct iodesc *, void *);
    365 static int tlp_get(struct iodesc *, void *, size_t, time_t);
    366 static int tlp_put(struct iodesc *, void *, size_t);
    367 static void tlp_end(struct netif *);
    368 
    369 #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
    370 
    371 static struct netif_stats tlp_stats[1];
    372 
    373 static struct netif_dif tlp_ifs[] = {
    374 	{ 0, 1, &tlp_stats[0], NULL, 0 },
    375 };
    376 
    377 struct netif_driver ether_tlp_driver = {
    378 	"tlp",
    379 	tlp_match,
    380 	tlp_probe,
    381 	tlp_attach,
    382 	tlp_get,
    383 	tlp_put,
    384 	tlp_end,
    385 	tlp_ifs,
    386 	1,
    387 };
    388 
    389 #ifdef DEBUG
    390 int debug = 1;		/* referred in various libsa net sources */
    391 #endif
    392 
    393 int
    394 tlp_match(struct netif *netif, void *hint)
    395 {
    396 
    397 	/* always match for onboard tlp */
    398 	return 1;
    399 }
    400 
    401 int
    402 tlp_probe(struct netif *netif, void *hint)
    403 {
    404 
    405 	/* XXX */
    406 	return 0;
    407 }
    408 
    409 void
    410 tlp_attach(struct iodesc *desc, void *hint)
    411 {
    412 	struct netif *nif = desc->io_netif;
    413 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    414 
    415 	dif->dif_private = tlp_init(&desc->myea);
    416 }
    417 
    418 int
    419 tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    420 {
    421 	int len;
    422 	struct netif *nif = desc->io_netif;
    423 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    424 	void *l = dif->dif_private;
    425 
    426 	len = tlp_recv(l, pkt, maxlen, timeout);
    427 	if (len == -1) {
    428 		printf("tlp: receive timeout\n");
    429 		/* XXX */
    430 	}
    431 
    432 	if (len < MIN_LEN)
    433 		len = -1;
    434 
    435 	return len;
    436 }
    437 
    438 int
    439 tlp_put(struct iodesc *desc, void *pkt, size_t len)
    440 {
    441 	struct netif *nif = desc->io_netif;
    442 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    443 	void *l = dif->dif_private;
    444 	int rv;
    445 	size_t sendlen;
    446 
    447 	sendlen = len;
    448 	if (sendlen < MIN_LEN)
    449 		sendlen = MIN_LEN;	/* XXX */
    450 
    451 	rv = tlp_send(l, pkt, sendlen);
    452 
    453 	return rv;
    454 }
    455 
    456 void
    457 tlp_end(struct netif *netif)
    458 {
    459 }
    460