Home | History | Annotate | Line # | Download | only in boot
nif_tlp.c revision 1.1.14.2
      1  1.1.14.2  ad /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad Exp $	*/
      2  1.1.14.2  ad 
      3  1.1.14.2  ad /*-
      4  1.1.14.2  ad  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  1.1.14.2  ad  * All rights reserved.
      6  1.1.14.2  ad  *
      7  1.1.14.2  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.14.2  ad  * by UCHIYAMA Yasushi.
      9  1.1.14.2  ad  *
     10  1.1.14.2  ad  * Redistribution and use in source and binary forms, with or without
     11  1.1.14.2  ad  * modification, are permitted provided that the following conditions
     12  1.1.14.2  ad  * are met:
     13  1.1.14.2  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.1.14.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.14.2  ad  *    documentation and/or other materials provided with the distribution.
     18  1.1.14.2  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.1.14.2  ad  *    must display the following acknowledgement:
     20  1.1.14.2  ad  *        This product includes software developed by the NetBSD
     21  1.1.14.2  ad  *        Foundation, Inc. and its contributors.
     22  1.1.14.2  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.14.2  ad  *    contributors may be used to endorse or promote products derived
     24  1.1.14.2  ad  *    from this software without specific prior written permission.
     25  1.1.14.2  ad  *
     26  1.1.14.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.14.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.14.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.14.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.14.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.14.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.14.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.14.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.14.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.14.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.14.2  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.14.2  ad  */
     38  1.1.14.2  ad 
     39  1.1.14.2  ad #include <sys/param.h>
     40  1.1.14.2  ad #include <sys/socket.h>
     41  1.1.14.2  ad 
     42  1.1.14.2  ad #include <lib/libsa/stand.h>
     43  1.1.14.2  ad #include <lib/libkern/libkern.h>
     44  1.1.14.2  ad 
     45  1.1.14.2  ad #include <sys/socket.h>
     46  1.1.14.2  ad #include <net/if.h>
     47  1.1.14.2  ad #include <netinet/in.h>
     48  1.1.14.2  ad #include <netinet/in_systm.h>
     49  1.1.14.2  ad 
     50  1.1.14.2  ad #include <lib/libsa/net.h>
     51  1.1.14.2  ad #include <lib/libsa/netif.h>
     52  1.1.14.2  ad #include <lib/libsa/dev_net.h>
     53  1.1.14.2  ad 
     54  1.1.14.2  ad #include "boot.h"
     55  1.1.14.2  ad 
     56  1.1.14.2  ad static int tlp_match(struct netif *, void *);
     57  1.1.14.2  ad static int tlp_probe(struct netif *, void *);
     58  1.1.14.2  ad static void tlp_attach(struct iodesc *, void *);
     59  1.1.14.2  ad static int tlp_get(struct iodesc *, void *, size_t, time_t);
     60  1.1.14.2  ad static int tlp_put(struct iodesc *, void *, size_t);
     61  1.1.14.2  ad static void tlp_end(struct netif *);
     62  1.1.14.2  ad 
     63  1.1.14.2  ad #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
     64  1.1.14.2  ad 
     65  1.1.14.2  ad static struct netif_stats tlp_stats[1];
     66  1.1.14.2  ad 
     67  1.1.14.2  ad static struct netif_dif tlp_ifs[] = {
     68  1.1.14.2  ad 	{ 0, 1, &tlp_stats[0], NULL, 0 },
     69  1.1.14.2  ad };
     70  1.1.14.2  ad 
     71  1.1.14.2  ad struct netif_driver ether_tlp_driver = {
     72  1.1.14.2  ad 	"tlp",
     73  1.1.14.2  ad 	tlp_match,
     74  1.1.14.2  ad 	tlp_probe,
     75  1.1.14.2  ad 	tlp_attach,
     76  1.1.14.2  ad 	tlp_get,
     77  1.1.14.2  ad 	tlp_put,
     78  1.1.14.2  ad 	tlp_end,
     79  1.1.14.2  ad 	tlp_ifs,
     80  1.1.14.2  ad 	1,
     81  1.1.14.2  ad };
     82  1.1.14.2  ad 
     83  1.1.14.2  ad #ifdef DEBUG
     84  1.1.14.2  ad int debug = 1;		/* referred in various libsa net sources */
     85  1.1.14.2  ad #endif
     86  1.1.14.2  ad 
     87  1.1.14.2  ad int
     88  1.1.14.2  ad tlp_match(struct netif *netif, void *hint)
     89  1.1.14.2  ad {
     90  1.1.14.2  ad 
     91  1.1.14.2  ad 	/* always match for onboard tlp */
     92  1.1.14.2  ad 	return 1;
     93  1.1.14.2  ad }
     94  1.1.14.2  ad 
     95  1.1.14.2  ad int
     96  1.1.14.2  ad tlp_probe(struct netif *netif, void *hint)
     97  1.1.14.2  ad {
     98  1.1.14.2  ad 
     99  1.1.14.2  ad 	/* XXX */
    100  1.1.14.2  ad 	return 0;
    101  1.1.14.2  ad }
    102  1.1.14.2  ad 
    103  1.1.14.2  ad void
    104  1.1.14.2  ad tlp_attach(struct iodesc *desc, void *hint)
    105  1.1.14.2  ad {
    106  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    107  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    108  1.1.14.2  ad 
    109  1.1.14.2  ad 	dif->dif_private = tlp_init(&desc->myea);
    110  1.1.14.2  ad }
    111  1.1.14.2  ad 
    112  1.1.14.2  ad int
    113  1.1.14.2  ad tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    114  1.1.14.2  ad {
    115  1.1.14.2  ad 	int len;
    116  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    117  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    118  1.1.14.2  ad 	void *l = dif->dif_private;
    119  1.1.14.2  ad 
    120  1.1.14.2  ad 	len = tlp_recv(l, pkt, maxlen, timeout);
    121  1.1.14.2  ad 	if (len == -1) {
    122  1.1.14.2  ad 		printf("tlp: receive timeout\n");
    123  1.1.14.2  ad 		/* XXX */
    124  1.1.14.2  ad 	}
    125  1.1.14.2  ad 
    126  1.1.14.2  ad 	if (len < MIN_LEN)
    127  1.1.14.2  ad 		len = -1;
    128  1.1.14.2  ad 
    129  1.1.14.2  ad 	return len;
    130  1.1.14.2  ad }
    131  1.1.14.2  ad 
    132  1.1.14.2  ad int
    133  1.1.14.2  ad tlp_put(struct iodesc *desc, void *pkt, size_t len)
    134  1.1.14.2  ad {
    135  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    136  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    137  1.1.14.2  ad 	void *l = dif->dif_private;
    138  1.1.14.2  ad 	int rv;
    139  1.1.14.2  ad 	size_t sendlen;
    140  1.1.14.2  ad 
    141  1.1.14.2  ad 	sendlen = len;
    142  1.1.14.2  ad 	if (sendlen < MIN_LEN)
    143  1.1.14.2  ad 		sendlen = MIN_LEN;	/* XXX */
    144  1.1.14.2  ad 
    145  1.1.14.2  ad 	rv = tlp_send(l, pkt, sendlen);
    146  1.1.14.2  ad 
    147  1.1.14.2  ad 	return rv;
    148  1.1.14.2  ad }
    149  1.1.14.2  ad 
    150  1.1.14.2  ad void
    151  1.1.14.2  ad tlp_end(struct netif *netif)
    152  1.1.14.2  ad {
    153  1.1.14.2  ad }
    154  1.1.14.2  ad /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad Exp $	*/
    155  1.1.14.2  ad 
    156  1.1.14.2  ad /*-
    157  1.1.14.2  ad  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    158  1.1.14.2  ad  * All rights reserved.
    159  1.1.14.2  ad  *
    160  1.1.14.2  ad  * This code is derived from software contributed to The NetBSD Foundation
    161  1.1.14.2  ad  * by UCHIYAMA Yasushi.
    162  1.1.14.2  ad  *
    163  1.1.14.2  ad  * Redistribution and use in source and binary forms, with or without
    164  1.1.14.2  ad  * modification, are permitted provided that the following conditions
    165  1.1.14.2  ad  * are met:
    166  1.1.14.2  ad  * 1. Redistributions of source code must retain the above copyright
    167  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer.
    168  1.1.14.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
    169  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer in the
    170  1.1.14.2  ad  *    documentation and/or other materials provided with the distribution.
    171  1.1.14.2  ad  * 3. All advertising materials mentioning features or use of this software
    172  1.1.14.2  ad  *    must display the following acknowledgement:
    173  1.1.14.2  ad  *        This product includes software developed by the NetBSD
    174  1.1.14.2  ad  *        Foundation, Inc. and its contributors.
    175  1.1.14.2  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
    176  1.1.14.2  ad  *    contributors may be used to endorse or promote products derived
    177  1.1.14.2  ad  *    from this software without specific prior written permission.
    178  1.1.14.2  ad  *
    179  1.1.14.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
    180  1.1.14.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    181  1.1.14.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    182  1.1.14.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
    183  1.1.14.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    184  1.1.14.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    185  1.1.14.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    186  1.1.14.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    187  1.1.14.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    188  1.1.14.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    189  1.1.14.2  ad  * POSSIBILITY OF SUCH DAMAGE.
    190  1.1.14.2  ad  */
    191  1.1.14.2  ad 
    192  1.1.14.2  ad #include <sys/param.h>
    193  1.1.14.2  ad #include <sys/socket.h>
    194  1.1.14.2  ad 
    195  1.1.14.2  ad #include <lib/libsa/stand.h>
    196  1.1.14.2  ad #include <lib/libkern/libkern.h>
    197  1.1.14.2  ad 
    198  1.1.14.2  ad #include <sys/socket.h>
    199  1.1.14.2  ad #include <net/if.h>
    200  1.1.14.2  ad #include <netinet/in.h>
    201  1.1.14.2  ad #include <netinet/in_systm.h>
    202  1.1.14.2  ad 
    203  1.1.14.2  ad #include <lib/libsa/net.h>
    204  1.1.14.2  ad #include <lib/libsa/netif.h>
    205  1.1.14.2  ad #include <lib/libsa/dev_net.h>
    206  1.1.14.2  ad 
    207  1.1.14.2  ad #include "boot.h"
    208  1.1.14.2  ad 
    209  1.1.14.2  ad static int tlp_match(struct netif *, void *);
    210  1.1.14.2  ad static int tlp_probe(struct netif *, void *);
    211  1.1.14.2  ad static void tlp_attach(struct iodesc *, void *);
    212  1.1.14.2  ad static int tlp_get(struct iodesc *, void *, size_t, time_t);
    213  1.1.14.2  ad static int tlp_put(struct iodesc *, void *, size_t);
    214  1.1.14.2  ad static void tlp_end(struct netif *);
    215  1.1.14.2  ad 
    216  1.1.14.2  ad #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
    217  1.1.14.2  ad 
    218  1.1.14.2  ad static struct netif_stats tlp_stats[1];
    219  1.1.14.2  ad 
    220  1.1.14.2  ad static struct netif_dif tlp_ifs[] = {
    221  1.1.14.2  ad 	{ 0, 1, &tlp_stats[0], NULL, 0 },
    222  1.1.14.2  ad };
    223  1.1.14.2  ad 
    224  1.1.14.2  ad struct netif_driver ether_tlp_driver = {
    225  1.1.14.2  ad 	"tlp",
    226  1.1.14.2  ad 	tlp_match,
    227  1.1.14.2  ad 	tlp_probe,
    228  1.1.14.2  ad 	tlp_attach,
    229  1.1.14.2  ad 	tlp_get,
    230  1.1.14.2  ad 	tlp_put,
    231  1.1.14.2  ad 	tlp_end,
    232  1.1.14.2  ad 	tlp_ifs,
    233  1.1.14.2  ad 	1,
    234  1.1.14.2  ad };
    235  1.1.14.2  ad 
    236  1.1.14.2  ad #ifdef DEBUG
    237  1.1.14.2  ad int debug = 1;		/* referred in various libsa net sources */
    238  1.1.14.2  ad #endif
    239  1.1.14.2  ad 
    240  1.1.14.2  ad int
    241  1.1.14.2  ad tlp_match(struct netif *netif, void *hint)
    242  1.1.14.2  ad {
    243  1.1.14.2  ad 
    244  1.1.14.2  ad 	/* always match for onboard tlp */
    245  1.1.14.2  ad 	return 1;
    246  1.1.14.2  ad }
    247  1.1.14.2  ad 
    248  1.1.14.2  ad int
    249  1.1.14.2  ad tlp_probe(struct netif *netif, void *hint)
    250  1.1.14.2  ad {
    251  1.1.14.2  ad 
    252  1.1.14.2  ad 	/* XXX */
    253  1.1.14.2  ad 	return 0;
    254  1.1.14.2  ad }
    255  1.1.14.2  ad 
    256  1.1.14.2  ad void
    257  1.1.14.2  ad tlp_attach(struct iodesc *desc, void *hint)
    258  1.1.14.2  ad {
    259  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    260  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    261  1.1.14.2  ad 
    262  1.1.14.2  ad 	dif->dif_private = tlp_init(&desc->myea);
    263  1.1.14.2  ad }
    264  1.1.14.2  ad 
    265  1.1.14.2  ad int
    266  1.1.14.2  ad tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    267  1.1.14.2  ad {
    268  1.1.14.2  ad 	int len;
    269  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    270  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    271  1.1.14.2  ad 	void *l = dif->dif_private;
    272  1.1.14.2  ad 
    273  1.1.14.2  ad 	len = tlp_recv(l, pkt, maxlen, timeout);
    274  1.1.14.2  ad 	if (len == -1) {
    275  1.1.14.2  ad 		printf("tlp: receive timeout\n");
    276  1.1.14.2  ad 		/* XXX */
    277  1.1.14.2  ad 	}
    278  1.1.14.2  ad 
    279  1.1.14.2  ad 	if (len < MIN_LEN)
    280  1.1.14.2  ad 		len = -1;
    281  1.1.14.2  ad 
    282  1.1.14.2  ad 	return len;
    283  1.1.14.2  ad }
    284  1.1.14.2  ad 
    285  1.1.14.2  ad int
    286  1.1.14.2  ad tlp_put(struct iodesc *desc, void *pkt, size_t len)
    287  1.1.14.2  ad {
    288  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    289  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    290  1.1.14.2  ad 	void *l = dif->dif_private;
    291  1.1.14.2  ad 	int rv;
    292  1.1.14.2  ad 	size_t sendlen;
    293  1.1.14.2  ad 
    294  1.1.14.2  ad 	sendlen = len;
    295  1.1.14.2  ad 	if (sendlen < MIN_LEN)
    296  1.1.14.2  ad 		sendlen = MIN_LEN;	/* XXX */
    297  1.1.14.2  ad 
    298  1.1.14.2  ad 	rv = tlp_send(l, pkt, sendlen);
    299  1.1.14.2  ad 
    300  1.1.14.2  ad 	return rv;
    301  1.1.14.2  ad }
    302  1.1.14.2  ad 
    303  1.1.14.2  ad void
    304  1.1.14.2  ad tlp_end(struct netif *netif)
    305  1.1.14.2  ad {
    306  1.1.14.2  ad }
    307  1.1.14.2  ad /*	$NetBSD: nif_tlp.c,v 1.1.14.2 2007/12/03 19:03:10 ad Exp $	*/
    308  1.1.14.2  ad 
    309  1.1.14.2  ad /*-
    310  1.1.14.2  ad  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    311  1.1.14.2  ad  * All rights reserved.
    312  1.1.14.2  ad  *
    313  1.1.14.2  ad  * This code is derived from software contributed to The NetBSD Foundation
    314  1.1.14.2  ad  * by UCHIYAMA Yasushi.
    315  1.1.14.2  ad  *
    316  1.1.14.2  ad  * Redistribution and use in source and binary forms, with or without
    317  1.1.14.2  ad  * modification, are permitted provided that the following conditions
    318  1.1.14.2  ad  * are met:
    319  1.1.14.2  ad  * 1. Redistributions of source code must retain the above copyright
    320  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer.
    321  1.1.14.2  ad  * 2. Redistributions in binary form must reproduce the above copyright
    322  1.1.14.2  ad  *    notice, this list of conditions and the following disclaimer in the
    323  1.1.14.2  ad  *    documentation and/or other materials provided with the distribution.
    324  1.1.14.2  ad  * 3. All advertising materials mentioning features or use of this software
    325  1.1.14.2  ad  *    must display the following acknowledgement:
    326  1.1.14.2  ad  *        This product includes software developed by the NetBSD
    327  1.1.14.2  ad  *        Foundation, Inc. and its contributors.
    328  1.1.14.2  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
    329  1.1.14.2  ad  *    contributors may be used to endorse or promote products derived
    330  1.1.14.2  ad  *    from this software without specific prior written permission.
    331  1.1.14.2  ad  *
    332  1.1.14.2  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
    333  1.1.14.2  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    334  1.1.14.2  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    335  1.1.14.2  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
    336  1.1.14.2  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    337  1.1.14.2  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    338  1.1.14.2  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    339  1.1.14.2  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    340  1.1.14.2  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    341  1.1.14.2  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    342  1.1.14.2  ad  * POSSIBILITY OF SUCH DAMAGE.
    343  1.1.14.2  ad  */
    344  1.1.14.2  ad 
    345  1.1.14.2  ad #include <sys/param.h>
    346  1.1.14.2  ad #include <sys/socket.h>
    347  1.1.14.2  ad 
    348  1.1.14.2  ad #include <lib/libsa/stand.h>
    349  1.1.14.2  ad #include <lib/libkern/libkern.h>
    350  1.1.14.2  ad 
    351  1.1.14.2  ad #include <sys/socket.h>
    352  1.1.14.2  ad #include <net/if.h>
    353  1.1.14.2  ad #include <netinet/in.h>
    354  1.1.14.2  ad #include <netinet/in_systm.h>
    355  1.1.14.2  ad 
    356  1.1.14.2  ad #include <lib/libsa/net.h>
    357  1.1.14.2  ad #include <lib/libsa/netif.h>
    358  1.1.14.2  ad #include <lib/libsa/dev_net.h>
    359  1.1.14.2  ad 
    360  1.1.14.2  ad #include "boot.h"
    361  1.1.14.2  ad 
    362  1.1.14.2  ad static int tlp_match(struct netif *, void *);
    363  1.1.14.2  ad static int tlp_probe(struct netif *, void *);
    364  1.1.14.2  ad static void tlp_attach(struct iodesc *, void *);
    365  1.1.14.2  ad static int tlp_get(struct iodesc *, void *, size_t, time_t);
    366  1.1.14.2  ad static int tlp_put(struct iodesc *, void *, size_t);
    367  1.1.14.2  ad static void tlp_end(struct netif *);
    368  1.1.14.2  ad 
    369  1.1.14.2  ad #define MIN_LEN		60	/* ETHER_MIN_LEN - ETHER_CRC_LEN */
    370  1.1.14.2  ad 
    371  1.1.14.2  ad static struct netif_stats tlp_stats[1];
    372  1.1.14.2  ad 
    373  1.1.14.2  ad static struct netif_dif tlp_ifs[] = {
    374  1.1.14.2  ad 	{ 0, 1, &tlp_stats[0], NULL, 0 },
    375  1.1.14.2  ad };
    376  1.1.14.2  ad 
    377  1.1.14.2  ad struct netif_driver ether_tlp_driver = {
    378  1.1.14.2  ad 	"tlp",
    379  1.1.14.2  ad 	tlp_match,
    380  1.1.14.2  ad 	tlp_probe,
    381  1.1.14.2  ad 	tlp_attach,
    382  1.1.14.2  ad 	tlp_get,
    383  1.1.14.2  ad 	tlp_put,
    384  1.1.14.2  ad 	tlp_end,
    385  1.1.14.2  ad 	tlp_ifs,
    386  1.1.14.2  ad 	1,
    387  1.1.14.2  ad };
    388  1.1.14.2  ad 
    389  1.1.14.2  ad #ifdef DEBUG
    390  1.1.14.2  ad int debug = 1;		/* referred in various libsa net sources */
    391  1.1.14.2  ad #endif
    392  1.1.14.2  ad 
    393  1.1.14.2  ad int
    394  1.1.14.2  ad tlp_match(struct netif *netif, void *hint)
    395  1.1.14.2  ad {
    396  1.1.14.2  ad 
    397  1.1.14.2  ad 	/* always match for onboard tlp */
    398  1.1.14.2  ad 	return 1;
    399  1.1.14.2  ad }
    400  1.1.14.2  ad 
    401  1.1.14.2  ad int
    402  1.1.14.2  ad tlp_probe(struct netif *netif, void *hint)
    403  1.1.14.2  ad {
    404  1.1.14.2  ad 
    405  1.1.14.2  ad 	/* XXX */
    406  1.1.14.2  ad 	return 0;
    407  1.1.14.2  ad }
    408  1.1.14.2  ad 
    409  1.1.14.2  ad void
    410  1.1.14.2  ad tlp_attach(struct iodesc *desc, void *hint)
    411  1.1.14.2  ad {
    412  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    413  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    414  1.1.14.2  ad 
    415  1.1.14.2  ad 	dif->dif_private = tlp_init(&desc->myea);
    416  1.1.14.2  ad }
    417  1.1.14.2  ad 
    418  1.1.14.2  ad int
    419  1.1.14.2  ad tlp_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
    420  1.1.14.2  ad {
    421  1.1.14.2  ad 	int len;
    422  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    423  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    424  1.1.14.2  ad 	void *l = dif->dif_private;
    425  1.1.14.2  ad 
    426  1.1.14.2  ad 	len = tlp_recv(l, pkt, maxlen, timeout);
    427  1.1.14.2  ad 	if (len == -1) {
    428  1.1.14.2  ad 		printf("tlp: receive timeout\n");
    429  1.1.14.2  ad 		/* XXX */
    430  1.1.14.2  ad 	}
    431  1.1.14.2  ad 
    432  1.1.14.2  ad 	if (len < MIN_LEN)
    433  1.1.14.2  ad 		len = -1;
    434  1.1.14.2  ad 
    435  1.1.14.2  ad 	return len;
    436  1.1.14.2  ad }
    437  1.1.14.2  ad 
    438  1.1.14.2  ad int
    439  1.1.14.2  ad tlp_put(struct iodesc *desc, void *pkt, size_t len)
    440  1.1.14.2  ad {
    441  1.1.14.2  ad 	struct netif *nif = desc->io_netif;
    442  1.1.14.2  ad 	struct netif_dif *dif = &nif->nif_driver->netif_ifs[nif->nif_unit];
    443  1.1.14.2  ad 	void *l = dif->dif_private;
    444  1.1.14.2  ad 	int rv;
    445  1.1.14.2  ad 	size_t sendlen;
    446  1.1.14.2  ad 
    447  1.1.14.2  ad 	sendlen = len;
    448  1.1.14.2  ad 	if (sendlen < MIN_LEN)
    449  1.1.14.2  ad 		sendlen = MIN_LEN;	/* XXX */
    450  1.1.14.2  ad 
    451  1.1.14.2  ad 	rv = tlp_send(l, pkt, sendlen);
    452  1.1.14.2  ad 
    453  1.1.14.2  ad 	return rv;
    454  1.1.14.2  ad }
    455  1.1.14.2  ad 
    456  1.1.14.2  ad void
    457  1.1.14.2  ad tlp_end(struct netif *netif)
    458  1.1.14.2  ad {
    459  1.1.14.2  ad }
    460