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