Home | History | Annotate | Line # | Download | only in scsipi
scsipi_base.h revision 1.2
      1  1.2  bouyer /*	$NetBSD: scsipi_base.h,v 1.2 1997/08/27 11:26:51 bouyer Exp $	*/
      2  1.2  bouyer 
      3  1.2  bouyer /*
      4  1.2  bouyer  * Copyright (c) 1994, 1995, 1997 Charles M. Hannum.  All rights reserved.
      5  1.2  bouyer  *
      6  1.2  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.2  bouyer  * modification, are permitted provided that the following conditions
      8  1.2  bouyer  * are met:
      9  1.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.2  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.2  bouyer  *    must display the following acknowledgement:
     16  1.2  bouyer  *	This product includes software developed by Charles M. Hannum.
     17  1.2  bouyer  * 4. The name of the author may not be used to endorse or promote products
     18  1.2  bouyer  *    derived from this software without specific prior written permission.
     19  1.2  bouyer  *
     20  1.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.2  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.2  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.2  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.2  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.2  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.2  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.2  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.2  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.2  bouyer  */
     31  1.2  bouyer 
     32  1.2  bouyer /*
     33  1.2  bouyer  * Originally written by Julian Elischer (julian (at) dialix.oz.au)
     34  1.2  bouyer  */
     35  1.2  bouyer 
     36  1.2  bouyer extern LIST_HEAD(xs_free_list, scsipi_xfer) xs_free_list;
     37  1.2  bouyer 
     38  1.2  bouyer struct scsipi_xfer *scsipi_get_xs __P((struct scsipi_link *, int));
     39  1.2  bouyer void scsipi_free_xs __P((struct scsipi_xfer *, int));
     40  1.2  bouyer 
     41  1.2  bouyer static __inline struct scsipi_xfer *scsipi_make_xs __P((struct scsipi_link *,
     42  1.2  bouyer 						    struct scsipi_generic *,
     43  1.2  bouyer 						    int cmdlen,
     44  1.2  bouyer 						    u_char *data_addr,
     45  1.2  bouyer 						    int datalen,
     46  1.2  bouyer 						    int retries,
     47  1.2  bouyer 						    int timeout,
     48  1.2  bouyer 						    struct buf *,
     49  1.2  bouyer 						    int flags));
     50  1.2  bouyer 
     51  1.2  bouyer /*
     52  1.2  bouyer  * Make a scsipi_xfer, and return a pointer to it.
     53  1.2  bouyer  */
     54  1.2  bouyer 
     55  1.2  bouyer static __inline struct scsipi_xfer *
     56  1.2  bouyer scsipi_make_xs(sc_link, scsipi_cmd, cmdlen, data_addr, datalen,
     57  1.2  bouyer 	     retries, timeout, bp, flags)
     58  1.2  bouyer 	struct scsipi_link *sc_link;
     59  1.2  bouyer 	struct scsipi_generic *scsipi_cmd;
     60  1.2  bouyer 	int cmdlen;
     61  1.2  bouyer 	u_char *data_addr;
     62  1.2  bouyer 	int datalen;
     63  1.2  bouyer 	int retries;
     64  1.2  bouyer 	int timeout;
     65  1.2  bouyer 	struct buf *bp;
     66  1.2  bouyer 	int flags;
     67  1.2  bouyer {
     68  1.2  bouyer 	struct scsipi_xfer *xs;
     69  1.2  bouyer 
     70  1.2  bouyer 	if ((xs = scsipi_get_xs(sc_link, flags)) == NULL)
     71  1.2  bouyer 		return NULL;
     72  1.2  bouyer 
     73  1.2  bouyer 	/*
     74  1.2  bouyer 	 * Fill out the scsipi_xfer structure.  We don't know whose context
     75  1.2  bouyer 	 * the cmd is in, so copy it.
     76  1.2  bouyer 	 */
     77  1.2  bouyer 	xs->sc_link = sc_link;
     78  1.2  bouyer 	bcopy(scsipi_cmd, &xs->cmdstore, cmdlen);
     79  1.2  bouyer 	xs->cmd = &xs->cmdstore;
     80  1.2  bouyer 	xs->cmdlen = cmdlen;
     81  1.2  bouyer 	xs->data = data_addr;
     82  1.2  bouyer 	xs->datalen = datalen;
     83  1.2  bouyer 	xs->retries = retries;
     84  1.2  bouyer 	xs->timeout = timeout;
     85  1.2  bouyer 	xs->bp = bp;
     86  1.2  bouyer 
     87  1.2  bouyer 	/*
     88  1.2  bouyer 	 * Set the LUN in the CDB if we have an older device.  We also
     89  1.2  bouyer 	 * set it for more modern SCSI-II devices "just in case".
     90  1.2  bouyer 	 */
     91  1.2  bouyer 
     92  1.2  bouyer 	if ((sc_link->type == BUS_SCSI) &&
     93  1.2  bouyer 		((sc_link->scsipi_scsi.scsi_version & SID_ANSII) <= 2))
     94  1.2  bouyer 		xs->cmd->bytes[0] |=
     95  1.2  bouyer 		    ((sc_link->scsipi_scsi.lun << SCSI_CMD_LUN_SHIFT) &
     96  1.2  bouyer 			SCSI_CMD_LUN_MASK);
     97  1.2  bouyer 
     98  1.2  bouyer 	return xs;
     99  1.2  bouyer }
    100