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