1 /* $NetBSD: nif_tlp.c,v 1.2 2008/04/28 20:23:16 martin Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <lib/libsa/stand.h>
36 #include <lib/libkern/libkern.h>
38 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <netinet/in_systm.h>
43 #include <lib/libsa/net.h>
44 #include <lib/libsa/netif.h>
45 #include <lib/libsa/dev_net.h>
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
*);
56 #define MIN_LEN 60 /* ETHER_MIN_LEN - ETHER_CRC_LEN */
58 static struct netif_stats tlp_stats
[1];
60 static struct netif_dif tlp_ifs
[] = {
61 { 0, 1, &tlp_stats
[0], NULL
, 0 },
64 struct netif_driver ether_tlp_driver
= {
77 int debug
= 1; /* referred in various libsa net sources */
81 tlp_match(struct netif
*netif
, void *hint
)
84 /* always match for onboard tlp */
89 tlp_probe(struct netif
*netif
, void *hint
)
97 tlp_attach(struct iodesc
*desc
, void *hint
)
99 struct netif
*nif
= desc
->io_netif
;
100 struct netif_dif
*dif
= &nif
->nif_driver
->netif_ifs
[nif
->nif_unit
];
102 dif
->dif_private
= tlp_init(&desc
->myea
);
106 tlp_get(struct iodesc
*desc
, void *pkt
, size_t maxlen
, saseconds_t timeout
)
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
;
113 len
= tlp_recv(l
, pkt
, maxlen
, timeout
);
115 printf("tlp: receive timeout\n");
126 tlp_put(struct iodesc
*desc
, void *pkt
, size_t len
)
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
;
135 if (sendlen
< MIN_LEN
)
136 sendlen
= MIN_LEN
; /* XXX */
138 rv
= tlp_send(l
, pkt
, sendlen
);
144 tlp_end(struct netif
*netif
)