scsi_base.c revision 1.87.48.1 1 1.87.48.1 mjf /* $NetBSD: scsi_base.c,v 1.87.48.1 2008/06/02 13:23:50 mjf Exp $ */
2 1.14 cgd
3 1.65 mycroft /*-
4 1.82 mycroft * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
5 1.65 mycroft * All rights reserved.
6 1.65 mycroft *
7 1.65 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.65 mycroft * by Charles M. Hannum.
9 1.9 mycroft *
10 1.9 mycroft * Redistribution and use in source and binary forms, with or without
11 1.9 mycroft * modification, are permitted provided that the following conditions
12 1.9 mycroft * are met:
13 1.9 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.9 mycroft * notice, this list of conditions and the following disclaimer.
15 1.9 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.9 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.9 mycroft * documentation and/or other materials provided with the distribution.
18 1.9 mycroft *
19 1.65 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.65 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.65 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.65 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.65 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.65 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.65 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.65 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.65 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.65 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.65 mycroft * POSSIBILITY OF SUCH DAMAGE.
30 1.1 mycroft */
31 1.76 lukem
32 1.76 lukem #include <sys/cdefs.h>
33 1.87.48.1 mjf __KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.87.48.1 2008/06/02 13:23:50 mjf Exp $");
34 1.49 enami
35 1.1 mycroft #include <sys/param.h>
36 1.30 thorpej #include <sys/systm.h>
37 1.11 mycroft #include <sys/kernel.h>
38 1.1 mycroft #include <sys/buf.h>
39 1.1 mycroft #include <sys/uio.h>
40 1.1 mycroft #include <sys/malloc.h>
41 1.1 mycroft #include <sys/errno.h>
42 1.1 mycroft #include <sys/device.h>
43 1.33 christos #include <sys/proc.h>
44 1.2 mycroft
45 1.47 bouyer #include <dev/scsipi/scsipi_all.h>
46 1.47 bouyer #include <dev/scsipi/scsi_all.h>
47 1.47 bouyer #include <dev/scsipi/scsi_disk.h>
48 1.47 bouyer #include <dev/scsipi/scsiconf.h>
49 1.47 bouyer #include <dev/scsipi/scsipi_base.h>
50 1.47 bouyer
51 1.1 mycroft /*
52 1.1 mycroft * Do a scsi operation, asking a device to run as SCSI-II if it can.
53 1.1 mycroft */
54 1.50 enami int
55 1.79 thorpej scsi_change_def(struct scsipi_periph *periph, int flags)
56 1.1 mycroft {
57 1.84 mycroft struct scsi_changedef cmd;
58 1.1 mycroft
59 1.84 mycroft memset(&cmd, 0, sizeof(cmd));
60 1.84 mycroft cmd.opcode = SCSI_CHANGE_DEFINITION;
61 1.84 mycroft cmd.how = SC_SCSI_2;
62 1.84 mycroft
63 1.84 mycroft return (scsipi_command(periph, (void *)&cmd, sizeof(cmd), 0, 0,
64 1.84 mycroft SCSIPIRETRIES, 100000, NULL, flags));
65 1.22 mycroft }
66 1.22 mycroft
67 1.22 mycroft /*
68 1.22 mycroft * ask the scsi driver to perform a command for us.
69 1.22 mycroft * tell it where to read/write the data, and how
70 1.22 mycroft * long the data is supposed to be. If we have a buf
71 1.22 mycroft * to associate with the transfer, we need that too.
72 1.22 mycroft */
73 1.82 mycroft void
74 1.82 mycroft scsi_scsipi_cmd(struct scsipi_xfer *xs)
75 1.22 mycroft {
76 1.82 mycroft struct scsipi_periph *periph = xs->xs_periph;
77 1.22 mycroft
78 1.74 bouyer SC_DEBUG(periph, SCSIPI_DB2, ("scsi_scsipi_cmd\n"));
79 1.22 mycroft
80 1.58 cgd /*
81 1.58 cgd * Set the LUN in the CDB if we have an older device. We also
82 1.74 bouyer * set it for more modern SCSI-2 devices "just in case".
83 1.58 cgd */
84 1.74 bouyer if (periph->periph_version <= 2)
85 1.58 cgd xs->cmd->bytes[0] |=
86 1.74 bouyer ((periph->periph_lun << SCSI_CMD_LUN_SHIFT) &
87 1.58 cgd SCSI_CMD_LUN_MASK);
88 1.1 mycroft }
89 1.1 mycroft
90 1.1 mycroft /*
91 1.1 mycroft * Utility routines often used in SCSI stuff
92 1.1 mycroft */
93 1.1 mycroft
94 1.1 mycroft /*
95 1.74 bouyer * Print out the periph's address info.
96 1.1 mycroft */
97 1.1 mycroft void
98 1.79 thorpej scsi_print_addr(struct scsipi_periph *periph)
99 1.1 mycroft {
100 1.74 bouyer struct scsipi_channel *chan = periph->periph_channel;
101 1.74 bouyer struct scsipi_adapter *adapt = chan->chan_adapter;
102 1.1 mycroft
103 1.74 bouyer printf("%s(%s:%d:%d:%d): ", periph->periph_dev != NULL ?
104 1.87.48.1 mjf device_xname(periph->periph_dev) : "probe",
105 1.87.48.1 mjf device_xname(adapt->adapt_dev),
106 1.74 bouyer chan->chan_channel, periph->periph_target,
107 1.74 bouyer periph->periph_lun);
108 1.70 enami }
109 1.70 enami
110 1.70 enami /*
111 1.74 bouyer * Kill off all pending xfers for a periph.
112 1.70 enami *
113 1.70 enami * Must be called at splbio().
114 1.70 enami */
115 1.70 enami void
116 1.87 christos scsi_kill_pending(struct scsipi_periph *periph)
117 1.70 enami {
118 1.1 mycroft }
119