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