Home | History | Annotate | Line # | Download | only in scsipi
st_scsi.c revision 1.10.8.1
      1  1.10.8.1       he /*	$NetBSD: st_scsi.c,v 1.10.8.1 2004/09/11 12:59:02 he Exp $ */
      2       1.1   bouyer 
      3       1.1   bouyer /*-
      4       1.1   bouyer  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1   bouyer  * All rights reserved.
      6       1.1   bouyer  *
      7       1.1   bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   bouyer  * by Charles M. Hannum.
      9       1.1   bouyer  *
     10       1.1   bouyer  * Redistribution and use in source and binary forms, with or without
     11       1.1   bouyer  * modification, are permitted provided that the following conditions
     12       1.1   bouyer  * are met:
     13       1.1   bouyer  * 1. Redistributions of source code must retain the above copyright
     14       1.1   bouyer  *    notice, this list of conditions and the following disclaimer.
     15       1.1   bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   bouyer  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   bouyer  *    documentation and/or other materials provided with the distribution.
     18       1.1   bouyer  * 3. All advertising materials mentioning features or use of this software
     19       1.1   bouyer  *    must display the following acknowledgement:
     20       1.1   bouyer  *        This product includes software developed by the NetBSD
     21       1.1   bouyer  *        Foundation, Inc. and its contributors.
     22       1.1   bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   bouyer  *    contributors may be used to endorse or promote products derived
     24       1.1   bouyer  *    from this software without specific prior written permission.
     25       1.1   bouyer  *
     26       1.1   bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   bouyer  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   bouyer  */
     38       1.1   bouyer 
     39       1.1   bouyer /*
     40       1.1   bouyer  * Originally written by Julian Elischer (julian (at) tfs.com)
     41       1.1   bouyer  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     42       1.1   bouyer  *
     43       1.1   bouyer  * TRW Financial Systems, in accordance with their agreement with Carnegie
     44       1.1   bouyer  * Mellon University, makes this software available to CMU to distribute
     45       1.1   bouyer  * or use in any manner that they see fit as long as this message is kept with
     46       1.1   bouyer  * the software. For this reason TFS also grants any other persons or
     47       1.1   bouyer  * organisations permission to use or modify this software.
     48       1.1   bouyer  *
     49       1.1   bouyer  * TFS supplies this software to be publicly redistributed
     50       1.1   bouyer  * on the understanding that TFS is not responsible for the correct
     51       1.1   bouyer  * functioning of this software in any circumstances.
     52       1.1   bouyer  *
     53       1.1   bouyer  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     54       1.1   bouyer  * major changes by Julian Elischer (julian (at) jules.dialix.oz.au) May 1993
     55       1.1   bouyer  *
     56       1.1   bouyer  * A lot of rewhacking done by mjacob (mjacob (at) nas.nasa.gov).
     57       1.1   bouyer  */
     58       1.5    lukem 
     59       1.5    lukem #include <sys/cdefs.h>
     60  1.10.8.1       he __KERNEL_RCSID(0, "$NetBSD: st_scsi.c,v 1.10.8.1 2004/09/11 12:59:02 he Exp $");
     61       1.1   bouyer 
     62       1.1   bouyer #include "opt_scsi.h"
     63       1.1   bouyer #include "rnd.h"
     64       1.1   bouyer 
     65       1.1   bouyer #include <sys/param.h>
     66       1.1   bouyer #include <sys/device.h>
     67       1.1   bouyer #include <sys/buf.h>
     68       1.1   bouyer #include <sys/conf.h>
     69       1.1   bouyer #include <sys/kernel.h>
     70       1.2   bouyer #include <sys/systm.h>
     71       1.1   bouyer 
     72       1.1   bouyer #include <dev/scsipi/stvar.h>
     73       1.2   bouyer #include <dev/scsipi/scsi_tape.h>
     74       1.2   bouyer #include <dev/scsipi/scsi_all.h>
     75       1.1   bouyer 
     76       1.1   bouyer int	st_scsibus_match __P((struct device *, struct cfdata *, void *));
     77       1.2   bouyer void	st_scsibus_attach __P((struct device *, struct device *, void *));
     78       1.2   bouyer int	st_scsibus_ops __P((struct st_softc *, int, int));
     79       1.2   bouyer int	st_scsibus_read_block_limits __P((struct st_softc *, int));
     80       1.2   bouyer int	st_scsibus_mode_sense __P((struct st_softc *, int));
     81       1.2   bouyer int	st_scsibus_mode_select __P((struct st_softc *, int));
     82       1.2   bouyer int	st_scsibus_cmprss __P((struct st_softc *, int, int));
     83       1.1   bouyer 
     84       1.9  thorpej CFATTACH_DECL(st_scsibus, sizeof(struct st_softc),
     85      1.10  thorpej     st_scsibus_match, st_scsibus_attach, stdetach, stactivate);
     86       1.1   bouyer 
     87       1.1   bouyer const struct scsipi_inquiry_pattern st_scsibus_patterns[] = {
     88       1.1   bouyer 	{T_SEQUENTIAL, T_REMOV,
     89       1.1   bouyer 	 "",         "",                 ""},
     90       1.1   bouyer };
     91       1.1   bouyer 
     92       1.1   bouyer int
     93       1.1   bouyer st_scsibus_match(parent, match, aux)
     94       1.1   bouyer 	struct device *parent;
     95       1.1   bouyer 	struct cfdata *match;
     96       1.1   bouyer 	void *aux;
     97       1.1   bouyer {
     98       1.1   bouyer 	struct scsipibus_attach_args *sa = aux;
     99       1.1   bouyer 	int priority;
    100       1.1   bouyer 
    101       1.2   bouyer 	if (scsipi_periph_bustype(sa->sa_periph) != SCSIPI_BUSTYPE_SCSI)
    102       1.2   bouyer 		return (0);
    103       1.2   bouyer 
    104       1.1   bouyer 	(void)scsipi_inqmatch(&sa->sa_inqbuf,
    105       1.1   bouyer 	    (caddr_t)st_scsibus_patterns,
    106       1.1   bouyer 	    sizeof(st_scsibus_patterns)/sizeof(st_scsibus_patterns[0]),
    107       1.1   bouyer 	    sizeof(st_scsibus_patterns[0]), &priority);
    108       1.1   bouyer 	return (priority);
    109       1.2   bouyer }
    110       1.2   bouyer 
    111       1.2   bouyer void
    112       1.2   bouyer st_scsibus_attach(parent, self, aux)
    113       1.2   bouyer 	struct device *parent, *self;
    114       1.2   bouyer 	void *aux;
    115       1.2   bouyer {
    116       1.2   bouyer 	struct st_softc *st = (void *)self;
    117       1.2   bouyer 
    118       1.2   bouyer 	st->ops = st_scsibus_ops;
    119       1.2   bouyer 	stattach(parent, st, aux);
    120       1.2   bouyer }
    121       1.2   bouyer 
    122       1.2   bouyer int
    123       1.2   bouyer st_scsibus_ops(st, op, flags)
    124       1.2   bouyer 	struct st_softc *st;
    125       1.2   bouyer 	int op;
    126       1.2   bouyer 	int flags;
    127       1.2   bouyer {
    128       1.2   bouyer 	switch(op) {
    129       1.2   bouyer 	case ST_OPS_RBL:
    130       1.2   bouyer 		return st_scsibus_read_block_limits(st, flags);
    131       1.2   bouyer 	case ST_OPS_MODESENSE:
    132       1.2   bouyer 		return st_scsibus_mode_sense(st, flags);
    133       1.2   bouyer 	case ST_OPS_MODESELECT:
    134       1.2   bouyer 		return st_scsibus_mode_select(st, flags);
    135       1.2   bouyer 	case ST_OPS_CMPRSS_ON:
    136       1.2   bouyer 	case ST_OPS_CMPRSS_OFF:
    137       1.2   bouyer 		return st_scsibus_cmprss(st, flags,
    138       1.2   bouyer 		    (op == ST_OPS_CMPRSS_ON) ? 1 : 0);
    139       1.2   bouyer 	default:
    140       1.2   bouyer 		panic("st_scsibus_ops: invalid op");
    141       1.2   bouyer 		return 0; /* XXX to appease gcc */
    142       1.2   bouyer 	}
    143       1.2   bouyer 	/* NOTREACHED */
    144       1.2   bouyer }
    145       1.2   bouyer 
    146       1.2   bouyer /*
    147       1.2   bouyer  * Ask the drive what it's min and max blk sizes are.
    148       1.2   bouyer  */
    149       1.2   bouyer int
    150       1.2   bouyer st_scsibus_read_block_limits(st, flags)
    151       1.2   bouyer 	struct st_softc *st;
    152       1.2   bouyer 	int flags;
    153       1.2   bouyer {
    154       1.2   bouyer 	struct scsi_block_limits cmd;
    155       1.2   bouyer 	struct scsi_block_limits_data block_limits;
    156       1.2   bouyer 	struct scsipi_periph *periph = st->sc_periph;
    157       1.2   bouyer 	int error;
    158       1.2   bouyer 
    159       1.2   bouyer 	/*
    160       1.2   bouyer 	 * do a 'Read Block Limits'
    161       1.2   bouyer 	 */
    162       1.3  thorpej 	memset(&cmd, 0, sizeof(cmd));
    163       1.2   bouyer 	cmd.opcode = READ_BLOCK_LIMITS;
    164       1.2   bouyer 
    165       1.2   bouyer 	/*
    166       1.2   bouyer 	 * do the command, update the global values
    167       1.2   bouyer 	 */
    168  1.10.8.1       he 	error = scsipi_command(periph, NULL, (struct scsipi_generic *)&cmd,
    169       1.2   bouyer 	    sizeof(cmd), (u_char *)&block_limits, sizeof(block_limits),
    170       1.2   bouyer 	    ST_RETRIES, ST_CTL_TIME, NULL,
    171       1.2   bouyer 	    flags | XS_CTL_DATA_IN | XS_CTL_DATA_ONSTACK);
    172       1.2   bouyer 	if (error)
    173       1.2   bouyer 		return (error);
    174       1.2   bouyer 
    175       1.2   bouyer 	st->blkmin = _2btol(block_limits.min_length);
    176       1.2   bouyer 	st->blkmax = _3btol(block_limits.max_length);
    177       1.2   bouyer 
    178       1.2   bouyer 	SC_DEBUG(periph, SCSIPI_DB3,
    179       1.2   bouyer 	    ("(%d <= blksize <= %d)\n", st->blkmin, st->blkmax));
    180       1.2   bouyer 	return (0);
    181       1.2   bouyer }
    182       1.2   bouyer 
    183       1.2   bouyer /*
    184       1.2   bouyer  * Get the scsi driver to send a full inquiry to the
    185       1.2   bouyer  * device and use the results to fill out the global
    186       1.2   bouyer  * parameter structure.
    187       1.2   bouyer  *
    188       1.2   bouyer  * called from:
    189       1.2   bouyer  * attach
    190       1.2   bouyer  * open
    191       1.2   bouyer  * ioctl (to reset original blksize)
    192       1.2   bouyer  */
    193       1.2   bouyer int
    194       1.2   bouyer st_scsibus_mode_sense(st, flags)
    195       1.2   bouyer 	struct st_softc *st;
    196       1.2   bouyer 	int flags;
    197       1.2   bouyer {
    198       1.2   bouyer 	u_int scsipi_sense_len;
    199       1.2   bouyer 	int error;
    200       1.2   bouyer 	struct scsipi_sense {
    201       1.2   bouyer 		struct scsipi_mode_header header;
    202       1.2   bouyer 		struct scsi_blk_desc blk_desc;
    203       1.2   bouyer 		u_char sense_data[MAX_PAGE_0_SIZE];
    204       1.2   bouyer 	} scsipi_sense;
    205       1.2   bouyer 	struct scsipi_periph *periph = st->sc_periph;
    206       1.2   bouyer 
    207       1.2   bouyer 	scsipi_sense_len = 12 + st->page_0_size;
    208       1.2   bouyer 
    209       1.2   bouyer 	/*
    210       1.2   bouyer 	 * Set up a mode sense
    211       1.2   bouyer 	 * We don't need the results. Just print them for our interest's sake,
    212       1.2   bouyer 	 * if asked, or if we need it as a template for the mode select store
    213       1.2   bouyer 	 * it away.
    214       1.2   bouyer 	 */
    215       1.2   bouyer 	error = scsipi_mode_sense(st->sc_periph, 0, SMS_PAGE_CTRL_CURRENT,
    216       1.2   bouyer 	    &scsipi_sense.header, scsipi_sense_len, flags | XS_CTL_DATA_ONSTACK,
    217       1.2   bouyer 	    ST_RETRIES, ST_CTL_TIME);
    218       1.2   bouyer 	if (error)
    219       1.2   bouyer 		return (error);
    220       1.2   bouyer 
    221       1.2   bouyer 	st->numblks = _3btol(scsipi_sense.blk_desc.nblocks);
    222       1.2   bouyer 	st->media_blksize = _3btol(scsipi_sense.blk_desc.blklen);
    223       1.2   bouyer 	st->media_density = scsipi_sense.blk_desc.density;
    224       1.2   bouyer 	if (scsipi_sense.header.dev_spec & SMH_DSP_WRITE_PROT)
    225       1.2   bouyer 		st->flags |= ST_READONLY;
    226       1.2   bouyer 	else
    227       1.2   bouyer 		st->flags &= ~ST_READONLY;
    228       1.2   bouyer 	SC_DEBUG(periph, SCSIPI_DB3,
    229       1.2   bouyer 	    ("density code %d, %d-byte blocks, write-%s, ",
    230       1.2   bouyer 	    st->media_density, st->media_blksize,
    231       1.2   bouyer 	    st->flags & ST_READONLY ? "protected" : "enabled"));
    232       1.2   bouyer 	SC_DEBUG(periph, SCSIPI_DB3,
    233       1.2   bouyer 	    ("%sbuffered\n",
    234       1.2   bouyer 	    scsipi_sense.header.dev_spec & SMH_DSP_BUFF_MODE ? "" : "un"));
    235       1.2   bouyer 	if (st->page_0_size)
    236       1.4  thorpej 		memcpy(st->sense_data, scsipi_sense.sense_data,
    237       1.2   bouyer 		    st->page_0_size);
    238       1.2   bouyer 	periph->periph_flags |= PERIPH_MEDIA_LOADED;
    239       1.2   bouyer 	return (0);
    240       1.2   bouyer }
    241       1.2   bouyer 
    242       1.2   bouyer /*
    243       1.2   bouyer  * Send a filled out parameter structure to the drive to
    244       1.2   bouyer  * set it into the desire modes etc.
    245       1.2   bouyer  */
    246       1.2   bouyer int
    247       1.2   bouyer st_scsibus_mode_select(st, flags)
    248       1.2   bouyer 	struct st_softc *st;
    249       1.2   bouyer 	int flags;
    250       1.2   bouyer {
    251       1.2   bouyer 	u_int scsi_select_len;
    252       1.2   bouyer 	struct scsi_select {
    253       1.2   bouyer 		struct scsipi_mode_header header;
    254       1.2   bouyer 		struct scsi_blk_desc blk_desc;
    255       1.2   bouyer 		u_char sense_data[MAX_PAGE_0_SIZE];
    256       1.2   bouyer 	} scsi_select;
    257       1.2   bouyer 	struct scsipi_periph *periph = st->sc_periph;
    258       1.2   bouyer 
    259       1.2   bouyer 	scsi_select_len = 12 + st->page_0_size;
    260       1.2   bouyer 
    261       1.2   bouyer 	/*
    262       1.2   bouyer 	 * This quirk deals with drives that have only one valid mode
    263       1.2   bouyer 	 * and think this gives them license to reject all mode selects,
    264       1.2   bouyer 	 * even if the selected mode is the one that is supported.
    265       1.2   bouyer 	 */
    266       1.2   bouyer 	if (st->quirks & ST_Q_UNIMODAL) {
    267       1.2   bouyer 		SC_DEBUG(periph, SCSIPI_DB3,
    268       1.2   bouyer 		    ("not setting density 0x%x blksize 0x%x\n",
    269       1.2   bouyer 		    st->density, st->blksize));
    270       1.2   bouyer 		return (0);
    271       1.2   bouyer 	}
    272       1.2   bouyer 
    273       1.2   bouyer 	/*
    274       1.2   bouyer 	 * Set up for a mode select
    275       1.2   bouyer 	 */
    276       1.3  thorpej 	memset(&scsi_select, 0, scsi_select_len);
    277       1.2   bouyer 	scsi_select.header.blk_desc_len = sizeof(struct scsi_blk_desc);
    278       1.2   bouyer 	scsi_select.header.dev_spec &= ~SMH_DSP_BUFF_MODE;
    279       1.2   bouyer 	scsi_select.blk_desc.density = st->density;
    280       1.2   bouyer 	if (st->flags & ST_DONTBUFFER)
    281       1.2   bouyer 		scsi_select.header.dev_spec |= SMH_DSP_BUFF_MODE_OFF;
    282       1.2   bouyer 	else
    283       1.2   bouyer 		scsi_select.header.dev_spec |= SMH_DSP_BUFF_MODE_ON;
    284       1.2   bouyer 	if (st->flags & ST_FIXEDBLOCKS)
    285       1.2   bouyer 		_lto3b(st->blksize, scsi_select.blk_desc.blklen);
    286       1.2   bouyer 	if (st->page_0_size)
    287       1.4  thorpej 		memcpy(scsi_select.sense_data, st->sense_data, st->page_0_size);
    288       1.2   bouyer 
    289       1.2   bouyer 	/*
    290       1.2   bouyer 	 * do the command
    291       1.2   bouyer 	 */
    292       1.2   bouyer 	return scsipi_mode_select(periph, 0, &scsi_select.header,
    293       1.2   bouyer 	    scsi_select_len, flags | XS_CTL_DATA_ONSTACK,
    294       1.2   bouyer 	    ST_RETRIES, ST_CTL_TIME);
    295       1.2   bouyer }
    296       1.2   bouyer 
    297       1.2   bouyer int
    298       1.2   bouyer st_scsibus_cmprss(st, flags, onoff)
    299       1.2   bouyer 	struct st_softc *st;
    300       1.2   bouyer 	int flags;
    301       1.2   bouyer 	int onoff;
    302       1.2   bouyer {
    303       1.2   bouyer 	u_int scsi_dlen;
    304       1.2   bouyer 	int byte2, page;
    305       1.2   bouyer 	struct scsi_select {
    306       1.2   bouyer 		struct scsipi_mode_header header;
    307       1.2   bouyer 		struct scsi_blk_desc blk_desc;
    308       1.2   bouyer 		u_char pdata[MAX(sizeof(struct scsi_tape_dev_conf_page),
    309       1.2   bouyer 		    sizeof(struct scsi_tape_dev_compression_page))];
    310       1.2   bouyer 	} scsi_pdata;
    311       1.2   bouyer 	struct scsi_tape_dev_conf_page *ptr;
    312       1.2   bouyer 	struct scsi_tape_dev_compression_page *cptr;
    313       1.2   bouyer 	struct scsipi_periph *periph = st->sc_periph;
    314       1.2   bouyer 	int error, ison;
    315       1.2   bouyer 
    316       1.2   bouyer 	scsi_dlen = sizeof(scsi_pdata);
    317       1.2   bouyer 	/*
    318       1.2   bouyer 	 * Do DATA COMPRESSION page first.
    319       1.2   bouyer 	 */
    320       1.2   bouyer 	page = SMS_PAGE_CTRL_CURRENT | 0xf;
    321       1.2   bouyer 	byte2 = 0;
    322       1.2   bouyer 
    323       1.2   bouyer 	/*
    324       1.2   bouyer 	 * Do the MODE SENSE command...
    325       1.2   bouyer 	 */
    326       1.2   bouyer again:
    327       1.3  thorpej 	memset(&scsi_pdata, 0, scsi_dlen);
    328       1.2   bouyer 	error = scsipi_mode_sense(periph, byte2, page,
    329       1.2   bouyer 	    &scsi_pdata.header, scsi_dlen, flags | XS_CTL_DATA_ONSTACK,
    330       1.2   bouyer 	    ST_RETRIES, ST_CTL_TIME);
    331       1.2   bouyer 
    332       1.2   bouyer 	if (error) {
    333       1.2   bouyer 		if (byte2 != SMS_DBD) {
    334       1.2   bouyer 			byte2 = SMS_DBD;
    335       1.2   bouyer 			goto again;
    336       1.2   bouyer 		}
    337       1.2   bouyer 		/*
    338       1.2   bouyer 		 * Try a different page?
    339       1.2   bouyer 		 */
    340       1.2   bouyer 		if (page == (SMS_PAGE_CTRL_CURRENT | 0xf)) {
    341       1.2   bouyer 			page = SMS_PAGE_CTRL_CURRENT | 0x10;
    342       1.2   bouyer 			byte2 = 0;
    343       1.2   bouyer 			goto again;
    344       1.2   bouyer 		}
    345       1.2   bouyer 		return (error);
    346       1.2   bouyer 	}
    347       1.2   bouyer 
    348       1.2   bouyer 	if (scsi_pdata.header.blk_desc_len)
    349       1.2   bouyer 		ptr = (struct scsi_tape_dev_conf_page *) scsi_pdata.pdata;
    350       1.2   bouyer 	else
    351       1.2   bouyer 		ptr = (struct scsi_tape_dev_conf_page *) &scsi_pdata.blk_desc;
    352       1.2   bouyer 
    353       1.2   bouyer 	if ((page & SMS_PAGE_CODE) == 0xf) {
    354       1.2   bouyer 		cptr = (struct scsi_tape_dev_compression_page *) ptr;
    355       1.2   bouyer 		ison = (cptr->dce_dcc & DCP_DCE) != 0;
    356       1.2   bouyer 		if (onoff)
    357       1.2   bouyer 			cptr->dce_dcc |= DCP_DCE;
    358       1.2   bouyer 		else
    359       1.2   bouyer 			cptr->dce_dcc &= ~DCP_DCE;
    360       1.2   bouyer 		cptr->pagecode &= ~0x80;
    361       1.2   bouyer 	} else {
    362       1.2   bouyer 		ison =  (ptr->sel_comp_alg != 0);
    363       1.2   bouyer 		if (onoff)
    364       1.2   bouyer 			ptr->sel_comp_alg = 1;
    365       1.2   bouyer 		else
    366       1.2   bouyer 			ptr->sel_comp_alg = 0;
    367       1.2   bouyer 		ptr->pagecode &= ~0x80;
    368       1.2   bouyer 		ptr->byte2 = 0;
    369       1.2   bouyer 		ptr->active_partition = 0;
    370       1.2   bouyer 		ptr->wb_full_ratio = 0;
    371       1.2   bouyer 		ptr->rb_empty_ratio = 0;
    372       1.2   bouyer 		ptr->byte8 &= ~0x30;
    373       1.2   bouyer 		ptr->gap_size = 0;
    374       1.2   bouyer 		ptr->byte10 &= ~0xe7;
    375       1.2   bouyer 		ptr->ew_bufsize[0] = 0;
    376       1.2   bouyer 		ptr->ew_bufsize[1] = 0;
    377       1.2   bouyer 		ptr->ew_bufsize[2] = 0;
    378       1.2   bouyer 		ptr->reserved = 0;
    379       1.2   bouyer 	}
    380       1.2   bouyer 	/*
    381       1.2   bouyer 	 * There might be a virtue in actually doing the MODE SELECTS,
    382       1.2   bouyer 	 * but let's not clog the bus over it.
    383       1.2   bouyer 	 */
    384       1.2   bouyer 	if (onoff == ison)
    385       1.2   bouyer 		return (0);
    386       1.2   bouyer 
    387       1.2   bouyer 	/*
    388       1.2   bouyer 	 * Set up for a mode select
    389       1.2   bouyer 	 */
    390       1.2   bouyer 
    391       1.2   bouyer 	scsi_pdata.header.data_length = 0;
    392       1.2   bouyer 	scsi_pdata.header.medium_type = 0;
    393       1.2   bouyer 	if ((st->flags & ST_DONTBUFFER) == 0)
    394       1.2   bouyer 		scsi_pdata.header.dev_spec = SMH_DSP_BUFF_MODE_ON;
    395       1.2   bouyer 	else
    396       1.2   bouyer 		scsi_pdata.header.dev_spec = 0;
    397       1.2   bouyer 
    398       1.2   bouyer 	if (scsi_pdata.header.blk_desc_len) {
    399       1.2   bouyer 		scsi_pdata.blk_desc.density = 0;
    400       1.2   bouyer 		scsi_pdata.blk_desc.nblocks[0] = 0;
    401       1.2   bouyer 		scsi_pdata.blk_desc.nblocks[1] = 0;
    402       1.2   bouyer 		scsi_pdata.blk_desc.nblocks[2] = 0;
    403       1.2   bouyer 	}
    404       1.2   bouyer 
    405       1.2   bouyer 	/*
    406       1.2   bouyer 	 * Do the command
    407       1.2   bouyer 	 */
    408       1.2   bouyer 	error = scsipi_mode_select(periph, SMS_PF, &scsi_pdata.header,
    409       1.2   bouyer 	    scsi_dlen, flags | XS_CTL_DATA_ONSTACK, ST_RETRIES, ST_CTL_TIME);
    410       1.2   bouyer 
    411       1.2   bouyer 	if (error && (page & SMS_PAGE_CODE) == 0xf) {
    412       1.2   bouyer 		/*
    413       1.2   bouyer 		 * Try DEVICE CONFIGURATION page.
    414       1.2   bouyer 		 */
    415       1.2   bouyer 		page = SMS_PAGE_CTRL_CURRENT | 0x10;
    416       1.2   bouyer 		goto again;
    417       1.2   bouyer 	}
    418       1.2   bouyer 	return (error);
    419       1.1   bouyer }
    420