1 /* $NetBSD: nif.c,v 1.10 2009/03/14 15:36:13 dsl Exp $ */
4 * Copyright (c) 2007 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>
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
37 #include <lib/libsa/stand.h>
38 #include <lib/libsa/net.h>
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);
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]);
62 netif_init(unsigned tag
)
69 extern char rootdev
[4];
71 for (n
= 0; n
< nnifdv
; n
++) {
73 if ((*dv
->match
)(tag
, NULL
) > 0)
78 dv
->priv
= (*dv
->init
)(tag
, enaddr
);
81 memcpy(s
->myea
, enaddr
, sizeof(s
->myea
));
82 memcpy(en
, enaddr
, sizeof(en
));
83 snprintf(rootdev
, sizeof(rootdev
), "%s", dv
->name
);
88 netif_open(void *cookie
)
97 /* nothing to do for the HW */
102 * Send a packet. The ether header is already there.
103 * Return the length sent (or -1 on error).
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).
118 netif_get(struct iodesc
*desc
, void *pkt
, size_t maxlen
, saseconds_t timo
)
120 struct nifdv
*dv
= desc
->io_netif
;
123 len
= (*dv
->recv
)(dv
->priv
, pkt
, maxlen
, timo
);
133 return (num
== 0) ? &netdesc
: NULL
;