Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / cobalt / stand / boot / nif_tlp.c
blob520980578e022b59068cd176da48f54d274b2cf1
1 /* $NetBSD: nif_tlp.c,v 1.2 2008/04/28 20:23:16 martin Exp $ */
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
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>
39 #include <net/if.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>
47 #include "boot.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 = {
65 "tlp",
66 tlp_match,
67 tlp_probe,
68 tlp_attach,
69 tlp_get,
70 tlp_put,
71 tlp_end,
72 tlp_ifs,
76 #ifdef DEBUG
77 int debug = 1; /* referred in various libsa net sources */
78 #endif
80 int
81 tlp_match(struct netif *netif, void *hint)
84 /* always match for onboard tlp */
85 return 1;
88 int
89 tlp_probe(struct netif *netif, void *hint)
92 /* XXX */
93 return 0;
96 void
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)
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;
113 len = tlp_recv(l, pkt, maxlen, timeout);
114 if (len == -1) {
115 printf("tlp: receive timeout\n");
116 /* XXX */
119 if (len < MIN_LEN)
120 len = -1;
122 return len;
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;
131 int rv;
132 size_t sendlen;
134 sendlen = len;
135 if (sendlen < MIN_LEN)
136 sendlen = MIN_LEN; /* XXX */
138 rv = tlp_send(l, pkt, sendlen);
140 return rv;
143 void
144 tlp_end(struct netif *netif)