Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / sandpoint / stand / netboot / nif.c
blob1f57eaca081a9dfb5673025f3686ab0325a38b52
1 /* $NetBSD: nif.c,v 1.10 2009/03/14 15:36:13 dsl Exp $ */
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
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>
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
37 #include <lib/libsa/stand.h>
38 #include <lib/libsa/net.h>
40 #include "globals.h"
42 struct nifdv {
43 char *name;
44 int (*match)(unsigned, void *);
45 void *(*init)(unsigned, void *);
46 int (*send)(void *, char *, unsigned);
47 int (*recv)(void *, char *, unsigned, unsigned);
48 int (*halt)(void *, int);
49 void *priv;
52 static struct iodesc netdesc;
54 static struct nifdv vnifdv[] = {
55 { "fxp", fxp_match, fxp_init, fxp_send, fxp_recv },
56 { "tlp", tlp_match, tlp_init, tlp_send, tlp_recv },
57 { "re", rge_match, rge_init, rge_send, rge_recv },
59 static int nnifdv = sizeof(vnifdv)/sizeof(vnifdv[0]);
61 int
62 netif_init(unsigned tag)
64 struct iodesc *s;
65 struct nifdv *dv;
66 int n;
67 uint8_t enaddr[6];
68 extern uint8_t en[6];
69 extern char rootdev[4];
71 for (n = 0; n < nnifdv; n++) {
72 dv = &vnifdv[n];
73 if ((*dv->match)(tag, NULL) > 0)
74 goto found;
76 return 0;
77 found:
78 dv->priv = (*dv->init)(tag, enaddr);
79 s = &netdesc;
80 s->io_netif = dv;
81 memcpy(s->myea, enaddr, sizeof(s->myea));
82 memcpy(en, enaddr, sizeof(en));
83 snprintf(rootdev, sizeof(rootdev), "%s", dv->name);
84 return 1;
87 int
88 netif_open(void *cookie)
90 /* single action */
91 return 0;
94 int
95 netif_close(int sock)
97 /* nothing to do for the HW */
98 return 0;
102 * Send a packet. The ether header is already there.
103 * Return the length sent (or -1 on error).
105 ssize_t
106 netif_put(struct iodesc *desc, void *pkt, size_t len)
108 struct nifdv *dv = desc->io_netif;
110 return (*dv->send)(dv->priv, pkt, len);
114 * Receive a packet, including the ether header.
115 * Return the total length received (or -1 on error).
117 ssize_t
118 netif_get(struct iodesc *desc, void *pkt, size_t maxlen, saseconds_t timo)
120 struct nifdv *dv = desc->io_netif;
121 int len;
123 len = (*dv->recv)(dv->priv, pkt, maxlen, timo);
124 if (len == -1)
125 printf("timeout\n");
126 return len;
129 struct iodesc *
130 socktodesc(int num)
133 return (num == 0) ? &netdesc : NULL;