1 /* $NetBSD: if_bug.c,v 1.3 2009/01/12 11:32:44 tsutsui Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
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/types.h>
34 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netinet/in_systm.h>
40 #include <net/if_ether.h>
42 #include <lib/libkern/libkern.h>
43 #include <lib/libsa/stand.h>
44 #include <lib/libsa/net.h>
45 #include <lib/libsa/netif.h>
48 #include "bugsyscalls.h"
50 static int bug_match(struct netif
*, void *);
51 static int bug_probe(struct netif
*, void *);
52 static void bug_init(struct iodesc
*, void *);
53 static int bug_get(struct iodesc
*, void *, size_t, saseconds_t
);
54 static int bug_put(struct iodesc
*, void *, size_t);
55 static void bug_end(struct netif
*);
57 static struct netif_stats bug_stats
;
59 static struct netif_dif bug0_dif
= {
60 0, 1, &bug_stats
, 0, 0
63 struct netif_driver bug_driver
= {
64 "net", /* netif_bname */
65 bug_match
, /* match */
66 bug_probe
, /* probe */
71 &bug0_dif
, /* netif_ifs */
77 u_int8_t sc_rxbuf
[ETHER_MAX_LEN
];
79 u_int8_t sc_txbuf
[ETHER_MAX_LEN
];
82 static struct bug_softc bug_softc
;
85 bug_match(struct netif
*nif
, void *machdep_hint
)
89 memcmp(bug_driver
.netif_bname
, machdep_hint
,
90 strlen(bug_driver
.netif_bname
)) == 0)
97 bug_probe(struct netif
*nif
, void *machdep_hint
)
104 bug_init(struct iodesc
*desc
, void *machdep_hint
)
106 struct netif
*nif
= desc
->io_netif
;
107 struct bug_netio nio
;
112 nio
.nc_command
= BUG_NETIO_CMD_GET_MAC
;
113 nio
.nc_buffer
= desc
->myea
;
117 if (bugsys_netio(&nio
) != 0 || nio
.nc_status
!= 0)
118 panic("bug_init: Failed to get MAC address! (code 0x%x)",
124 nio
.nc_command
= BUG_NETIO_CMD_FLUSH
;
125 nio
.nc_buffer
= NULL
;
129 if (bugsys_netio(&nio
) != 0 || nio
.nc_status
!= 0)
130 panic("bug_init: Failed to flush netio device (code 0x%x)",
133 printf("network: %s%d attached to %s\n", nif
->nif_driver
->netif_bname
,
134 nif
->nif_unit
, ether_sprintf(desc
->myea
));
136 nif
->nif_devdata
= &bug_softc
;
140 bug_get(struct iodesc
*desc
, void *pkt
, size_t len
, saseconds_t timeout
)
142 struct netif
*nif
= desc
->io_netif
;
143 struct bug_softc
*sc
= nif
->nif_devdata
;
144 struct bug_netio nio
;
149 nio
.nc_command
= BUG_NETIO_CMD_RECEIVE
;
150 nio
.nc_buffer
= sc
->sc_rxbuf
;
151 nio
.nc_length
= ETHER_MAX_LEN
;
154 if (bugsys_netio(&nio
) != 0 || nio
.nc_status
!= 0) {
155 printf("bug_get: Receive packet failed (code: 0x%x)\n",
161 memcpy(pkt
, sc
->sc_rxbuf
, MIN(len
, nio
.nc_length
));
162 return (MIN(len
, nio
.nc_length
));
169 bug_put(struct iodesc
*desc
, void *pkt
, size_t len
)
171 struct netif
*nif
= desc
->io_netif
;
172 struct bug_softc
*sc
= nif
->nif_devdata
;
173 struct bug_netio nio
;
175 memcpy(&sc
->sc_txbuf
, pkt
, len
);
180 nio
.nc_command
= BUG_NETIO_CMD_TRANSMIT
;
181 nio
.nc_buffer
= sc
->sc_txbuf
;
182 nio
.nc_length
= MAX(len
, ETHER_MIN_LEN
);
185 if (bugsys_netio(&nio
) != 0 || nio
.nc_status
!= 0) {
186 printf("bug_put: Send packet failed (code: 0x%x)\n",
195 bug_end(struct netif
*nif
)
197 struct bug_netio nio
;
202 nio
.nc_command
= BUG_NETIO_CMD_FLUSH
;
203 nio
.nc_buffer
= NULL
;
207 if (bugsys_netio(&nio
) != 0 || nio
.nc_status
!= 0)
208 printf("bug_end: netio failed (code: 0x%x)\n", nio
.nc_status
);