if_se.c revision 1.9.2.4 1 1.9.2.4 thorpej /* $NetBSD: if_se.c,v 1.9.2.4 1997/10/15 05:37:22 thorpej Exp $ */
2 1.9.2.2 thorpej
3 1.9.2.2 thorpej /*
4 1.9.2.2 thorpej * Copyright (c) 1997 Ian W. Dall <ian.dall (at) dsto.defence.gov.au>
5 1.9.2.2 thorpej * All rights reserved.
6 1.9.2.2 thorpej *
7 1.9.2.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.9.2.2 thorpej * modification, are permitted provided that the following conditions
9 1.9.2.2 thorpej * are met:
10 1.9.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.9.2.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.9.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.9.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.9.2.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.9.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.9.2.2 thorpej * must display the following acknowledgement:
17 1.9.2.2 thorpej * This product includes software developed by Ian W. Dall.
18 1.9.2.2 thorpej * 4. The name of the author may not be used to endorse or promote products
19 1.9.2.2 thorpej * derived from this software without specific prior written permission.
20 1.9.2.2 thorpej *
21 1.9.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.9.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.9.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.9.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.9.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.9.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.9.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.9.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.9.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.9.2.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.9.2.2 thorpej */
32 1.9.2.2 thorpej
33 1.9.2.2 thorpej /*
34 1.9.2.2 thorpej * Driver for Cabletron EA41x scsi ethernet adaptor.
35 1.9.2.2 thorpej *
36 1.9.2.4 thorpej * Written by Ian Dall <ian.dall (at) dsto.defence.gov.au> Feb 3, 1997
37 1.9.2.4 thorpej *
38 1.9.2.4 thorpej * Acknowledgement: Thanks are due to Philip L. Budne <budd (at) cs.bu.edu>
39 1.9.2.4 thorpej * who reverse engineered the the EA41x. In developing this code,
40 1.9.2.4 thorpej * Phil's userland daemon "etherd", was refered to extensively in lieu
41 1.9.2.4 thorpej * of accurate documentation for the device.
42 1.9.2.4 thorpej *
43 1.9.2.2 thorpej * This is a weird device! It doesn't conform to the scsi spec in much
44 1.9.2.2 thorpej * at all. About the only standard command supported in inquiry. Most
45 1.9.2.2 thorpej * commands are 6 bytes long, but the recv data is only 1 byte. Data
46 1.9.2.2 thorpej * must be received by periodically polling the device with the recv
47 1.9.2.2 thorpej * command.
48 1.9.2.2 thorpej *
49 1.9.2.2 thorpej * This driver is also a bit unusual. It must look like a network
50 1.9.2.2 thorpej * interface and it must also appear to be a scsi device to the scsi
51 1.9.2.2 thorpej * system. Hence there are cases where there are two entry points. eg
52 1.9.2.2 thorpej * sestart is to be called from the scsi subsytem and se_ifstart from
53 1.9.2.2 thorpej * the network interface subsystem. In addition, to facilitate scsi
54 1.9.2.2 thorpej * commands issued by userland programs, there are open, close and
55 1.9.2.2 thorpej * ioctl entry points. This allows a user program to, for example,
56 1.9.2.2 thorpej * display the ea41x stats and download new code into the adaptor ---
57 1.9.2.2 thorpej * functions which can't be performed through the ifconfig interface.
58 1.9.2.2 thorpej * Normal operation does not require any special userland program.
59 1.9.2.2 thorpej */
60 1.9.2.2 thorpej
61 1.9.2.2 thorpej #include "bpfilter.h"
62 1.9.2.2 thorpej
63 1.9.2.2 thorpej #include <sys/types.h>
64 1.9.2.2 thorpej #include <sys/param.h>
65 1.9.2.2 thorpej #include <sys/systm.h>
66 1.9.2.2 thorpej #include <sys/syslog.h>
67 1.9.2.2 thorpej #include <sys/kernel.h>
68 1.9.2.2 thorpej #include <sys/file.h>
69 1.9.2.2 thorpej #include <sys/stat.h>
70 1.9.2.2 thorpej #include <sys/ioctl.h>
71 1.9.2.2 thorpej #include <sys/buf.h>
72 1.9.2.2 thorpej #include <sys/uio.h>
73 1.9.2.2 thorpej #include <sys/malloc.h>
74 1.9.2.2 thorpej #include <sys/errno.h>
75 1.9.2.2 thorpej #include <sys/device.h>
76 1.9.2.2 thorpej #include <sys/disklabel.h>
77 1.9.2.2 thorpej #include <sys/disk.h>
78 1.9.2.2 thorpej #include <sys/proc.h>
79 1.9.2.2 thorpej #include <sys/conf.h>
80 1.9.2.2 thorpej
81 1.9.2.2 thorpej #include <dev/scsipi/scsipi_all.h>
82 1.9.2.2 thorpej #include <dev/scsipi/scsi_ctron_ether.h>
83 1.9.2.2 thorpej #include <dev/scsipi/scsiconf.h>
84 1.9.2.2 thorpej
85 1.9.2.2 thorpej #include <sys/mbuf.h>
86 1.9.2.2 thorpej
87 1.9.2.2 thorpej #include <sys/socket.h>
88 1.9.2.2 thorpej #include <net/if.h>
89 1.9.2.2 thorpej #include <net/if_dl.h>
90 1.9.2.2 thorpej #include <net/if_ether.h>
91 1.9.2.2 thorpej #include <net/if_media.h>
92 1.9.2.2 thorpej
93 1.9.2.2 thorpej #ifdef INET
94 1.9.2.2 thorpej #include <netinet/in.h>
95 1.9.2.2 thorpej #include <netinet/if_inarp.h>
96 1.9.2.2 thorpej #endif
97 1.9.2.2 thorpej
98 1.9.2.2 thorpej #ifdef NS
99 1.9.2.2 thorpej #include <netns/ns.h>
100 1.9.2.2 thorpej #include <netns/ns_if.h>
101 1.9.2.2 thorpej #endif
102 1.9.2.2 thorpej
103 1.9.2.2 thorpej #ifdef NETATALK
104 1.9.2.2 thorpej #include <netatalk/at.h>
105 1.9.2.2 thorpej #endif
106 1.9.2.2 thorpej
107 1.9.2.2 thorpej #if defined(CCITT) && defined(LLC)
108 1.9.2.2 thorpej #include <sys/socketvar.h>
109 1.9.2.2 thorpej #include <netccitt/x25.h>
110 1.9.2.2 thorpej #include <netccitt/pk.h>
111 1.9.2.2 thorpej #include <netccitt/pk_var.h>
112 1.9.2.2 thorpej #include <netccitt/pk_extern.h>
113 1.9.2.2 thorpej #endif
114 1.9.2.2 thorpej
115 1.9.2.2 thorpej #if NBPFILTER > 0
116 1.9.2.2 thorpej #include <net/bpf.h>
117 1.9.2.2 thorpej #include <net/bpfdesc.h>
118 1.9.2.2 thorpej #endif
119 1.9.2.2 thorpej
120 1.9.2.2 thorpej #define SETIMEOUT 1000
121 1.9.2.2 thorpej #define SEOUTSTANDING 4
122 1.9.2.2 thorpej #define SERETRIES 4
123 1.9.2.2 thorpej #define SE_PREFIX 4
124 1.9.2.2 thorpej #define ETHER_CRC 4
125 1.9.2.2 thorpej #define SEMINSIZE 60
126 1.9.2.2 thorpej
127 1.9.2.2 thorpej /* Make this big enough for an ETHERMTU packet in promiscuous mode. */
128 1.9.2.2 thorpej #define MAX_SNAP (ETHERMTU + sizeof(struct ether_header) + \
129 1.9.2.2 thorpej SE_PREFIX + ETHER_CRC)
130 1.9.2.2 thorpej
131 1.9.2.4 thorpej /* 10 full length packets appears to be the max ever returned. 16k is OK */
132 1.9.2.4 thorpej #define RBUF_LEN (16 * 1024)
133 1.9.2.4 thorpej
134 1.9.2.4 thorpej /* Tuning parameters:
135 1.9.2.4 thorpej * The EA41x only returns a maximum of 10 packets (regardless of size).
136 1.9.2.4 thorpej * We will attempt to adapt to polling fast enough to get RDATA_GOAL packets
137 1.9.2.4 thorpej * per read
138 1.9.2.4 thorpej */
139 1.9.2.4 thorpej #define RDATA_MAX 10
140 1.9.2.4 thorpej #define RDATA_GOAL 8
141 1.9.2.4 thorpej
142 1.9.2.4 thorpej /* se_poll and se_poll0 are the normal polling rate and the minimum
143 1.9.2.4 thorpej * polling rate respectively. se_poll0 should be chosen so that at
144 1.9.2.4 thorpej * maximum ethernet speed, we will read nearly RDATA_MAX packets. se_poll
145 1.9.2.4 thorpej * should be chosen for reasonable maximum latency.
146 1.9.2.4 thorpej * In practice, if we are being saturated with min length packets, we
147 1.9.2.4 thorpej * can't poll fast enough. Polling with zero delay actually
148 1.9.2.4 thorpej * worsens performance. se_poll0 is enforced to be always at least 1
149 1.9.2.2 thorpej */
150 1.9.2.2 thorpej #define SE_POLL 40 /* default in milliseconds */
151 1.9.2.4 thorpej #define SE_POLL0 10 /* default in milliseconds */
152 1.9.2.4 thorpej int se_poll = 0; /* Delay in ticks set at attach time */
153 1.9.2.2 thorpej int se_poll0 = 0;
154 1.9.2.4 thorpej int se_max_received = 0; /* Instrumentation */
155 1.9.2.2 thorpej
156 1.9.2.2 thorpej #define PROTOCMD(p, d) \
157 1.9.2.2 thorpej ((d) = (p))
158 1.9.2.2 thorpej
159 1.9.2.2 thorpej #define PROTOCMD_DECL(name, val) \
160 1.9.2.2 thorpej static const struct scsi_ctron_ether_generic name = val
161 1.9.2.2 thorpej
162 1.9.2.2 thorpej #define PROTOCMD_DECL_SPECIAL(name, val) \
163 1.9.2.2 thorpej static const struct __CONCAT(scsi_,name) name = val
164 1.9.2.2 thorpej
165 1.9.2.2 thorpej /* Command initializers for commands using scsi_ctron_ether_generic */
166 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_send, {CTRON_ETHER_SEND});
167 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_add_proto, {CTRON_ETHER_ADD_PROTO});
168 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_get_addr, {CTRON_ETHER_GET_ADDR});
169 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_set_media, {CTRON_ETHER_SET_MEDIA});
170 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_set_addr, {CTRON_ETHER_SET_ADDR});
171 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_set_multi, {CTRON_ETHER_SET_MULTI});
172 1.9.2.2 thorpej PROTOCMD_DECL(ctron_ether_remove_multi, {CTRON_ETHER_REMOVE_MULTI});
173 1.9.2.2 thorpej
174 1.9.2.2 thorpej /* Command initializers for commands using their own structures */
175 1.9.2.2 thorpej PROTOCMD_DECL_SPECIAL(ctron_ether_recv, {CTRON_ETHER_RECV});
176 1.9.2.2 thorpej PROTOCMD_DECL_SPECIAL(ctron_ether_set_mode, {CTRON_ETHER_SET_MODE});
177 1.9.2.2 thorpej
178 1.9.2.2 thorpej struct se_softc {
179 1.9.2.2 thorpej struct device sc_dev;
180 1.9.2.2 thorpej struct ethercom sc_ethercom; /* Ethernet common part */
181 1.9.2.2 thorpej struct scsipi_link *sc_link; /* contains our targ, lun, etc. */
182 1.9.2.2 thorpej char *sc_tbuf;
183 1.9.2.2 thorpej char *sc_rbuf;
184 1.9.2.2 thorpej int protos;
185 1.9.2.2 thorpej #define PROTO_IP 0x01
186 1.9.2.2 thorpej #define PROTO_ARP 0x02
187 1.9.2.2 thorpej #define PROTO_REVARP 0x04
188 1.9.2.2 thorpej #define PROTO_AT 0x08
189 1.9.2.2 thorpej #define PROTO_AARP 0x10
190 1.9.2.2 thorpej int sc_debug;
191 1.9.2.2 thorpej int sc_flags;
192 1.9.2.2 thorpej #define SE_NEED_RECV 0x1
193 1.9.2.4 thorpej int sc_last_timeout;
194 1.9.2.2 thorpej };
195 1.9.2.2 thorpej
196 1.9.2.2 thorpej cdev_decl(se);
197 1.9.2.2 thorpej
198 1.9.2.2 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
199 1.9.2.2 thorpej static int sematch __P((struct device *, void *, void *));
200 1.9.2.2 thorpej #else
201 1.9.2.2 thorpej static int sematch __P((struct device *, struct cfdata *, void *));
202 1.9.2.2 thorpej #endif
203 1.9.2.2 thorpej static void seattach __P((struct device *, struct device *, void *));
204 1.9.2.2 thorpej
205 1.9.2.2 thorpej static void se_ifstart __P((struct ifnet *));
206 1.9.2.2 thorpej static void sestart __P((void *));
207 1.9.2.2 thorpej
208 1.9.2.2 thorpej static void sedone __P((struct scsipi_xfer *));
209 1.9.2.2 thorpej static int se_ioctl __P((struct ifnet *, u_long, caddr_t));
210 1.9.2.2 thorpej static void sewatchdog __P((struct ifnet *));
211 1.9.2.2 thorpej
212 1.9.2.2 thorpej static __inline u_int16_t ether_cmp __P((void *, void *));
213 1.9.2.2 thorpej static void se_recv __P((void *));
214 1.9.2.2 thorpej static struct mbuf *se_get __P((struct se_softc *, char *, int));
215 1.9.2.2 thorpej static int se_read __P((struct se_softc *, char *, int));
216 1.9.2.2 thorpej static int se_reset __P((struct se_softc *));
217 1.9.2.2 thorpej static int se_add_proto __P((struct se_softc *, int));
218 1.9.2.2 thorpej static int se_get_addr __P((struct se_softc *, u_int8_t *));
219 1.9.2.2 thorpej static int se_set_media __P((struct se_softc *, int));
220 1.9.2.2 thorpej static int se_init __P((struct se_softc *));
221 1.9.2.2 thorpej static int se_set_multi __P((struct se_softc *, u_int8_t *));
222 1.9.2.2 thorpej static int se_remove_multi __P((struct se_softc *, u_int8_t *));
223 1.9.2.2 thorpej #if 0
224 1.9.2.2 thorpej static int sc_set_all_multi __P((struct se_softc *, int));
225 1.9.2.2 thorpej #endif
226 1.9.2.2 thorpej static void se_stop __P((struct se_softc *));
227 1.9.2.2 thorpej static __inline int se_scsipi_cmd __P((struct scsipi_link *sc_link,
228 1.9.2.3 thorpej struct scsipi_generic *scsipi_cmd,
229 1.9.2.3 thorpej int cmdlen, u_char *data_addr, int datalen,
230 1.9.2.3 thorpej int retries, int timeout, struct buf *bp,
231 1.9.2.3 thorpej int flags));
232 1.9.2.2 thorpej static void se_delayed_ifstart __P((void *));
233 1.9.2.2 thorpej static int se_set_mode(struct se_softc *, int, int);
234 1.9.2.2 thorpej
235 1.9.2.2 thorpej struct cfattach se_ca = {
236 1.9.2.2 thorpej sizeof(struct se_softc), sematch, seattach
237 1.9.2.2 thorpej };
238 1.9.2.2 thorpej
239 1.9.2.2 thorpej struct cfdriver se_cd = {
240 1.9.2.2 thorpej NULL, "se", DV_IFNET
241 1.9.2.2 thorpej };
242 1.9.2.2 thorpej
243 1.9.2.2 thorpej struct scsipi_device se_switch = {
244 1.9.2.2 thorpej NULL, /* Use default error handler */
245 1.9.2.2 thorpej sestart, /* have a queue, served by this */
246 1.9.2.2 thorpej NULL, /* have no async handler */
247 1.9.2.2 thorpej sedone, /* deal with stats at interrupt time */
248 1.9.2.2 thorpej };
249 1.9.2.2 thorpej
250 1.9.2.2 thorpej struct scsipi_inquiry_pattern se_patterns[] = {
251 1.9.2.2 thorpej {T_PROCESSOR, T_FIXED,
252 1.9.2.4 thorpej "CABLETRN", "EA412", ""},
253 1.9.2.2 thorpej {T_PROCESSOR, T_FIXED,
254 1.9.2.4 thorpej "Cabletrn", "EA412", ""},
255 1.9.2.2 thorpej };
256 1.9.2.2 thorpej
257 1.9.2.2 thorpej /*
258 1.9.2.2 thorpej * Compare two Ether/802 addresses for equality, inlined and
259 1.9.2.2 thorpej * unrolled for speed.
260 1.9.2.2 thorpej * Note: use this like bcmp()
261 1.9.2.2 thorpej */
262 1.9.2.2 thorpej static __inline u_int16_t
263 1.9.2.2 thorpej ether_cmp(one, two)
264 1.9.2.2 thorpej void *one, *two;
265 1.9.2.2 thorpej {
266 1.9.2.2 thorpej register u_int16_t *a = (u_int16_t *) one;
267 1.9.2.2 thorpej register u_int16_t *b = (u_int16_t *) two;
268 1.9.2.2 thorpej register u_int16_t diff;
269 1.9.2.2 thorpej
270 1.9.2.2 thorpej diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
271 1.9.2.2 thorpej
272 1.9.2.2 thorpej return (diff);
273 1.9.2.2 thorpej }
274 1.9.2.2 thorpej
275 1.9.2.2 thorpej #define ETHER_CMP ether_cmp
276 1.9.2.2 thorpej
277 1.9.2.2 thorpej static int
278 1.9.2.2 thorpej sematch(parent, match, aux)
279 1.9.2.2 thorpej struct device *parent;
280 1.9.2.2 thorpej #ifdef __BROKEN_INDIRECT_CONFIG
281 1.9.2.2 thorpej void *match;
282 1.9.2.2 thorpej #else
283 1.9.2.2 thorpej struct cfdata *match;
284 1.9.2.2 thorpej #endif
285 1.9.2.2 thorpej void *aux;
286 1.9.2.2 thorpej {
287 1.9.2.2 thorpej struct scsipibus_attach_args *sa = aux;
288 1.9.2.2 thorpej int priority;
289 1.9.2.2 thorpej
290 1.9.2.2 thorpej (void)scsipi_inqmatch(&sa->sa_inqbuf,
291 1.9.2.3 thorpej (caddr_t)se_patterns, sizeof(se_patterns) / sizeof(se_patterns[0]),
292 1.9.2.2 thorpej sizeof(se_patterns[0]), &priority);
293 1.9.2.2 thorpej return (priority);
294 1.9.2.2 thorpej }
295 1.9.2.2 thorpej
296 1.9.2.2 thorpej /*
297 1.9.2.2 thorpej * The routine called by the low level scsi routine when it discovers
298 1.9.2.2 thorpej * a device suitable for this driver.
299 1.9.2.2 thorpej */
300 1.9.2.2 thorpej static void
301 1.9.2.2 thorpej seattach(parent, self, aux)
302 1.9.2.2 thorpej struct device *parent, *self;
303 1.9.2.2 thorpej void *aux;
304 1.9.2.2 thorpej {
305 1.9.2.2 thorpej struct se_softc *sc = (void *)self;
306 1.9.2.2 thorpej struct scsipibus_attach_args *sa = aux;
307 1.9.2.2 thorpej struct scsipi_link *sc_link = sa->sa_sc_link;
308 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
309 1.9.2.2 thorpej u_int8_t myaddr[ETHER_ADDR_LEN];
310 1.9.2.2 thorpej
311 1.9.2.2 thorpej printf("\n");
312 1.9.2.2 thorpej SC_DEBUG(sc_link, SDEV_DB2, ("seattach: "));
313 1.9.2.2 thorpej
314 1.9.2.2 thorpej /*
315 1.9.2.2 thorpej * Store information needed to contact our base driver
316 1.9.2.2 thorpej */
317 1.9.2.2 thorpej sc->sc_link = sc_link;
318 1.9.2.2 thorpej sc_link->device = &se_switch;
319 1.9.2.2 thorpej sc_link->device_softc = sc;
320 1.9.2.2 thorpej if (sc_link->openings > SEOUTSTANDING)
321 1.9.2.2 thorpej sc_link->openings = SEOUTSTANDING;
322 1.9.2.2 thorpej
323 1.9.2.2 thorpej se_poll = (SE_POLL * hz) / 1000;
324 1.9.2.2 thorpej se_poll = se_poll? se_poll: 1;
325 1.9.2.2 thorpej se_poll0 = (SE_POLL0 * hz) / 1000;
326 1.9.2.2 thorpej se_poll0 = se_poll0? se_poll0: 1;
327 1.9.2.2 thorpej
328 1.9.2.2 thorpej /*
329 1.9.2.2 thorpej * Initialize and attach a buffer
330 1.9.2.2 thorpej */
331 1.9.2.2 thorpej sc->sc_tbuf = malloc(ETHERMTU + sizeof(struct ether_header),
332 1.9.2.2 thorpej M_DEVBUF, M_NOWAIT);
333 1.9.2.2 thorpej if (sc->sc_tbuf == 0)
334 1.9.2.2 thorpej panic("seattach: can't allocate transmit buffer");
335 1.9.2.2 thorpej
336 1.9.2.2 thorpej sc->sc_rbuf = malloc(RBUF_LEN, M_DEVBUF, M_NOWAIT);/* A Guess */
337 1.9.2.2 thorpej if (sc->sc_rbuf == 0)
338 1.9.2.2 thorpej panic("seattach: can't allocate receive buffer");
339 1.9.2.2 thorpej
340 1.9.2.2 thorpej se_get_addr(sc, myaddr);
341 1.9.2.2 thorpej
342 1.9.2.2 thorpej /* Initialize ifnet structure. */
343 1.9.2.2 thorpej bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
344 1.9.2.2 thorpej ifp->if_softc = sc;
345 1.9.2.2 thorpej ifp->if_start = se_ifstart;
346 1.9.2.2 thorpej ifp->if_ioctl = se_ioctl;
347 1.9.2.2 thorpej ifp->if_watchdog = sewatchdog;
348 1.9.2.2 thorpej ifp->if_flags =
349 1.9.2.2 thorpej IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
350 1.9.2.2 thorpej
351 1.9.2.2 thorpej /* Attach the interface. */
352 1.9.2.2 thorpej if_attach(ifp);
353 1.9.2.2 thorpej ether_ifattach(ifp, myaddr);
354 1.9.2.2 thorpej
355 1.9.2.2 thorpej #if NBPFILTER > 0
356 1.9.2.2 thorpej bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
357 1.9.2.2 thorpej #endif
358 1.9.2.2 thorpej }
359 1.9.2.2 thorpej
360 1.9.2.2 thorpej
361 1.9.2.2 thorpej static __inline int
362 1.9.2.2 thorpej se_scsipi_cmd(sc_link, scsipi_cmd, cmdlen, data_addr, datalen,
363 1.9.2.2 thorpej retries, timeout, bp, flags)
364 1.9.2.2 thorpej struct scsipi_link *sc_link;
365 1.9.2.2 thorpej struct scsipi_generic *scsipi_cmd;
366 1.9.2.2 thorpej int cmdlen;
367 1.9.2.2 thorpej u_char *data_addr;
368 1.9.2.2 thorpej int datalen;
369 1.9.2.2 thorpej int retries;
370 1.9.2.2 thorpej int timeout;
371 1.9.2.2 thorpej struct buf *bp;
372 1.9.2.2 thorpej int flags;
373 1.9.2.2 thorpej {
374 1.9.2.2 thorpej int error;
375 1.9.2.2 thorpej int s = splbio();
376 1.9.2.3 thorpej
377 1.9.2.3 thorpej error = (*sc_link->scsipi_cmd)(sc_link, scsipi_cmd, cmdlen, data_addr,
378 1.9.2.3 thorpej datalen, retries, timeout, bp, flags);
379 1.9.2.2 thorpej splx(s);
380 1.9.2.3 thorpej return (error);
381 1.9.2.2 thorpej }
382 1.9.2.2 thorpej
383 1.9.2.2 thorpej /* Start routine for calling from scsi sub system */
384 1.9.2.2 thorpej static void
385 1.9.2.2 thorpej sestart(v)
386 1.9.2.2 thorpej void *v;
387 1.9.2.2 thorpej {
388 1.9.2.2 thorpej struct se_softc *sc = (struct se_softc *) v;
389 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
390 1.9.2.2 thorpej int s = splnet();
391 1.9.2.3 thorpej
392 1.9.2.2 thorpej se_ifstart(ifp);
393 1.9.2.2 thorpej (void) splx(s);
394 1.9.2.2 thorpej }
395 1.9.2.2 thorpej
396 1.9.2.2 thorpej static void
397 1.9.2.2 thorpej se_delayed_ifstart(v)
398 1.9.2.2 thorpej void *v;
399 1.9.2.2 thorpej {
400 1.9.2.2 thorpej struct ifnet *ifp = v;
401 1.9.2.2 thorpej int s = splnet();
402 1.9.2.3 thorpej
403 1.9.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
404 1.9.2.2 thorpej se_ifstart(ifp);
405 1.9.2.2 thorpej splx(s);
406 1.9.2.2 thorpej }
407 1.9.2.2 thorpej
408 1.9.2.2 thorpej /*
409 1.9.2.2 thorpej * Start transmission on the interface.
410 1.9.2.2 thorpej * Always called at splnet().
411 1.9.2.2 thorpej */
412 1.9.2.2 thorpej static void
413 1.9.2.2 thorpej se_ifstart(ifp)
414 1.9.2.2 thorpej struct ifnet *ifp;
415 1.9.2.2 thorpej {
416 1.9.2.2 thorpej struct se_softc *sc = ifp->if_softc;
417 1.9.2.2 thorpej struct scsi_ctron_ether_generic send_cmd;
418 1.9.2.2 thorpej struct mbuf *m, *m0;
419 1.9.2.2 thorpej int len, error;
420 1.9.2.2 thorpej u_char *cp;
421 1.9.2.2 thorpej
422 1.9.2.2 thorpej /* Don't transmit if interface is busy or not running */
423 1.9.2.2 thorpej if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
424 1.9.2.2 thorpej return;
425 1.9.2.2 thorpej
426 1.9.2.2 thorpej IF_DEQUEUE(&ifp->if_snd, m0);
427 1.9.2.2 thorpej if (m0 == 0)
428 1.9.2.2 thorpej return;
429 1.9.2.2 thorpej #if NBPFILTER > 0
430 1.9.2.2 thorpej /* If BPF is listening on this interface, let it see the
431 1.9.2.2 thorpej * packet before we commit it to the wire.
432 1.9.2.2 thorpej */
433 1.9.2.2 thorpej if (ifp->if_bpf)
434 1.9.2.2 thorpej bpf_mtap(ifp->if_bpf, m0);
435 1.9.2.2 thorpej #endif
436 1.9.2.2 thorpej
437 1.9.2.2 thorpej /* We need to use m->m_pkthdr.len, so require the header */
438 1.9.2.2 thorpej if ((m0->m_flags & M_PKTHDR) == 0)
439 1.9.2.2 thorpej panic("ctscstart: no header mbuf");
440 1.9.2.2 thorpej len = m0->m_pkthdr.len;
441 1.9.2.2 thorpej
442 1.9.2.2 thorpej /* Mark the interface busy. */
443 1.9.2.2 thorpej ifp->if_flags |= IFF_OACTIVE;
444 1.9.2.2 thorpej
445 1.9.2.2 thorpej /* Chain; copy into linear buffer we allocated at attach time. */
446 1.9.2.2 thorpej cp = sc->sc_tbuf;
447 1.9.2.2 thorpej for (m = m0; m != NULL; ) {
448 1.9.2.2 thorpej bcopy(mtod(m, u_char *), cp, m->m_len);
449 1.9.2.2 thorpej cp += m->m_len;
450 1.9.2.2 thorpej MFREE(m, m0);
451 1.9.2.2 thorpej m = m0;
452 1.9.2.2 thorpej }
453 1.9.2.2 thorpej if (len < SEMINSIZE) {
454 1.9.2.2 thorpej #ifdef SEDEBUG
455 1.9.2.2 thorpej if (sc->sc_debug)
456 1.9.2.2 thorpej printf("se: packet size %d (%d) < %d\n", len,
457 1.9.2.3 thorpej cp - (u_char *)sc->sc_tbuf, SEMINSIZE);
458 1.9.2.2 thorpej #endif
459 1.9.2.2 thorpej bzero(cp, SEMINSIZE - len);
460 1.9.2.2 thorpej len = SEMINSIZE;
461 1.9.2.2 thorpej }
462 1.9.2.2 thorpej
463 1.9.2.2 thorpej /* Fill out SCSI command. */
464 1.9.2.2 thorpej PROTOCMD(ctron_ether_send, send_cmd);
465 1.9.2.2 thorpej _lto2b(len, send_cmd.length);
466 1.9.2.2 thorpej
467 1.9.2.2 thorpej /* Send command to device. */
468 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
469 1.9.2.3 thorpej (struct scsipi_generic *)&send_cmd, sizeof(send_cmd),
470 1.9.2.3 thorpej sc->sc_tbuf, len, SERETRIES,
471 1.9.2.3 thorpej SETIMEOUT, NULL, SCSI_NOSLEEP|SCSI_DATA_OUT);
472 1.9.2.2 thorpej if (error) {
473 1.9.2.2 thorpej printf("%s: not queued, error %d\n",
474 1.9.2.3 thorpej sc->sc_dev.dv_xname, error);
475 1.9.2.2 thorpej ifp->if_oerrors++;
476 1.9.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
477 1.9.2.2 thorpej } else
478 1.9.2.2 thorpej ifp->if_opackets++;
479 1.9.2.2 thorpej if (sc->sc_flags & SE_NEED_RECV) {
480 1.9.2.2 thorpej sc->sc_flags &= ~SE_NEED_RECV;
481 1.9.2.2 thorpej se_recv((void *) sc);
482 1.9.2.2 thorpej }
483 1.9.2.2 thorpej }
484 1.9.2.2 thorpej
485 1.9.2.2 thorpej
486 1.9.2.2 thorpej /*
487 1.9.2.2 thorpej * Called from the scsibus layer via our scsi device switch.
488 1.9.2.2 thorpej */
489 1.9.2.2 thorpej static void
490 1.9.2.2 thorpej sedone(xs)
491 1.9.2.2 thorpej struct scsipi_xfer *xs;
492 1.9.2.2 thorpej {
493 1.9.2.2 thorpej int error;
494 1.9.2.2 thorpej struct se_softc *sc = xs->sc_link->device_softc;
495 1.9.2.2 thorpej struct scsipi_generic *cmd = xs->cmd;
496 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
497 1.9.2.2 thorpej int s;
498 1.9.2.2 thorpej
499 1.9.2.2 thorpej error = !(xs->error == XS_NOERROR);
500 1.9.2.2 thorpej
501 1.9.2.2 thorpej s = splnet();
502 1.9.2.2 thorpej if(IS_SEND(cmd)) {
503 1.9.2.2 thorpej if (xs->error == XS_BUSY) {
504 1.9.2.2 thorpej printf("se: busy, retry txmit\n");
505 1.9.2.2 thorpej timeout(se_delayed_ifstart, ifp, hz);
506 1.9.2.2 thorpej } else {
507 1.9.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
508 1.9.2.2 thorpej /* the generic scsipi_done will call
509 1.9.2.2 thorpej * sestart (through scsipi_free_xs).
510 1.9.2.2 thorpej */
511 1.9.2.2 thorpej }
512 1.9.2.2 thorpej } else if(IS_RECV(cmd)) {
513 1.9.2.2 thorpej /* RECV complete */
514 1.9.2.2 thorpej /* pass data up. reschedule a recv */
515 1.9.2.2 thorpej /* scsipi_free_xs will call start. Harmless. */
516 1.9.2.2 thorpej if (error) {
517 1.9.2.2 thorpej /* Reschedule after a delay */
518 1.9.2.2 thorpej timeout(se_recv, (void *)sc, se_poll);
519 1.9.2.2 thorpej } else {
520 1.9.2.4 thorpej int n, ntimeo;
521 1.9.2.2 thorpej n = se_read(sc, xs->data, xs->datalen - xs->resid);
522 1.9.2.4 thorpej if (n > se_max_received)
523 1.9.2.4 thorpej se_max_received = n;
524 1.9.2.4 thorpej if (n == 0)
525 1.9.2.4 thorpej ntimeo = se_poll;
526 1.9.2.4 thorpej else if (n >= RDATA_MAX)
527 1.9.2.4 thorpej ntimeo = se_poll0;
528 1.9.2.4 thorpej else {
529 1.9.2.4 thorpej ntimeo = sc->sc_last_timeout;
530 1.9.2.4 thorpej ntimeo = (ntimeo * RDATA_GOAL)/n;
531 1.9.2.4 thorpej ntimeo = (ntimeo < se_poll0?
532 1.9.2.4 thorpej se_poll0: ntimeo);
533 1.9.2.4 thorpej ntimeo = (ntimeo > se_poll?
534 1.9.2.4 thorpej se_poll: ntimeo);
535 1.9.2.2 thorpej }
536 1.9.2.4 thorpej sc->sc_last_timeout = ntimeo;
537 1.9.2.4 thorpej if (ntimeo == se_poll0 &&
538 1.9.2.4 thorpej ifp->if_snd.ifq_head)
539 1.9.2.4 thorpej /* Output is pending. Do next recv
540 1.9.2.4 thorpej * after the next send. */
541 1.9.2.4 thorpej sc->sc_flags |= SE_NEED_RECV;
542 1.9.2.4 thorpej else {
543 1.9.2.4 thorpej timeout(se_recv, (void *)sc, ntimeo);
544 1.9.2.4 thorpej }
545 1.9.2.2 thorpej }
546 1.9.2.2 thorpej }
547 1.9.2.2 thorpej splx(s);
548 1.9.2.2 thorpej }
549 1.9.2.3 thorpej
550 1.9.2.2 thorpej static void
551 1.9.2.2 thorpej se_recv(v)
552 1.9.2.2 thorpej void *v;
553 1.9.2.2 thorpej {
554 1.9.2.2 thorpej /* do a recv command */
555 1.9.2.2 thorpej struct se_softc *sc = (struct se_softc *) v;
556 1.9.2.2 thorpej struct scsi_ctron_ether_recv recv_cmd;
557 1.9.2.2 thorpej int error;
558 1.9.2.2 thorpej
559 1.9.2.2 thorpej PROTOCMD(ctron_ether_recv, recv_cmd);
560 1.9.2.2 thorpej
561 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
562 1.9.2.3 thorpej (struct scsipi_generic *)&recv_cmd, sizeof(recv_cmd),
563 1.9.2.3 thorpej sc->sc_rbuf, RBUF_LEN, SERETRIES, SETIMEOUT, NULL,
564 1.9.2.3 thorpej SCSI_NOSLEEP|SCSI_DATA_IN);
565 1.9.2.2 thorpej if (error)
566 1.9.2.2 thorpej timeout(se_recv, (void *)sc, se_poll);
567 1.9.2.2 thorpej }
568 1.9.2.2 thorpej
569 1.9.2.2 thorpej /*
570 1.9.2.2 thorpej * We copy the data into mbufs. When full cluster sized units are present
571 1.9.2.2 thorpej * we copy into clusters.
572 1.9.2.2 thorpej */
573 1.9.2.2 thorpej static struct mbuf *
574 1.9.2.2 thorpej se_get(sc, data, totlen)
575 1.9.2.2 thorpej struct se_softc *sc;
576 1.9.2.2 thorpej char *data;
577 1.9.2.2 thorpej int totlen;
578 1.9.2.2 thorpej {
579 1.9.2.2 thorpej struct mbuf *m;
580 1.9.2.2 thorpej struct mbuf *top, **mp;
581 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
582 1.9.2.2 thorpej int len, pad;
583 1.9.2.2 thorpej
584 1.9.2.2 thorpej MGETHDR(m, M_DONTWAIT, MT_DATA);
585 1.9.2.2 thorpej if (m == 0)
586 1.9.2.2 thorpej return (0);
587 1.9.2.2 thorpej m->m_pkthdr.rcvif = ifp;
588 1.9.2.2 thorpej m->m_pkthdr.len = totlen;
589 1.9.2.2 thorpej pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
590 1.9.2.2 thorpej m->m_data += pad;
591 1.9.2.2 thorpej len = MHLEN - pad;
592 1.9.2.2 thorpej top = 0;
593 1.9.2.2 thorpej mp = ⊤
594 1.9.2.2 thorpej
595 1.9.2.2 thorpej while (totlen > 0) {
596 1.9.2.2 thorpej if (top) {
597 1.9.2.2 thorpej MGET(m, M_DONTWAIT, MT_DATA);
598 1.9.2.2 thorpej if (m == 0) {
599 1.9.2.2 thorpej m_freem(top);
600 1.9.2.3 thorpej return (0);
601 1.9.2.2 thorpej }
602 1.9.2.2 thorpej len = MLEN;
603 1.9.2.2 thorpej }
604 1.9.2.2 thorpej if (totlen >= MINCLSIZE) {
605 1.9.2.2 thorpej MCLGET(m, M_DONTWAIT);
606 1.9.2.2 thorpej if ((m->m_flags & M_EXT) == 0) {
607 1.9.2.2 thorpej m_free(m);
608 1.9.2.2 thorpej m_freem(top);
609 1.9.2.3 thorpej return (0);
610 1.9.2.2 thorpej }
611 1.9.2.2 thorpej len = MCLBYTES;
612 1.9.2.2 thorpej }
613 1.9.2.2 thorpej m->m_len = len = min(totlen, len);
614 1.9.2.2 thorpej bcopy(data, mtod(m, caddr_t), len);
615 1.9.2.2 thorpej data += len;
616 1.9.2.2 thorpej totlen -= len;
617 1.9.2.2 thorpej *mp = m;
618 1.9.2.2 thorpej mp = &m->m_next;
619 1.9.2.2 thorpej }
620 1.9.2.2 thorpej
621 1.9.2.2 thorpej return (top);
622 1.9.2.2 thorpej }
623 1.9.2.2 thorpej
624 1.9.2.2 thorpej /*
625 1.9.2.2 thorpej * Pass packets to higher levels.
626 1.9.2.2 thorpej */
627 1.9.2.2 thorpej static int
628 1.9.2.2 thorpej se_read(sc, data, datalen)
629 1.9.2.2 thorpej register struct se_softc *sc;
630 1.9.2.2 thorpej char *data;
631 1.9.2.2 thorpej int datalen;
632 1.9.2.2 thorpej {
633 1.9.2.2 thorpej struct mbuf *m;
634 1.9.2.2 thorpej struct ether_header *eh;
635 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
636 1.9.2.2 thorpej int n;
637 1.9.2.2 thorpej
638 1.9.2.2 thorpej n = 0;
639 1.9.2.2 thorpej while (datalen >= 2) {
640 1.9.2.2 thorpej int len = _2btol(data);
641 1.9.2.2 thorpej data += 2;
642 1.9.2.2 thorpej datalen -= 2;
643 1.9.2.2 thorpej
644 1.9.2.2 thorpej if (len == 0)
645 1.9.2.2 thorpej break;
646 1.9.2.2 thorpej #ifdef SEDEBUG
647 1.9.2.2 thorpej if (sc->sc_debug) {
648 1.9.2.2 thorpej printf("se_read: datalen = %d, packetlen = %d, proto = 0x%04x\n", datalen, len,
649 1.9.2.2 thorpej ntohs(((struct ether_header *)data)->ether_type));
650 1.9.2.2 thorpej }
651 1.9.2.2 thorpej #endif
652 1.9.2.2 thorpej if (len <= sizeof(struct ether_header) ||
653 1.9.2.2 thorpej len > MAX_SNAP) {
654 1.9.2.2 thorpej #ifdef SEDEBUG
655 1.9.2.2 thorpej printf("%s: invalid packet size %d; dropping\n",
656 1.9.2.2 thorpej sc->sc_dev.dv_xname, len);
657 1.9.2.2 thorpej #endif
658 1.9.2.2 thorpej ifp->if_ierrors++;
659 1.9.2.2 thorpej goto next_packet;
660 1.9.2.2 thorpej }
661 1.9.2.2 thorpej
662 1.9.2.2 thorpej /* Don't need crc. Must keep ether header for BPF */
663 1.9.2.2 thorpej m = se_get(sc, data, len - ETHER_CRC);
664 1.9.2.2 thorpej if (m == 0) {
665 1.9.2.2 thorpej #ifdef SEDEBUG
666 1.9.2.3 thorpej if (sc->sc_debug)
667 1.9.2.2 thorpej printf("se_read: se_get returned null\n");
668 1.9.2.2 thorpej #endif
669 1.9.2.2 thorpej ifp->if_ierrors++;
670 1.9.2.2 thorpej goto next_packet;
671 1.9.2.2 thorpej }
672 1.9.2.2 thorpej if ((ifp->if_flags & IFF_PROMISC) != 0) {
673 1.9.2.2 thorpej m_adj(m, SE_PREFIX);
674 1.9.2.2 thorpej }
675 1.9.2.2 thorpej ifp->if_ipackets++;
676 1.9.2.2 thorpej
677 1.9.2.2 thorpej /* We assume that the header fit entirely in one mbuf. */
678 1.9.2.2 thorpej eh = mtod(m, struct ether_header *);
679 1.9.2.2 thorpej
680 1.9.2.2 thorpej #if NBPFILTER > 0
681 1.9.2.2 thorpej /*
682 1.9.2.2 thorpej * Check if there's a BPF listener on this interface.
683 1.9.2.2 thorpej * If so, hand off the raw packet to BPF.
684 1.9.2.2 thorpej */
685 1.9.2.2 thorpej if (ifp->if_bpf) {
686 1.9.2.2 thorpej bpf_mtap(ifp->if_bpf, m);
687 1.9.2.2 thorpej
688 1.9.2.2 thorpej /* Note that the interface cannot be in
689 1.9.2.2 thorpej * promiscuous mode if there are no BPF
690 1.9.2.2 thorpej * listeners. And if we are in promiscuous
691 1.9.2.2 thorpej * mode, we have to check if this packet is
692 1.9.2.2 thorpej * really ours.
693 1.9.2.2 thorpej */
694 1.9.2.2 thorpej if ((ifp->if_flags & IFF_PROMISC) != 0 &&
695 1.9.2.2 thorpej (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
696 1.9.2.2 thorpej ETHER_CMP(eh->ether_dhost, LLADDR(ifp->if_sadl))) {
697 1.9.2.2 thorpej m_freem(m);
698 1.9.2.2 thorpej goto next_packet;
699 1.9.2.2 thorpej }
700 1.9.2.2 thorpej }
701 1.9.2.2 thorpej #endif
702 1.9.2.2 thorpej
703 1.9.2.2 thorpej /* Pass the packet up, with the ether header sort-of removed. */
704 1.9.2.2 thorpej m_adj(m, sizeof(struct ether_header));
705 1.9.2.2 thorpej ether_input(ifp, eh, m);
706 1.9.2.2 thorpej
707 1.9.2.2 thorpej next_packet:
708 1.9.2.2 thorpej data += len;
709 1.9.2.2 thorpej datalen -= len;
710 1.9.2.2 thorpej n++;
711 1.9.2.2 thorpej }
712 1.9.2.3 thorpej return (n);
713 1.9.2.2 thorpej }
714 1.9.2.2 thorpej
715 1.9.2.2 thorpej
716 1.9.2.2 thorpej static void
717 1.9.2.2 thorpej sewatchdog(ifp)
718 1.9.2.2 thorpej struct ifnet *ifp;
719 1.9.2.2 thorpej {
720 1.9.2.2 thorpej struct se_softc *sc = ifp->if_softc;
721 1.9.2.2 thorpej
722 1.9.2.2 thorpej log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
723 1.9.2.2 thorpej ++ifp->if_oerrors;
724 1.9.2.2 thorpej
725 1.9.2.2 thorpej se_reset(sc);
726 1.9.2.2 thorpej }
727 1.9.2.2 thorpej
728 1.9.2.2 thorpej static int
729 1.9.2.2 thorpej se_reset(sc)
730 1.9.2.2 thorpej struct se_softc *sc;
731 1.9.2.2 thorpej {
732 1.9.2.3 thorpej int error;
733 1.9.2.2 thorpej int s = splnet();
734 1.9.2.2 thorpej #if 0
735 1.9.2.2 thorpej /* Maybe we don't *really* want to reset the entire bus
736 1.9.2.2 thorpej * because the ctron isn't working. We would like to send a
737 1.9.2.2 thorpej * "BUS DEVICE RESET" message, but don't think the ctron
738 1.9.2.2 thorpej * understands it.
739 1.9.2.2 thorpej */
740 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link, 0, 0, 0, 0, SERETRIES, 2000, NULL,
741 1.9.2.2 thorpej SCSI_RESET);
742 1.9.2.2 thorpej #endif
743 1.9.2.2 thorpej error = se_init(sc);
744 1.9.2.2 thorpej splx(s);
745 1.9.2.3 thorpej return (error);
746 1.9.2.2 thorpej }
747 1.9.2.2 thorpej
748 1.9.2.2 thorpej static int
749 1.9.2.2 thorpej se_add_proto(sc, proto)
750 1.9.2.2 thorpej struct se_softc *sc;
751 1.9.2.2 thorpej int proto;
752 1.9.2.2 thorpej {
753 1.9.2.3 thorpej int error;
754 1.9.2.2 thorpej struct scsi_ctron_ether_generic add_proto_cmd;
755 1.9.2.2 thorpej u_int8_t data[2];
756 1.9.2.2 thorpej _lto2b(proto, data);
757 1.9.2.2 thorpej #ifdef SEDEBUG
758 1.9.2.2 thorpej if (sc->sc_debug)
759 1.9.2.2 thorpej printf("se: adding proto 0x%02x%02x\n", data[0], data[1]);
760 1.9.2.2 thorpej #endif
761 1.9.2.2 thorpej
762 1.9.2.2 thorpej PROTOCMD(ctron_ether_add_proto, add_proto_cmd);
763 1.9.2.2 thorpej _lto2b(sizeof(data), add_proto_cmd.length);
764 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
765 1.9.2.3 thorpej (struct scsipi_generic *) &add_proto_cmd, sizeof(add_proto_cmd),
766 1.9.2.3 thorpej data, sizeof(data), SERETRIES, SETIMEOUT, NULL, SCSI_DATA_OUT);
767 1.9.2.3 thorpej return (error);
768 1.9.2.2 thorpej }
769 1.9.2.2 thorpej
770 1.9.2.2 thorpej static int
771 1.9.2.2 thorpej se_get_addr(sc, myaddr)
772 1.9.2.2 thorpej struct se_softc *sc;
773 1.9.2.2 thorpej u_int8_t *myaddr;
774 1.9.2.2 thorpej {
775 1.9.2.3 thorpej int error;
776 1.9.2.2 thorpej struct scsi_ctron_ether_generic get_addr_cmd;
777 1.9.2.2 thorpej
778 1.9.2.2 thorpej PROTOCMD(ctron_ether_get_addr, get_addr_cmd);
779 1.9.2.2 thorpej _lto2b(ETHER_ADDR_LEN, get_addr_cmd.length);
780 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
781 1.9.2.3 thorpej (struct scsipi_generic *) &get_addr_cmd, sizeof(get_addr_cmd),
782 1.9.2.3 thorpej myaddr, ETHER_ADDR_LEN, SERETRIES, SETIMEOUT, NULL, SCSI_DATA_IN);
783 1.9.2.2 thorpej printf("%s: ethernet address %s\n", sc->sc_dev.dv_xname,
784 1.9.2.2 thorpej ether_sprintf(myaddr));
785 1.9.2.3 thorpej return (error);
786 1.9.2.2 thorpej }
787 1.9.2.2 thorpej
788 1.9.2.2 thorpej
789 1.9.2.2 thorpej static int
790 1.9.2.2 thorpej se_set_media(sc, type)
791 1.9.2.2 thorpej struct se_softc *sc;
792 1.9.2.2 thorpej int type;
793 1.9.2.2 thorpej {
794 1.9.2.3 thorpej int error;
795 1.9.2.2 thorpej struct scsi_ctron_ether_generic set_media_cmd;
796 1.9.2.2 thorpej
797 1.9.2.2 thorpej PROTOCMD(ctron_ether_set_media, set_media_cmd);
798 1.9.2.2 thorpej set_media_cmd.byte3 = type;
799 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
800 1.9.2.3 thorpej (struct scsipi_generic *) &set_media_cmd, sizeof(set_media_cmd),
801 1.9.2.3 thorpej 0, 0, SERETRIES, SETIMEOUT, NULL, 0);
802 1.9.2.3 thorpej return (error);
803 1.9.2.2 thorpej }
804 1.9.2.2 thorpej
805 1.9.2.2 thorpej static int
806 1.9.2.2 thorpej se_set_mode(sc, len, mode)
807 1.9.2.2 thorpej struct se_softc *sc;
808 1.9.2.2 thorpej int len;
809 1.9.2.2 thorpej int mode;
810 1.9.2.2 thorpej {
811 1.9.2.3 thorpej int error;
812 1.9.2.2 thorpej struct scsi_ctron_ether_set_mode set_mode_cmd;
813 1.9.2.2 thorpej
814 1.9.2.2 thorpej PROTOCMD(ctron_ether_set_mode, set_mode_cmd);
815 1.9.2.2 thorpej set_mode_cmd.mode = mode;
816 1.9.2.2 thorpej _lto2b(len, set_mode_cmd.length);
817 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
818 1.9.2.3 thorpej (struct scsipi_generic *) &set_mode_cmd, sizeof(set_mode_cmd),
819 1.9.2.3 thorpej 0, 0, SERETRIES, SETIMEOUT, NULL, 0);
820 1.9.2.3 thorpej return (error);
821 1.9.2.2 thorpej }
822 1.9.2.2 thorpej
823 1.9.2.2 thorpej
824 1.9.2.2 thorpej static int
825 1.9.2.2 thorpej se_init(sc)
826 1.9.2.2 thorpej struct se_softc *sc;
827 1.9.2.2 thorpej {
828 1.9.2.2 thorpej struct ifnet *ifp = &sc->sc_ethercom.ec_if;
829 1.9.2.2 thorpej struct scsi_ctron_ether_generic set_addr_cmd;
830 1.9.2.2 thorpej int error;
831 1.9.2.2 thorpej
832 1.9.2.2 thorpej #if NBPFILTER > 0
833 1.9.2.2 thorpej if (ifp->if_flags & IFF_PROMISC) {
834 1.9.2.2 thorpej error = se_set_mode(sc, MAX_SNAP, 1);
835 1.9.2.2 thorpej }
836 1.9.2.2 thorpej else
837 1.9.2.2 thorpej #endif
838 1.9.2.2 thorpej error = se_set_mode(sc, ETHERMTU + sizeof(struct ether_header),
839 1.9.2.3 thorpej 0);
840 1.9.2.2 thorpej if (error != 0)
841 1.9.2.3 thorpej return (error);
842 1.9.2.2 thorpej
843 1.9.2.2 thorpej PROTOCMD(ctron_ether_set_addr, set_addr_cmd);
844 1.9.2.2 thorpej _lto2b(ETHER_ADDR_LEN, set_addr_cmd.length);
845 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
846 1.9.2.3 thorpej (struct scsipi_generic *) &set_addr_cmd, sizeof(set_addr_cmd),
847 1.9.2.3 thorpej LLADDR(ifp->if_sadl), ETHER_ADDR_LEN, SERETRIES, SETIMEOUT, NULL,
848 1.9.2.3 thorpej SCSI_DATA_OUT);
849 1.9.2.3 thorpej if (error != 0)
850 1.9.2.3 thorpej return (error);
851 1.9.2.2 thorpej
852 1.9.2.2 thorpej if ((sc->protos & PROTO_IP) &&
853 1.9.2.2 thorpej (error = se_add_proto(sc, ETHERTYPE_IP)) != 0)
854 1.9.2.3 thorpej return (error);
855 1.9.2.2 thorpej if ((sc->protos & PROTO_ARP) &&
856 1.9.2.2 thorpej (error = se_add_proto(sc, ETHERTYPE_ARP)) != 0)
857 1.9.2.3 thorpej return (error);
858 1.9.2.2 thorpej if ((sc->protos & PROTO_REVARP) &&
859 1.9.2.2 thorpej (error = se_add_proto(sc, ETHERTYPE_REVARP)) != 0)
860 1.9.2.3 thorpej return (error);
861 1.9.2.2 thorpej #ifdef NETATALK
862 1.9.2.2 thorpej if ((sc->protos & PROTO_AT) &&
863 1.9.2.2 thorpej (error = se_add_proto(sc, ETHERTYPE_AT)) != 0)
864 1.9.2.3 thorpej return (error);
865 1.9.2.2 thorpej if ((sc->protos & PROTO_AARP) &&
866 1.9.2.2 thorpej (error = se_add_proto(sc, ETHERTYPE_AARP)) != 0)
867 1.9.2.3 thorpej return (error);
868 1.9.2.2 thorpej #endif
869 1.9.2.2 thorpej
870 1.9.2.2 thorpej if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == IFF_UP) {
871 1.9.2.2 thorpej ifp->if_flags |= IFF_RUNNING;
872 1.9.2.2 thorpej se_recv(sc);
873 1.9.2.2 thorpej ifp->if_flags &= ~IFF_OACTIVE;
874 1.9.2.2 thorpej se_ifstart(ifp);
875 1.9.2.2 thorpej }
876 1.9.2.3 thorpej return (error);
877 1.9.2.2 thorpej }
878 1.9.2.2 thorpej
879 1.9.2.2 thorpej static int
880 1.9.2.2 thorpej se_set_multi(sc, addr)
881 1.9.2.2 thorpej struct se_softc *sc;
882 1.9.2.2 thorpej u_int8_t *addr;
883 1.9.2.2 thorpej {
884 1.9.2.2 thorpej struct scsi_ctron_ether_generic set_multi_cmd;
885 1.9.2.2 thorpej int error;
886 1.9.2.2 thorpej
887 1.9.2.2 thorpej if (sc->sc_debug)
888 1.9.2.2 thorpej printf("%s: set_set_multi: %s\n", sc->sc_dev.dv_xname,
889 1.9.2.2 thorpej ether_sprintf(addr));
890 1.9.2.2 thorpej
891 1.9.2.2 thorpej PROTOCMD(ctron_ether_set_multi, set_multi_cmd);
892 1.9.2.2 thorpej _lto2b(sizeof(addr), set_multi_cmd.length);
893 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
894 1.9.2.3 thorpej (struct scsipi_generic *) &set_multi_cmd, sizeof(set_multi_cmd),
895 1.9.2.3 thorpej addr, sizeof(addr), SERETRIES, SETIMEOUT, NULL, SCSI_DATA_OUT);
896 1.9.2.3 thorpej return (error);
897 1.9.2.2 thorpej }
898 1.9.2.2 thorpej
899 1.9.2.2 thorpej static int
900 1.9.2.2 thorpej se_remove_multi(sc, addr)
901 1.9.2.2 thorpej struct se_softc *sc;
902 1.9.2.2 thorpej u_int8_t *addr;
903 1.9.2.2 thorpej {
904 1.9.2.2 thorpej struct scsi_ctron_ether_generic remove_multi_cmd;
905 1.9.2.2 thorpej int error;
906 1.9.2.2 thorpej
907 1.9.2.2 thorpej if (sc->sc_debug)
908 1.9.2.2 thorpej printf("%s: se_remove_multi: %s\n", sc->sc_dev.dv_xname,
909 1.9.2.2 thorpej ether_sprintf(addr));
910 1.9.2.2 thorpej
911 1.9.2.2 thorpej PROTOCMD(ctron_ether_remove_multi, remove_multi_cmd);
912 1.9.2.2 thorpej _lto2b(sizeof(addr), remove_multi_cmd.length);
913 1.9.2.2 thorpej error = se_scsipi_cmd(sc->sc_link,
914 1.9.2.3 thorpej (struct scsipi_generic *) &remove_multi_cmd,
915 1.9.2.3 thorpej sizeof(remove_multi_cmd),
916 1.9.2.3 thorpej addr, sizeof(addr), SERETRIES, SETIMEOUT, NULL, SCSI_DATA_OUT);
917 1.9.2.3 thorpej return (error);
918 1.9.2.2 thorpej }
919 1.9.2.2 thorpej
920 1.9.2.2 thorpej #if 0 /* not used --thorpej */
921 1.9.2.2 thorpej static int
922 1.9.2.2 thorpej sc_set_all_multi(sc, set)
923 1.9.2.2 thorpej struct se_softc *sc;
924 1.9.2.2 thorpej int set;
925 1.9.2.2 thorpej {
926 1.9.2.2 thorpej int error = 0;
927 1.9.2.2 thorpej u_int8_t *addr;
928 1.9.2.2 thorpej struct ethercom *ac = &sc->sc_ethercom;
929 1.9.2.2 thorpej struct ether_multi *enm;
930 1.9.2.2 thorpej struct ether_multistep step;
931 1.9.2.3 thorpej
932 1.9.2.2 thorpej ETHER_FIRST_MULTI(step, ac, enm);
933 1.9.2.2 thorpej while (enm != NULL) {
934 1.9.2.2 thorpej if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {
935 1.9.2.2 thorpej /*
936 1.9.2.2 thorpej * We must listen to a range of multicast addresses.
937 1.9.2.2 thorpej * For now, just accept all multicasts, rather than
938 1.9.2.2 thorpej * trying to set only those filter bits needed to match
939 1.9.2.2 thorpej * the range. (At this time, the only use of address
940 1.9.2.2 thorpej * ranges is for IP multicast routing, for which the
941 1.9.2.2 thorpej * range is big enough to require all bits set.)
942 1.9.2.2 thorpej */
943 1.9.2.2 thorpej /* We have no way of adding a range to this device.
944 1.9.2.2 thorpej * stepping through all addresses in the range is
945 1.9.2.2 thorpej * typically not possible. The only real alternative
946 1.9.2.2 thorpej * is to go into promicuous mode and filter by hand.
947 1.9.2.2 thorpej */
948 1.9.2.3 thorpej return (ENODEV);
949 1.9.2.2 thorpej
950 1.9.2.2 thorpej }
951 1.9.2.2 thorpej
952 1.9.2.2 thorpej addr = enm->enm_addrlo;
953 1.9.2.3 thorpej if ((error = set ? se_set_multi(sc, addr) :
954 1.9.2.3 thorpej se_remove_multi(sc, addr)) != 0)
955 1.9.2.3 thorpej return (error);
956 1.9.2.2 thorpej ETHER_NEXT_MULTI(step, enm);
957 1.9.2.2 thorpej }
958 1.9.2.3 thorpej return (error);
959 1.9.2.2 thorpej }
960 1.9.2.2 thorpej #endif /* not used */
961 1.9.2.2 thorpej
962 1.9.2.2 thorpej static void
963 1.9.2.2 thorpej se_stop(sc)
964 1.9.2.2 thorpej struct se_softc *sc;
965 1.9.2.2 thorpej {
966 1.9.2.3 thorpej
967 1.9.2.2 thorpej /* Don't schedule any reads */
968 1.9.2.2 thorpej untimeout(se_recv, sc);
969 1.9.2.2 thorpej
970 1.9.2.2 thorpej /* How can we abort any scsi cmds in progress? */
971 1.9.2.2 thorpej }
972 1.9.2.2 thorpej
973 1.9.2.2 thorpej
974 1.9.2.2 thorpej /*
975 1.9.2.2 thorpej * Process an ioctl request.
976 1.9.2.2 thorpej */
977 1.9.2.2 thorpej static int
978 1.9.2.2 thorpej se_ioctl(ifp, cmd, data)
979 1.9.2.2 thorpej register struct ifnet *ifp;
980 1.9.2.2 thorpej u_long cmd;
981 1.9.2.2 thorpej caddr_t data;
982 1.9.2.2 thorpej {
983 1.9.2.2 thorpej register struct se_softc *sc = ifp->if_softc;
984 1.9.2.2 thorpej struct ifaddr *ifa = (struct ifaddr *)data;
985 1.9.2.2 thorpej struct ifreq *ifr = (struct ifreq *)data;
986 1.9.2.2 thorpej int s, error = 0;
987 1.9.2.2 thorpej
988 1.9.2.2 thorpej s = splnet();
989 1.9.2.2 thorpej
990 1.9.2.2 thorpej switch (cmd) {
991 1.9.2.2 thorpej
992 1.9.2.2 thorpej case SIOCSIFADDR:
993 1.9.2.2 thorpej ifp->if_flags |= IFF_UP;
994 1.9.2.2 thorpej
995 1.9.2.2 thorpej if ((error = se_set_media(sc, CMEDIA_AUTOSENSE) != 0))
996 1.9.2.3 thorpej return (error);
997 1.9.2.2 thorpej
998 1.9.2.2 thorpej switch (ifa->ifa_addr->sa_family) {
999 1.9.2.2 thorpej #ifdef INET
1000 1.9.2.2 thorpej case AF_INET:
1001 1.9.2.2 thorpej sc->protos |= (PROTO_IP | PROTO_ARP | PROTO_REVARP);
1002 1.9.2.2 thorpej if ((error = se_init(sc)) != 0)
1003 1.9.2.2 thorpej break;
1004 1.9.2.2 thorpej arp_ifinit(ifp, ifa);
1005 1.9.2.2 thorpej break;
1006 1.9.2.2 thorpej #endif
1007 1.9.2.2 thorpej #ifdef NS
1008 1.9.2.2 thorpej case AF_NS:
1009 1.9.2.2 thorpej {
1010 1.9.2.2 thorpej register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1011 1.9.2.2 thorpej
1012 1.9.2.2 thorpej if (ns_nullhost(*ina))
1013 1.9.2.2 thorpej ina->x_host =
1014 1.9.2.2 thorpej *(union ns_host *)LLADDR(ifp->if_sadl);
1015 1.9.2.2 thorpej else
1016 1.9.2.2 thorpej bcopy(ina->x_host.c_host,
1017 1.9.2.2 thorpej LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
1018 1.9.2.2 thorpej /* Set new address. */
1019 1.9.2.2 thorpej
1020 1.9.2.2 thorpej error = se_init(sc);
1021 1.9.2.2 thorpej break;
1022 1.9.2.2 thorpej }
1023 1.9.2.2 thorpej #endif
1024 1.9.2.2 thorpej #ifdef NETATALK
1025 1.9.2.2 thorpej case AF_APPLETALK:
1026 1.9.2.2 thorpej sc->protos |= (PROTO_AT | PROTO_AARP);
1027 1.9.2.2 thorpej if ((error = se_init(sc)) != 0)
1028 1.9.2.2 thorpej break;
1029 1.9.2.2 thorpej break;
1030 1.9.2.2 thorpej #endif
1031 1.9.2.2 thorpej default:
1032 1.9.2.2 thorpej error = se_init(sc);
1033 1.9.2.2 thorpej break;
1034 1.9.2.2 thorpej }
1035 1.9.2.2 thorpej break;
1036 1.9.2.2 thorpej
1037 1.9.2.2 thorpej #if defined(CCITT) && defined(LLC)
1038 1.9.2.2 thorpej case SIOCSIFCONF_X25:
1039 1.9.2.2 thorpej ifp->if_flags |= IFF_UP;
1040 1.9.2.2 thorpej ifa->ifa_rtrequest = cons_rtrequest; /* XXX */
1041 1.9.2.2 thorpej error = x25_llcglue(PRC_IFUP, ifa->ifa_addr);
1042 1.9.2.2 thorpej if (error == 0)
1043 1.9.2.2 thorpej error = se_init(sc);
1044 1.9.2.2 thorpej break;
1045 1.9.2.2 thorpej #endif /* CCITT && LLC */
1046 1.9.2.2 thorpej
1047 1.9.2.2 thorpej case SIOCSIFFLAGS:
1048 1.9.2.2 thorpej if ((ifp->if_flags & IFF_UP) == 0 &&
1049 1.9.2.2 thorpej (ifp->if_flags & IFF_RUNNING) != 0) {
1050 1.9.2.2 thorpej /*
1051 1.9.2.2 thorpej * If interface is marked down and it is running, then
1052 1.9.2.2 thorpej * stop it.
1053 1.9.2.2 thorpej */
1054 1.9.2.2 thorpej se_stop(sc);
1055 1.9.2.2 thorpej ifp->if_flags &= ~IFF_RUNNING;
1056 1.9.2.2 thorpej } else if ((ifp->if_flags & IFF_UP) != 0 &&
1057 1.9.2.2 thorpej (ifp->if_flags & IFF_RUNNING) == 0) {
1058 1.9.2.2 thorpej /*
1059 1.9.2.2 thorpej * If interface is marked up and it is stopped, then
1060 1.9.2.2 thorpej * start it.
1061 1.9.2.2 thorpej */
1062 1.9.2.2 thorpej error = se_init(sc);
1063 1.9.2.2 thorpej } else {
1064 1.9.2.2 thorpej /*
1065 1.9.2.2 thorpej * Reset the interface to pick up changes in any other
1066 1.9.2.2 thorpej * flags that affect hardware registers.
1067 1.9.2.2 thorpej */
1068 1.9.2.2 thorpej error = se_init(sc);
1069 1.9.2.2 thorpej }
1070 1.9.2.2 thorpej #ifdef SEDEBUG
1071 1.9.2.2 thorpej if (ifp->if_flags & IFF_DEBUG)
1072 1.9.2.2 thorpej sc->sc_debug = 1;
1073 1.9.2.2 thorpej else
1074 1.9.2.2 thorpej sc->sc_debug = 0;
1075 1.9.2.2 thorpej #endif
1076 1.9.2.2 thorpej break;
1077 1.9.2.2 thorpej
1078 1.9.2.2 thorpej case SIOCADDMULTI:
1079 1.9.2.3 thorpej if (ether_addmulti(ifr, &sc->sc_ethercom) == ENETRESET)
1080 1.9.2.2 thorpej error = se_set_multi(sc, ifr->ifr_addr.sa_data);
1081 1.9.2.3 thorpej else
1082 1.9.2.2 thorpej error = 0;
1083 1.9.2.2 thorpej break;
1084 1.9.2.2 thorpej case SIOCDELMULTI:
1085 1.9.2.3 thorpej if (ether_delmulti(ifr, &sc->sc_ethercom) == ENETRESET)
1086 1.9.2.2 thorpej error = se_remove_multi(sc, ifr->ifr_addr.sa_data);
1087 1.9.2.3 thorpej else
1088 1.9.2.2 thorpej error = 0;
1089 1.9.2.2 thorpej break;
1090 1.9.2.2 thorpej
1091 1.9.2.2 thorpej default:
1092 1.9.2.2 thorpej
1093 1.9.2.2 thorpej error = EINVAL;
1094 1.9.2.2 thorpej break;
1095 1.9.2.2 thorpej }
1096 1.9.2.2 thorpej
1097 1.9.2.2 thorpej splx(s);
1098 1.9.2.2 thorpej return (error);
1099 1.9.2.2 thorpej }
1100 1.9.2.2 thorpej
1101 1.9.2.2 thorpej #define SEUNIT(z) (minor(z))
1102 1.9.2.2 thorpej /*
1103 1.9.2.2 thorpej * open the device.
1104 1.9.2.2 thorpej */
1105 1.9.2.2 thorpej int
1106 1.9.2.2 thorpej seopen(dev, flag, fmt, p)
1107 1.9.2.2 thorpej dev_t dev;
1108 1.9.2.2 thorpej int flag, fmt;
1109 1.9.2.2 thorpej struct proc *p;
1110 1.9.2.2 thorpej {
1111 1.9.2.2 thorpej int unit;
1112 1.9.2.2 thorpej struct se_softc *sc;
1113 1.9.2.2 thorpej struct scsipi_link *sc_link;
1114 1.9.2.2 thorpej
1115 1.9.2.2 thorpej unit = SEUNIT(dev);
1116 1.9.2.2 thorpej if (unit >= se_cd.cd_ndevs)
1117 1.9.2.3 thorpej return (ENXIO);
1118 1.9.2.2 thorpej sc = se_cd.cd_devs[unit];
1119 1.9.2.3 thorpej if (sc == NULL)
1120 1.9.2.3 thorpej return (ENXIO);
1121 1.9.2.2 thorpej
1122 1.9.2.2 thorpej sc_link = sc->sc_link;
1123 1.9.2.2 thorpej
1124 1.9.2.2 thorpej SC_DEBUG(sc_link, SDEV_DB1,
1125 1.9.2.3 thorpej ("scopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
1126 1.9.2.3 thorpej se_cd.cd_ndevs));
1127 1.9.2.2 thorpej
1128 1.9.2.2 thorpej sc_link->flags |= SDEV_OPEN;
1129 1.9.2.2 thorpej
1130 1.9.2.2 thorpej SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
1131 1.9.2.3 thorpej return (0);
1132 1.9.2.2 thorpej }
1133 1.9.2.2 thorpej
1134 1.9.2.2 thorpej /*
1135 1.9.2.2 thorpej * close the device.. only called if we are the LAST
1136 1.9.2.2 thorpej * occurence of an open device
1137 1.9.2.2 thorpej */
1138 1.9.2.2 thorpej int
1139 1.9.2.2 thorpej seclose(dev, flag, fmt, p)
1140 1.9.2.2 thorpej dev_t dev;
1141 1.9.2.2 thorpej int flag, fmt;
1142 1.9.2.2 thorpej struct proc *p;
1143 1.9.2.2 thorpej {
1144 1.9.2.2 thorpej struct se_softc *sc = se_cd.cd_devs[SEUNIT(dev)];
1145 1.9.2.2 thorpej
1146 1.9.2.2 thorpej SC_DEBUG(sc->sc_link, SDEV_DB1, ("closing\n"));
1147 1.9.2.2 thorpej sc->sc_link->flags &= ~SDEV_OPEN;
1148 1.9.2.2 thorpej
1149 1.9.2.3 thorpej return (0);
1150 1.9.2.2 thorpej }
1151 1.9.2.2 thorpej
1152 1.9.2.2 thorpej /*
1153 1.9.2.2 thorpej * Perform special action on behalf of the user
1154 1.9.2.2 thorpej * Only does generic scsi ioctls.
1155 1.9.2.2 thorpej */
1156 1.9.2.2 thorpej int
1157 1.9.2.2 thorpej seioctl(dev, cmd, addr, flag, p)
1158 1.9.2.2 thorpej dev_t dev;
1159 1.9.2.2 thorpej u_long cmd;
1160 1.9.2.2 thorpej caddr_t addr;
1161 1.9.2.2 thorpej int flag;
1162 1.9.2.2 thorpej struct proc *p;
1163 1.9.2.2 thorpej {
1164 1.9.2.2 thorpej register struct se_softc *sc = se_cd.cd_devs[SEUNIT(dev)];
1165 1.9.2.2 thorpej
1166 1.9.2.3 thorpej return (scsipi_do_ioctl(sc->sc_link, dev, cmd, addr, flag, p));
1167 1.9.2.2 thorpej }
1168