scsipi_base.h revision 1.2 1 /* $NetBSD: scsipi_base.h,v 1.2 1997/08/27 11:26:51 bouyer 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 (at) 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 *,
43 int cmdlen,
44 u_char *data_addr,
45 int datalen,
46 int retries,
47 int timeout,
48 struct buf *,
49 int flags));
50
51 /*
52 * Make a scsipi_xfer, and return a pointer to it.
53 */
54
55 static __inline struct scsipi_xfer *
56 scsipi_make_xs(sc_link, scsipi_cmd, cmdlen, data_addr, datalen,
57 retries, timeout, bp, flags)
58 struct scsipi_link *sc_link;
59 struct scsipi_generic *scsipi_cmd;
60 int cmdlen;
61 u_char *data_addr;
62 int datalen;
63 int retries;
64 int timeout;
65 struct buf *bp;
66 int flags;
67 {
68 struct scsipi_xfer *xs;
69
70 if ((xs = scsipi_get_xs(sc_link, flags)) == NULL)
71 return NULL;
72
73 /*
74 * Fill out the scsipi_xfer structure. We don't know whose context
75 * the cmd is in, so copy it.
76 */
77 xs->sc_link = sc_link;
78 bcopy(scsipi_cmd, &xs->cmdstore, cmdlen);
79 xs->cmd = &xs->cmdstore;
80 xs->cmdlen = cmdlen;
81 xs->data = data_addr;
82 xs->datalen = datalen;
83 xs->retries = retries;
84 xs->timeout = timeout;
85 xs->bp = bp;
86
87 /*
88 * Set the LUN in the CDB if we have an older device. We also
89 * set it for more modern SCSI-II devices "just in case".
90 */
91
92 if ((sc_link->type == BUS_SCSI) &&
93 ((sc_link->scsipi_scsi.scsi_version & SID_ANSII) <= 2))
94 xs->cmd->bytes[0] |=
95 ((sc_link->scsipi_scsi.lun << SCSI_CMD_LUN_SHIFT) &
96 SCSI_CMD_LUN_MASK);
97
98 return xs;
99 }
100