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