2005-01-05 22:34:37 +00:00
|
|
|
/*-
|
1998-09-15 06:36:34 +00:00
|
|
|
* Copyright (c) 1997 Justin T. Gibbs.
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
|
1998-09-15 06:36:34 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2003-06-10 18:14:05 +00:00
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Derived from the NetBSD SCSI changer driver.
|
|
|
|
*
|
|
|
|
* $NetBSD: ch.c,v 1.32 1998/01/12 09:49:12 thorpej Exp $
|
|
|
|
*
|
|
|
|
*/
|
2005-01-05 22:34:37 +00:00
|
|
|
/*-
|
1998-09-15 06:36:34 +00:00
|
|
|
* Copyright (c) 1996, 1997 Jason R. Thorpe <thorpej@and.com>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Partially based on an autochanger driver written by Stefan Grefen
|
|
|
|
* and on an autochanger driver written by the Systems Programming Group
|
|
|
|
* at the University of Utah Computer Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgements:
|
|
|
|
* This product includes software developed by Jason R. Thorpe
|
|
|
|
* for And Communications, http://www.and.com/
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-10 18:14:05 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/chio.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/devicestat.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/cam_periph.h>
|
|
|
|
#include <cam/cam_xpt_periph.h>
|
|
|
|
#include <cam/cam_debug.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
#include <cam/scsi/scsi_message.h>
|
|
|
|
#include <cam/scsi/scsi_ch.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout definitions for various changer related commands. They may
|
|
|
|
* be too short for some devices (especially the timeout for INITIALIZE
|
|
|
|
* ELEMENT STATUS).
|
|
|
|
*/
|
|
|
|
|
1998-12-22 20:05:23 +00:00
|
|
|
static const u_int32_t CH_TIMEOUT_MODE_SENSE = 6000;
|
2013-08-29 21:25:27 +00:00
|
|
|
static const u_int32_t CH_TIMEOUT_MOVE_MEDIUM = 15 * 60 * 1000;
|
|
|
|
static const u_int32_t CH_TIMEOUT_EXCHANGE_MEDIUM = 15 * 60 * 1000;
|
|
|
|
static const u_int32_t CH_TIMEOUT_POSITION_TO_ELEMENT = 15 * 60 * 1000;
|
|
|
|
static const u_int32_t CH_TIMEOUT_READ_ELEMENT_STATUS = 5 * 60 * 1000;
|
1998-12-22 20:05:23 +00:00
|
|
|
static const u_int32_t CH_TIMEOUT_SEND_VOLTAG = 10000;
|
|
|
|
static const u_int32_t CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS = 500000;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
typedef enum {
|
Work around a race condition in devfs by changing the way closes
are handled in most CAM peripheral drivers that are not handled by
GEOM's disk class.
The usual character driver open and close semantics are that the
driver gets N open calls, but only one close, when the last caller
closes the device.
CAM peripheral drivers expect that behavior to be honored to the
letter, and the CAM peripheral driver code (specifically
cam_periph_release_locked_busses()) panics if it is done incorrectly.
Since devfs has to drop its locks while it calls a driver's close
routine, and it does not have a way to delay or prevent open calls
while it is calling the close routine, there is a race.
The sequence of events, simplified a bit, is:
- devfs acquires a lock
- devfs checks the reference count, and if it is 1, continues to close.
- devfs releases the lock
- 2nd process open call on the device happens here
- devfs calls the driver's close routine
- devfs acquires a lock
- devfs decrements the reference count
- devfs releases the lock
- 2nd process close call on the device happens here
At the second close, we get a panic in
cam_periph_release_locked_busses(), complaining that peripheral
has been released when the reference count is already 0. This is
because we have gotten two closes in a row, which should not
happen.
The fix is to add the D_TRACKCLOSE flag to the driver's cdevsw, so
that we get a close() call for each open(). That does happen
reliably, so we can make sure that our reference counts are
correct.
Note that the sa(4) and pt(4) drivers only allow one context
through the open routine. So these drivers aren't exposed to the
same race condition.
scsi_ch.c,
scsi_enc.c,
scsi_enc_internal.h,
scsi_pass.c,
scsi_sg.c:
For these drivers, change the open() routine to
increment the reference count for every open, and
just decrement the reference count in the close.
Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
scsi_pt.c: Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
MFC after: 3 days
2012-05-27 06:11:09 +00:00
|
|
|
CH_FLAG_INVALID = 0x001
|
1998-09-15 06:36:34 +00:00
|
|
|
} ch_flags;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CH_STATE_PROBE,
|
|
|
|
CH_STATE_NORMAL
|
|
|
|
} ch_state;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CH_CCB_PROBE,
|
|
|
|
CH_CCB_WAITING
|
|
|
|
} ch_ccb_types;
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
typedef enum {
|
|
|
|
CH_Q_NONE = 0x00,
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
CH_Q_NO_DBD = 0x01,
|
|
|
|
CH_Q_NO_DVCID = 0x02
|
1998-10-02 05:25:49 +00:00
|
|
|
} ch_quirks;
|
|
|
|
|
2013-05-18 23:36:21 +00:00
|
|
|
#define CH_Q_BIT_STRING \
|
|
|
|
"\020" \
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
"\001NO_DBD" \
|
|
|
|
"\002NO_DVCID"
|
2013-05-18 23:36:21 +00:00
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
#define ccb_state ppriv_field0
|
|
|
|
#define ccb_bp ppriv_ptr1
|
|
|
|
|
|
|
|
struct scsi_mode_sense_data {
|
|
|
|
struct scsi_mode_header_6 header;
|
1998-10-02 05:25:49 +00:00
|
|
|
struct scsi_mode_blk_desc blk_desc;
|
1998-09-15 06:36:34 +00:00
|
|
|
union {
|
|
|
|
struct page_element_address_assignment ea;
|
|
|
|
struct page_transport_geometry_parameters tg;
|
|
|
|
struct page_device_capabilities cap;
|
|
|
|
} pages;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ch_softc {
|
|
|
|
ch_flags flags;
|
|
|
|
ch_state state;
|
1998-10-02 05:25:49 +00:00
|
|
|
ch_quirks quirks;
|
1998-09-15 06:36:34 +00:00
|
|
|
union ccb saved_ccb;
|
2003-03-08 21:44:46 +00:00
|
|
|
struct devstat *device_stats;
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
struct cdev *dev;
|
|
|
|
int open_count;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
int sc_picker; /* current picker */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following information is obtained from the
|
|
|
|
* element address assignment page.
|
|
|
|
*/
|
2003-05-31 16:54:37 +00:00
|
|
|
int sc_firsts[CHET_MAX + 1]; /* firsts */
|
|
|
|
int sc_counts[CHET_MAX + 1]; /* counts */
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The following mask defines the legal combinations
|
|
|
|
* of elements for the MOVE MEDIUM command.
|
|
|
|
*/
|
2003-05-31 16:54:37 +00:00
|
|
|
u_int8_t sc_movemask[CHET_MAX + 1];
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As above, but for EXCHANGE MEDIUM.
|
|
|
|
*/
|
2003-05-31 16:54:37 +00:00
|
|
|
u_int8_t sc_exchangemask[CHET_MAX + 1];
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Quirks; see below. XXX KDM not implemented yet
|
|
|
|
*/
|
|
|
|
int sc_settledelay; /* delay for settle */
|
|
|
|
};
|
|
|
|
|
|
|
|
static d_open_t chopen;
|
|
|
|
static d_close_t chclose;
|
|
|
|
static d_ioctl_t chioctl;
|
|
|
|
static periph_init_t chinit;
|
|
|
|
static periph_ctor_t chregister;
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
static periph_oninv_t choninvalidate;
|
1998-09-15 06:36:34 +00:00
|
|
|
static periph_dtor_t chcleanup;
|
|
|
|
static periph_start_t chstart;
|
|
|
|
static void chasync(void *callback_arg, u_int32_t code,
|
|
|
|
struct cam_path *path, void *arg);
|
|
|
|
static void chdone(struct cam_periph *periph,
|
|
|
|
union ccb *done_ccb);
|
|
|
|
static int cherror(union ccb *ccb, u_int32_t cam_flags,
|
|
|
|
u_int32_t sense_flags);
|
|
|
|
static int chmove(struct cam_periph *periph,
|
|
|
|
struct changer_move *cm);
|
|
|
|
static int chexchange(struct cam_periph *periph,
|
|
|
|
struct changer_exchange *ce);
|
|
|
|
static int chposition(struct cam_periph *periph,
|
|
|
|
struct changer_position *cp);
|
|
|
|
static int chgetelemstatus(struct cam_periph *periph,
|
2013-04-19 20:03:51 +00:00
|
|
|
int scsi_version, u_long cmd,
|
1998-09-15 06:36:34 +00:00
|
|
|
struct changer_element_status_request *csr);
|
|
|
|
static int chsetvoltag(struct cam_periph *periph,
|
|
|
|
struct changer_set_voltag_request *csvr);
|
|
|
|
static int chielem(struct cam_periph *periph,
|
|
|
|
unsigned int timeout);
|
|
|
|
static int chgetparams(struct cam_periph *periph);
|
2013-04-19 20:03:51 +00:00
|
|
|
static int chscsiversion(struct cam_periph *periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
static struct periph_driver chdriver =
|
|
|
|
{
|
|
|
|
chinit, "ch",
|
|
|
|
TAILQ_HEAD_INITIALIZER(chdriver.units), /* generation */ 0
|
|
|
|
};
|
|
|
|
|
2001-02-07 07:05:59 +00:00
|
|
|
PERIPHDRIVER_DECLARE(ch, chdriver);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw ch_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
Work around a race condition in devfs by changing the way closes
are handled in most CAM peripheral drivers that are not handled by
GEOM's disk class.
The usual character driver open and close semantics are that the
driver gets N open calls, but only one close, when the last caller
closes the device.
CAM peripheral drivers expect that behavior to be honored to the
letter, and the CAM peripheral driver code (specifically
cam_periph_release_locked_busses()) panics if it is done incorrectly.
Since devfs has to drop its locks while it calls a driver's close
routine, and it does not have a way to delay or prevent open calls
while it is calling the close routine, there is a race.
The sequence of events, simplified a bit, is:
- devfs acquires a lock
- devfs checks the reference count, and if it is 1, continues to close.
- devfs releases the lock
- 2nd process open call on the device happens here
- devfs calls the driver's close routine
- devfs acquires a lock
- devfs decrements the reference count
- devfs releases the lock
- 2nd process close call on the device happens here
At the second close, we get a panic in
cam_periph_release_locked_busses(), complaining that peripheral
has been released when the reference count is already 0. This is
because we have gotten two closes in a row, which should not
happen.
The fix is to add the D_TRACKCLOSE flag to the driver's cdevsw, so
that we get a close() call for each open(). That does happen
reliably, so we can make sure that our reference counts are
correct.
Note that the sa(4) and pt(4) drivers only allow one context
through the open routine. So these drivers aren't exposed to the
same race condition.
scsi_ch.c,
scsi_enc.c,
scsi_enc_internal.h,
scsi_pass.c,
scsi_sg.c:
For these drivers, change the open() routine to
increment the reference count for every open, and
just decrement the reference count in the close.
Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
scsi_pt.c: Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
MFC after: 3 days
2012-05-27 06:11:09 +00:00
|
|
|
.d_flags = D_TRACKCLOSE,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = chopen,
|
|
|
|
.d_close = chclose,
|
|
|
|
.d_ioctl = chioctl,
|
|
|
|
.d_name = "ch",
|
1998-09-15 06:36:34 +00:00
|
|
|
};
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_SCSICH, "scsi_ch", "scsi_ch buffers");
|
2007-05-14 21:48:53 +00:00
|
|
|
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
1998-09-15 06:36:34 +00:00
|
|
|
chinit(void)
|
|
|
|
{
|
|
|
|
cam_status status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install a global async callback. This callback will
|
|
|
|
* receive async callbacks like "new device found".
|
|
|
|
*/
|
2007-05-16 16:54:23 +00:00
|
|
|
status = xpt_register_async(AC_FOUND_DEVICE, chasync, NULL, NULL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
printf("ch: Failed to attach master async callback "
|
|
|
|
"due to status 0x%x!\n", status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
static void
|
|
|
|
chdevgonecb(void *arg)
|
|
|
|
{
|
|
|
|
struct cam_sim *sim;
|
|
|
|
struct ch_softc *softc;
|
|
|
|
struct cam_periph *periph;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
periph = (struct cam_periph *)arg;
|
|
|
|
sim = periph->sim;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
KASSERT(softc->open_count >= 0, ("Negative open count %d",
|
|
|
|
softc->open_count));
|
|
|
|
|
|
|
|
mtx_lock(sim->mtx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When we get this callback, we will get no more close calls from
|
|
|
|
* devfs. So if we have any dangling opens, we need to release the
|
|
|
|
* reference held for that particular context.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < softc->open_count; i++)
|
|
|
|
cam_periph_release_locked(periph);
|
|
|
|
|
|
|
|
softc->open_count = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the reference held for the device node, it is gone now.
|
|
|
|
*/
|
|
|
|
cam_periph_release_locked(periph);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We reference the SIM lock directly here, instead of using
|
|
|
|
* cam_periph_unlock(). The reason is that the final call to
|
|
|
|
* cam_periph_release_locked() above could result in the periph
|
|
|
|
* getting freed. If that is the case, dereferencing the periph
|
|
|
|
* with a cam_periph_unlock() call would cause a page fault.
|
|
|
|
*/
|
|
|
|
mtx_unlock(sim->mtx);
|
|
|
|
}
|
|
|
|
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
static void
|
|
|
|
choninvalidate(struct cam_periph *periph)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* De-register any async callbacks.
|
|
|
|
*/
|
2007-05-16 16:54:23 +00:00
|
|
|
xpt_register_async(0, chasync, periph, periph->path);
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
|
|
|
|
softc->flags |= CH_FLAG_INVALID;
|
|
|
|
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
/*
|
|
|
|
* Tell devfs this device has gone away, and ask for a callback
|
|
|
|
* when it has cleaned up its state.
|
|
|
|
*/
|
|
|
|
destroy_dev_sched_cb(softc->dev, chdevgonecb, periph);
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
static void
|
|
|
|
chcleanup(struct cam_periph *periph)
|
|
|
|
{
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
struct ch_softc *softc;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
2003-03-08 21:44:46 +00:00
|
|
|
devstat_remove_entry(softc->device_stats);
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
free(softc, M_DEVBUF);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
|
|
|
|
periph = (struct cam_periph *)callback_arg;
|
|
|
|
|
|
|
|
switch(code) {
|
|
|
|
case AC_FOUND_DEVICE:
|
|
|
|
{
|
|
|
|
struct ccb_getdev *cgd;
|
|
|
|
cam_status status;
|
|
|
|
|
|
|
|
cgd = (struct ccb_getdev *)arg;
|
2001-07-04 05:22:42 +00:00
|
|
|
if (cgd == NULL)
|
|
|
|
break;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Separate the parallel scsi knowledge out of the core of the XPT, and
modularize it so that new transports can be created.
Add a transport for SATA
Add a periph+protocol layer for ATA
Add a driver for AHCI-compliant hardware.
Add a maxio field to CAM so that drivers can advertise their max
I/O capability. Modify various drivers so that they are insulated
from the value of MAXPHYS.
The new ATA/SATA code supports AHCI-compliant hardware, and will override
the classic ATA driver if it is loaded as a module at boot time or compiled
into the kernel. The stack now support NCQ (tagged queueing) for increased
performance on modern SATA drives. It also supports port multipliers.
ATA drives are accessed via 'ada' device nodes. ATAPI drives are
accessed via 'cd' device nodes. They can all be enumerated and manipulated
via camcontrol, just like SCSI drives. SCSI commands are not translated to
their ATA equivalents; ATA native commands are used throughout the entire
stack, including camcontrol. See the camcontrol manpage for further
details. Testing this code may require that you update your fstab, and
possibly modify your BIOS to enable AHCI functionality, if available.
This code is very experimental at the moment. The userland ABI/API has
changed, so applications will need to be recompiled. It may change
further in the near future. The 'ada' device name may also change as
more infrastructure is completed in this project. The goal is to
eventually put all CAM busses and devices until newbus, allowing for
interesting topology and management options.
Few functional changes will be seen with existing SCSI/SAS/FC drivers,
though the userland ABI has still changed. In the future, transports
specific modules for SAS and FC may appear in order to better support
the topologies and capabilities of these technologies.
The modularization of CAM and the addition of the ATA/SATA modules is
meant to break CAM out of the mold of being specific to SCSI, letting it
grow to be a framework for arbitrary transports and protocols. It also
allows drivers to be written to support discrete hardware without
jeopardizing the stability of non-related hardware. While only an AHCI
driver is provided now, a Silicon Image driver is also in the works.
Drivers for ICH1-4, ICH5-6, PIIX, classic IDE, and any other hardware
is possible and encouraged. Help with new transports is also encouraged.
Submitted by: scottl, mav
Approved by: re
2009-07-10 08:18:08 +00:00
|
|
|
if (cgd->protocol != PROTO_SCSI)
|
|
|
|
break;
|
|
|
|
|
2000-01-17 06:27:37 +00:00
|
|
|
if (SID_TYPE(&cgd->inq_data)!= T_CHANGER)
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a peripheral instance for
|
|
|
|
* this device and start the probe
|
|
|
|
* process.
|
|
|
|
*/
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
status = cam_periph_alloc(chregister, choninvalidate,
|
|
|
|
chcleanup, chstart, "ch",
|
|
|
|
CAM_PERIPH_BIO, cgd->ccb_h.path,
|
1998-09-15 06:36:34 +00:00
|
|
|
chasync, AC_FOUND_DEVICE, cgd);
|
|
|
|
|
|
|
|
if (status != CAM_REQ_CMP
|
|
|
|
&& status != CAM_REQ_INPROG)
|
|
|
|
printf("chasync: Unable to probe new device "
|
|
|
|
"due to status 0x%x\n", status);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
default:
|
1999-05-22 22:00:24 +00:00
|
|
|
cam_periph_async(periph, code, path, arg);
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static cam_status
|
|
|
|
chregister(struct cam_periph *periph, void *arg)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
struct ccb_getdev *cgd;
|
2011-04-14 21:25:32 +00:00
|
|
|
struct ccb_pathinq cpi;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
cgd = (struct ccb_getdev *)arg;
|
|
|
|
if (cgd == NULL) {
|
|
|
|
printf("chregister: no getdev CCB, can't register device\n");
|
|
|
|
return(CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
|
|
|
|
|
|
|
|
if (softc == NULL) {
|
|
|
|
printf("chregister: Unable to probe new device. "
|
|
|
|
"Unable to allocate softc\n");
|
|
|
|
return(CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(softc, sizeof(*softc));
|
|
|
|
softc->state = CH_STATE_PROBE;
|
|
|
|
periph->softc = softc;
|
1998-10-02 05:25:49 +00:00
|
|
|
softc->quirks = CH_Q_NONE;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
/*
|
|
|
|
* The DVCID and CURDATA bits were not introduced until the SMC
|
|
|
|
* spec. If this device claims SCSI-2 or earlier support, then it
|
|
|
|
* very likely does not support these bits.
|
|
|
|
*/
|
|
|
|
if (cgd->inq_data.version <= SCSI_REV_2)
|
|
|
|
softc->quirks |= CH_Q_NO_DVCID;
|
|
|
|
|
2011-04-14 21:25:32 +00:00
|
|
|
bzero(&cpi, sizeof(cpi));
|
|
|
|
xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
|
|
|
|
cpi.ccb_h.func_code = XPT_PATH_INQ;
|
|
|
|
xpt_action((union ccb *)&cpi);
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Changers don't have a blocksize, and obviously don't support
|
|
|
|
* tagged queueing.
|
|
|
|
*/
|
2007-05-16 16:54:23 +00:00
|
|
|
cam_periph_unlock(periph);
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats = devstat_new_entry("ch",
|
1998-09-15 06:36:34 +00:00
|
|
|
periph->unit_number, 0,
|
|
|
|
DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
|
2011-04-14 21:25:32 +00:00
|
|
|
SID_TYPE(&cgd->inq_data) |
|
|
|
|
XPORT_DEVSTAT_TYPE(cpi.transport),
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
DEVSTAT_PRIORITY_OTHER);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
/*
|
|
|
|
* Acquire a reference to the periph before we create the devfs
|
|
|
|
* instance for it. We'll release this reference once the devfs
|
|
|
|
* instance has been freed.
|
|
|
|
*/
|
|
|
|
if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
|
|
|
|
xpt_print(periph->path, "%s: lost periph during "
|
|
|
|
"registration!\n", __func__);
|
|
|
|
cam_periph_lock(periph);
|
|
|
|
return (CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-21 19:17:47 +00:00
|
|
|
/* Register the device */
|
|
|
|
softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT,
|
|
|
|
GID_OPERATOR, 0600, "%s%d", periph->periph_name,
|
|
|
|
periph->unit_number);
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
2002-08-15 20:54:03 +00:00
|
|
|
softc->dev->si_drv1 = periph;
|
1999-11-21 19:17:47 +00:00
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Add an async callback so that we get
|
|
|
|
* notified if this device goes away.
|
|
|
|
*/
|
2007-05-16 16:54:23 +00:00
|
|
|
xpt_register_async(AC_LOST_DEVICE, chasync, periph, periph->path);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
2007-04-15 08:49:19 +00:00
|
|
|
* Lock this periph until we are setup.
|
1998-09-15 06:36:34 +00:00
|
|
|
* This first call can't block
|
|
|
|
*/
|
2007-04-15 08:49:19 +00:00
|
|
|
(void)cam_periph_hold(periph, PRIBIO);
|
MFp4: Large set of CAM inprovements.
- Unify bus reset/probe sequence. Whenever bus attached at boot or later,
CAM will automatically reset and scan it. It allows to remove duplicate
code from many drivers.
- Any bus, attached before CAM completed it's boot-time initialization,
will equally join to the process, delaying boot if needed.
- New kern.cam.boot_delay loader tunable should help controllers that
are still unable to register their buses in time (such as slow USB/
PCCard/ CardBus devices), by adding one more event to wait on boot.
- To allow synchronization between different CAM levels, concept of
requests priorities was extended. Priorities now split between several
"run levels". Device can be freezed at specified level, allowing higher
priority requests to pass. For example, no payload requests allowed,
until PMP driver enable port. ATA XPT negotiate transfer parameters,
periph driver configure caching and so on.
- Frozen requests are no more counted by request allocation scheduler.
It fixes deadlocks, when frozen low priority payload requests occupying
slots, required by higher levels to manage theit execution.
- Two last changes were holding proper ATA reinitialization and error
recovery implementation. Now it is done: SATA controllers and Port
Multipliers now implement automatic hot-plug and should correctly
recover from timeouts and bus resets.
- Improve SCSI error recovery for devices on buses without automatic sense
reporting, such as ATAPI or USB. For example, it allows CAM to wait, while
CD drive loads disk, instead of immediately return error status.
- Decapitalize diagnostic messages and make them more readable and sensible.
- Teach PMP driver to limit maximum speed on fan-out ports.
- Make boot wait for PMP scan completes, and make rescan more reliable.
- Fix pass driver, to return CCB to user level in case of error.
- Increase number of retries in cd driver, as device may return several UAs.
2010-01-28 08:41:30 +00:00
|
|
|
xpt_schedule(periph, CAM_PRIORITY_DEV);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
return(CAM_REQ_CMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
chopen(struct cdev *dev, int flags, int fmt, struct thread *td)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct ch_softc *softc;
|
2002-08-15 20:54:03 +00:00
|
|
|
int error;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2002-08-15 20:54:03 +00:00
|
|
|
periph = (struct cam_periph *)dev->si_drv1;
|
2007-04-15 08:49:19 +00:00
|
|
|
if (cam_periph_acquire(periph) != CAM_REQ_CMP)
|
|
|
|
return (ENXIO);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
|
|
|
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
if (softc->flags & CH_FLAG_INVALID) {
|
Work around a race condition in devfs by changing the way closes
are handled in most CAM peripheral drivers that are not handled by
GEOM's disk class.
The usual character driver open and close semantics are that the
driver gets N open calls, but only one close, when the last caller
closes the device.
CAM peripheral drivers expect that behavior to be honored to the
letter, and the CAM peripheral driver code (specifically
cam_periph_release_locked_busses()) panics if it is done incorrectly.
Since devfs has to drop its locks while it calls a driver's close
routine, and it does not have a way to delay or prevent open calls
while it is calling the close routine, there is a race.
The sequence of events, simplified a bit, is:
- devfs acquires a lock
- devfs checks the reference count, and if it is 1, continues to close.
- devfs releases the lock
- 2nd process open call on the device happens here
- devfs calls the driver's close routine
- devfs acquires a lock
- devfs decrements the reference count
- devfs releases the lock
- 2nd process close call on the device happens here
At the second close, we get a panic in
cam_periph_release_locked_busses(), complaining that peripheral
has been released when the reference count is already 0. This is
because we have gotten two closes in a row, which should not
happen.
The fix is to add the D_TRACKCLOSE flag to the driver's cdevsw, so
that we get a close() call for each open(). That does happen
reliably, so we can make sure that our reference counts are
correct.
Note that the sa(4) and pt(4) drivers only allow one context
through the open routine. So these drivers aren't exposed to the
same race condition.
scsi_ch.c,
scsi_enc.c,
scsi_enc_internal.h,
scsi_pass.c,
scsi_sg.c:
For these drivers, change the open() routine to
increment the reference count for every open, and
just decrement the reference count in the close.
Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
scsi_pt.c: Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
MFC after: 3 days
2012-05-27 06:11:09 +00:00
|
|
|
cam_periph_release_locked(periph);
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unlock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
return(ENXIO);
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
if ((error = cam_periph_hold(periph, PRIBIO | PCATCH)) != 0) {
|
|
|
|
cam_periph_unlock(periph);
|
|
|
|
cam_periph_release(periph);
|
|
|
|
return (error);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load information about this changer device into the softc.
|
|
|
|
*/
|
|
|
|
if ((error = chgetparams(periph)) != 0) {
|
2013-04-19 20:03:51 +00:00
|
|
|
cam_periph_unhold(periph);
|
Work around a race condition in devfs by changing the way closes
are handled in most CAM peripheral drivers that are not handled by
GEOM's disk class.
The usual character driver open and close semantics are that the
driver gets N open calls, but only one close, when the last caller
closes the device.
CAM peripheral drivers expect that behavior to be honored to the
letter, and the CAM peripheral driver code (specifically
cam_periph_release_locked_busses()) panics if it is done incorrectly.
Since devfs has to drop its locks while it calls a driver's close
routine, and it does not have a way to delay or prevent open calls
while it is calling the close routine, there is a race.
The sequence of events, simplified a bit, is:
- devfs acquires a lock
- devfs checks the reference count, and if it is 1, continues to close.
- devfs releases the lock
- 2nd process open call on the device happens here
- devfs calls the driver's close routine
- devfs acquires a lock
- devfs decrements the reference count
- devfs releases the lock
- 2nd process close call on the device happens here
At the second close, we get a panic in
cam_periph_release_locked_busses(), complaining that peripheral
has been released when the reference count is already 0. This is
because we have gotten two closes in a row, which should not
happen.
The fix is to add the D_TRACKCLOSE flag to the driver's cdevsw, so
that we get a close() call for each open(). That does happen
reliably, so we can make sure that our reference counts are
correct.
Note that the sa(4) and pt(4) drivers only allow one context
through the open routine. So these drivers aren't exposed to the
same race condition.
scsi_ch.c,
scsi_enc.c,
scsi_enc_internal.h,
scsi_pass.c,
scsi_sg.c:
For these drivers, change the open() routine to
increment the reference count for every open, and
just decrement the reference count in the close.
Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
scsi_pt.c: Call cam_periph_release_locked() in some scenarios
to avoid additional lock and unlock calls.
MFC after: 3 days
2012-05-27 06:11:09 +00:00
|
|
|
cam_periph_release_locked(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
cam_periph_unlock(periph);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unhold(periph);
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
|
|
|
|
softc->open_count++;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
cam_periph_unlock(periph);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
chclose(struct cdev *dev, int flag, int fmt, struct thread *td)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
struct cam_sim *sim;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct cam_periph *periph;
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
struct ch_softc *softc;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2002-08-15 20:54:03 +00:00
|
|
|
periph = (struct cam_periph *)dev->si_drv1;
|
1998-09-15 06:36:34 +00:00
|
|
|
if (periph == NULL)
|
|
|
|
return(ENXIO);
|
|
|
|
|
Fix a device departure bug for the the pass(4), enc(4), sg(4) and ch(4)
drivers.
The bug occurrs when a userland process has the driver instance
open and the underlying device goes away. We get the devfs
callback that the device node has been destroyed, but not all of
the closes necessary to fully decrement the reference count on the
CAM peripheral.
The reason is that once devfs calls back and says the device has
been destroyed, it is moved off to deadfs, and devfs guarantees
that there will be no more open or close calls. So the solution
is to keep track of how many outstanding open calls there are on
the device, and just release that many references when we get the
callback from devfs.
scsi_pass.c,
scsi_enc.c,
scsi_enc_internal.h: Add an open count to the softc in these
drivers. Increment it on open and
decrement it on close.
When we get a devfs callback to say that
the device node has gone away, decrement
the peripheral reference count by the
number of still outstanding opens.
Make sure we don't access the peripheral
with cam_periph_unlock() after what might
be the final call to
cam_periph_release_locked(). The
peripheral might have been freed, and we
will be dereferencing freed memory.
scsi_ch.c,
scsi_sg.c: For the ch(4) and sg(4) drivers, add the
same changes described above, and in
addition, fix another bug that was
previously fixed in the pass(4) and enc(4)
drivers.
These drivers were calling destroy_dev()
from their cleanup routine, but that could
cause a deadlock because the cleanup
routine could be indirectly called from
the driver's close routine. This would
cause a deadlock, because the device node
is being held open by the active close
call, and can't be destroyed.
Sponsored by: Spectra Logic Corporation
MFC after: 1 week
2012-12-08 04:03:04 +00:00
|
|
|
sim = periph->sim;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
mtx_lock(sim->mtx);
|
|
|
|
|
|
|
|
softc->open_count--;
|
|
|
|
|
|
|
|
cam_periph_release_locked(periph);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We reference the SIM lock directly here, instead of using
|
|
|
|
* cam_periph_unlock(). The reason is that the call to
|
|
|
|
* cam_periph_release_locked() above could result in the periph
|
|
|
|
* getting freed. If that is the case, dereferencing the periph
|
|
|
|
* with a cam_periph_unlock() call would cause a page fault.
|
|
|
|
*
|
|
|
|
* cam_periph_release() avoids this problem using the same method,
|
|
|
|
* but we're manually acquiring and dropping the lock here to
|
|
|
|
* protect the open count and avoid another lock acquisition and
|
|
|
|
* release.
|
|
|
|
*/
|
|
|
|
mtx_unlock(sim->mtx);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chstart(struct cam_periph *periph, union ccb *start_ccb)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
switch (softc->state) {
|
|
|
|
case CH_STATE_NORMAL:
|
|
|
|
{
|
|
|
|
if (periph->immediate_priority <= periph->pinfo.priority){
|
|
|
|
start_ccb->ccb_h.ccb_state = CH_CCB_WAITING;
|
|
|
|
|
|
|
|
SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
|
|
|
|
periph_links.sle);
|
|
|
|
periph->immediate_priority = CAM_PRIORITY_NONE;
|
|
|
|
wakeup(&periph->ccb_list);
|
2007-04-15 08:49:19 +00:00
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CH_STATE_PROBE:
|
|
|
|
{
|
1998-10-02 05:25:49 +00:00
|
|
|
int mode_buffer_len;
|
|
|
|
void *mode_buffer;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
/*
|
|
|
|
* Include the block descriptor when calculating the mode
|
|
|
|
* buffer length,
|
|
|
|
*/
|
|
|
|
mode_buffer_len = sizeof(struct scsi_mode_header_6) +
|
|
|
|
sizeof(struct scsi_mode_blk_desc) +
|
|
|
|
sizeof(struct page_element_address_assignment);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2007-05-14 21:48:53 +00:00
|
|
|
mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
|
1998-10-02 05:25:49 +00:00
|
|
|
|
|
|
|
if (mode_buffer == NULL) {
|
1998-09-15 06:36:34 +00:00
|
|
|
printf("chstart: couldn't malloc mode sense data\n");
|
|
|
|
break;
|
|
|
|
}
|
1998-10-02 05:25:49 +00:00
|
|
|
bzero(mode_buffer, mode_buffer_len);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the element address assignment page.
|
|
|
|
*/
|
|
|
|
scsi_mode_sense(&start_ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* dbd */ (softc->quirks & CH_Q_NO_DBD) ?
|
|
|
|
FALSE : TRUE,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* page_code */ SMS_PAGE_CTRL_CURRENT,
|
|
|
|
/* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* param_buf */ (u_int8_t *)mode_buffer,
|
|
|
|
/* param_len */ mode_buffer_len,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_MODE_SENSE);
|
|
|
|
|
|
|
|
start_ccb->ccb_h.ccb_bp = NULL;
|
|
|
|
start_ccb->ccb_h.ccb_state = CH_CCB_PROBE;
|
|
|
|
xpt_action(start_ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chdone(struct cam_periph *periph, union ccb *done_ccb)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
csio = &done_ccb->csio;
|
|
|
|
|
|
|
|
switch(done_ccb->ccb_h.ccb_state) {
|
|
|
|
case CH_CCB_PROBE:
|
|
|
|
{
|
1998-10-02 05:25:49 +00:00
|
|
|
struct scsi_mode_header_6 *mode_header;
|
|
|
|
struct page_element_address_assignment *ea;
|
1998-09-15 06:36:34 +00:00
|
|
|
char announce_buf[80];
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
|
|
|
|
mode_header = (struct scsi_mode_header_6 *)csio->data_ptr;
|
|
|
|
|
|
|
|
ea = (struct page_element_address_assignment *)
|
|
|
|
find_mode_page_6(mode_header);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP){
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
|
|
|
|
softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
|
|
|
|
softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
|
|
|
|
softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
|
|
|
|
softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
|
|
|
|
softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
|
|
|
|
softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
|
|
|
|
softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
|
1998-09-15 06:36:34 +00:00
|
|
|
softc->sc_picker = softc->sc_firsts[CHET_MT];
|
|
|
|
|
|
|
|
#define PLURAL(c) (c) == 1 ? "" : "s"
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(announce_buf, sizeof(announce_buf),
|
|
|
|
"%d slot%s, %d drive%s, "
|
1998-09-15 06:36:34 +00:00
|
|
|
"%d picker%s, %d portal%s",
|
|
|
|
softc->sc_counts[CHET_ST],
|
|
|
|
PLURAL(softc->sc_counts[CHET_ST]),
|
|
|
|
softc->sc_counts[CHET_DT],
|
|
|
|
PLURAL(softc->sc_counts[CHET_DT]),
|
|
|
|
softc->sc_counts[CHET_MT],
|
|
|
|
PLURAL(softc->sc_counts[CHET_MT]),
|
|
|
|
softc->sc_counts[CHET_IE],
|
|
|
|
PLURAL(softc->sc_counts[CHET_IE]));
|
|
|
|
#undef PLURAL
|
|
|
|
} else {
|
|
|
|
int error;
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cherror(done_ccb, CAM_RETRY_SELTO,
|
|
|
|
SF_RETRY_UA | SF_NO_PRINT);
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Retry any UNIT ATTENTION type errors. They
|
|
|
|
* are expected at boot.
|
|
|
|
*/
|
|
|
|
if (error == ERESTART) {
|
|
|
|
/*
|
|
|
|
* A retry was scheuled, so
|
|
|
|
* just return.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
} else if (error != 0) {
|
1998-10-02 05:25:49 +00:00
|
|
|
int retry_scheduled;
|
|
|
|
struct scsi_mode_sense_6 *sms;
|
|
|
|
|
|
|
|
sms = (struct scsi_mode_sense_6 *)
|
|
|
|
done_ccb->csio.cdb_io.cdb_bytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if block descriptors were
|
|
|
|
* disabled. Some devices don't like that.
|
|
|
|
* We're taking advantage of the fact that
|
|
|
|
* the first few bytes of the 6 and 10 byte
|
|
|
|
* mode sense commands are the same. If
|
|
|
|
* block descriptors were disabled, enable
|
|
|
|
* them and re-send the command.
|
|
|
|
*/
|
|
|
|
if (sms->byte2 & SMS_DBD) {
|
|
|
|
sms->byte2 &= ~SMS_DBD;
|
|
|
|
xpt_action(done_ccb);
|
|
|
|
softc->quirks |= CH_Q_NO_DBD;
|
|
|
|
retry_scheduled = 1;
|
|
|
|
} else
|
|
|
|
retry_scheduled = 0;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/* Don't wedge this device's queue */
|
2009-11-14 20:13:38 +00:00
|
|
|
if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
|
|
|
|
cam_release_devq(done_ccb->ccb_h.path,
|
1998-09-15 06:36:34 +00:00
|
|
|
/*relsim_flags*/0,
|
|
|
|
/*reduction*/0,
|
|
|
|
/*timeout*/0,
|
|
|
|
/*getcount_only*/0);
|
1998-10-02 05:25:49 +00:00
|
|
|
|
|
|
|
if (retry_scheduled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((done_ccb->ccb_h.status & CAM_STATUS_MASK)
|
|
|
|
== CAM_SCSI_STATUS_ERROR)
|
|
|
|
scsi_sense_print(&done_ccb->csio);
|
|
|
|
else {
|
2006-12-05 07:45:28 +00:00
|
|
|
xpt_print(periph->path,
|
|
|
|
"got CAM status %#x\n",
|
|
|
|
done_ccb->ccb_h.status);
|
1998-10-02 05:25:49 +00:00
|
|
|
}
|
2006-12-05 07:45:28 +00:00
|
|
|
xpt_print(periph->path, "fatal error, failed "
|
|
|
|
"to attach to device\n");
|
1998-10-02 05:25:49 +00:00
|
|
|
|
|
|
|
cam_periph_invalidate(periph);
|
|
|
|
|
|
|
|
announce_buf[0] = '\0';
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-18 23:36:21 +00:00
|
|
|
if (announce_buf[0] != '\0') {
|
1998-10-02 05:25:49 +00:00
|
|
|
xpt_announce_periph(periph, announce_buf);
|
2013-05-18 23:36:21 +00:00
|
|
|
xpt_announce_quirks(periph, softc->quirks,
|
|
|
|
CH_Q_BIT_STRING);
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
softc->state = CH_STATE_NORMAL;
|
2007-05-14 21:48:53 +00:00
|
|
|
free(mode_header, M_SCSICH);
|
2000-04-02 07:49:09 +00:00
|
|
|
/*
|
|
|
|
* Since our peripheral may be invalidated by an error
|
|
|
|
* above or an external event, we must release our CCB
|
|
|
|
* before releasing the probe lock on the peripheral.
|
|
|
|
* The peripheral will only go away once the last lock
|
|
|
|
* is removed, and we need it around for the CCB release
|
|
|
|
* operation.
|
|
|
|
*/
|
|
|
|
xpt_release_ccb(done_ccb);
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unhold(periph);
|
2000-04-02 07:49:09 +00:00
|
|
|
return;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
case CH_CCB_WAITING:
|
|
|
|
{
|
|
|
|
/* Caller will release the CCB */
|
|
|
|
wakeup(&done_ccb->ccb_h.cbfcnp);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-02 07:49:09 +00:00
|
|
|
default:
|
|
|
|
break;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
xpt_release_ccb(done_ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cherror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
struct cam_periph *periph;
|
|
|
|
|
|
|
|
periph = xpt_path_periph(ccb->ccb_h.path);
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
return (cam_periph_error(ccb, cam_flags, sense_flags,
|
|
|
|
&softc->saved_ccb));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
chioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct ch_softc *softc;
|
|
|
|
int error;
|
|
|
|
|
2002-08-15 20:54:03 +00:00
|
|
|
periph = (struct cam_periph *)dev->si_drv1;
|
1998-09-15 06:36:34 +00:00
|
|
|
if (periph == NULL)
|
|
|
|
return(ENXIO);
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering chioctl\n"));
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
|
1998-10-02 21:20:21 +00:00
|
|
|
("trying to do ioctl %#lx\n", cmd));
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this command can change the device's state, we must
|
|
|
|
* have the device open for writing.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case CHIOGPICKER:
|
|
|
|
case CHIOGPARAMS:
|
2013-04-19 20:03:51 +00:00
|
|
|
case OCHIOGSTATUS:
|
1998-09-15 06:36:34 +00:00
|
|
|
case CHIOGSTATUS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-04-15 08:49:19 +00:00
|
|
|
if ((flag & FWRITE) == 0) {
|
|
|
|
cam_periph_unlock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
return (EBADF);
|
2007-04-15 08:49:19 +00:00
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CHIOMOVE:
|
|
|
|
error = chmove(periph, (struct changer_move *)addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHIOEXCHANGE:
|
|
|
|
error = chexchange(periph, (struct changer_exchange *)addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHIOPOSITION:
|
|
|
|
error = chposition(periph, (struct changer_position *)addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHIOGPICKER:
|
|
|
|
*(int *)addr = softc->sc_picker - softc->sc_firsts[CHET_MT];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHIOSPICKER:
|
|
|
|
{
|
|
|
|
int new_picker = *(int *)addr;
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
if (new_picker > (softc->sc_counts[CHET_MT] - 1)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
softc->sc_picker = softc->sc_firsts[CHET_MT] + new_picker;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CHIOGPARAMS:
|
|
|
|
{
|
|
|
|
struct changer_params *cp = (struct changer_params *)addr;
|
|
|
|
|
|
|
|
cp->cp_npickers = softc->sc_counts[CHET_MT];
|
|
|
|
cp->cp_nslots = softc->sc_counts[CHET_ST];
|
|
|
|
cp->cp_nportals = softc->sc_counts[CHET_IE];
|
|
|
|
cp->cp_ndrives = softc->sc_counts[CHET_DT];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CHIOIELEM:
|
|
|
|
error = chielem(periph, *(unsigned int *)addr);
|
|
|
|
break;
|
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
case OCHIOGSTATUS:
|
|
|
|
{
|
|
|
|
error = chgetelemstatus(periph, SCSI_REV_2, cmd,
|
|
|
|
(struct changer_element_status_request *)addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
case CHIOGSTATUS:
|
|
|
|
{
|
2013-04-19 20:03:51 +00:00
|
|
|
int scsi_version;
|
|
|
|
|
|
|
|
scsi_version = chscsiversion(periph);
|
|
|
|
if (scsi_version >= SCSI_REV_0) {
|
|
|
|
error = chgetelemstatus(periph, scsi_version, cmd,
|
|
|
|
(struct changer_element_status_request *)addr);
|
|
|
|
}
|
|
|
|
else { /* unable to determine the SCSI version */
|
|
|
|
cam_periph_unlock(periph);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CHIOSETVOLTAG:
|
|
|
|
{
|
|
|
|
error = chsetvoltag(periph,
|
|
|
|
(struct changer_set_voltag_request *) addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implement prevent/allow? */
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = cam_periph_ioctl(periph, cmd, addr, cherror);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unlock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chmove(struct cam_periph *periph, struct changer_move *cm)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
u_int16_t fromelem, toelem;
|
|
|
|
union ccb *ccb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check arguments.
|
|
|
|
*/
|
|
|
|
if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
|
|
|
|
return (EINVAL);
|
|
|
|
if ((cm->cm_fromunit > (softc->sc_counts[cm->cm_fromtype] - 1)) ||
|
|
|
|
(cm->cm_tounit > (softc->sc_counts[cm->cm_totype] - 1)))
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the request against the changer's capabilities.
|
|
|
|
*/
|
|
|
|
if ((softc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
|
1998-12-12 23:52:46 +00:00
|
|
|
return (ENODEV);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the source and destination elements.
|
|
|
|
*/
|
|
|
|
fromelem = softc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
|
|
|
|
toelem = softc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
scsi_move_medium(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* tea */ softc->sc_picker,
|
|
|
|
/* src */ fromelem,
|
|
|
|
/* dst */ toelem,
|
|
|
|
/* invert */ (cm->cm_flags & CM_INVERT) ? TRUE : FALSE,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_MOVE_MEDIUM);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chexchange(struct cam_periph *periph, struct changer_exchange *ce)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
u_int16_t src, dst1, dst2;
|
|
|
|
union ccb *ccb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
/*
|
|
|
|
* Check arguments.
|
|
|
|
*/
|
|
|
|
if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
|
|
|
|
(ce->ce_sdsttype > CHET_DT))
|
|
|
|
return (EINVAL);
|
|
|
|
if ((ce->ce_srcunit > (softc->sc_counts[ce->ce_srctype] - 1)) ||
|
|
|
|
(ce->ce_fdstunit > (softc->sc_counts[ce->ce_fdsttype] - 1)) ||
|
|
|
|
(ce->ce_sdstunit > (softc->sc_counts[ce->ce_sdsttype] - 1)))
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the request against the changer's capabilities.
|
|
|
|
*/
|
|
|
|
if (((softc->sc_exchangemask[ce->ce_srctype] &
|
|
|
|
(1 << ce->ce_fdsttype)) == 0) ||
|
|
|
|
((softc->sc_exchangemask[ce->ce_fdsttype] &
|
|
|
|
(1 << ce->ce_sdsttype)) == 0))
|
1998-12-12 23:52:46 +00:00
|
|
|
return (ENODEV);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the source and destination elements.
|
|
|
|
*/
|
|
|
|
src = softc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
|
|
|
|
dst1 = softc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
|
|
|
|
dst2 = softc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
scsi_exchange_medium(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* tea */ softc->sc_picker,
|
|
|
|
/* src */ src,
|
|
|
|
/* dst1 */ dst1,
|
|
|
|
/* dst2 */ dst2,
|
|
|
|
/* invert1 */ (ce->ce_flags & CE_INVERT1) ?
|
|
|
|
TRUE : FALSE,
|
|
|
|
/* invert2 */ (ce->ce_flags & CE_INVERT2) ?
|
|
|
|
TRUE : FALSE,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_EXCHANGE_MEDIUM);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chposition(struct cam_periph *periph, struct changer_position *cp)
|
|
|
|
{
|
|
|
|
struct ch_softc *softc;
|
|
|
|
u_int16_t dst;
|
|
|
|
union ccb *ccb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check arguments.
|
|
|
|
*/
|
|
|
|
if (cp->cp_type > CHET_DT)
|
|
|
|
return (EINVAL);
|
|
|
|
if (cp->cp_unit > (softc->sc_counts[cp->cp_type] - 1))
|
|
|
|
return (ENODEV);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the destination element.
|
|
|
|
*/
|
|
|
|
dst = softc->sc_firsts[cp->cp_type] + cp->cp_unit;
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
scsi_position_to_element(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* tea */ softc->sc_picker,
|
|
|
|
/* dst */ dst,
|
|
|
|
/* invert */ (cp->cp_flags & CP_INVERT) ?
|
|
|
|
TRUE : FALSE,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_POSITION_TO_ELEMENT);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a volume tag to a volume_tag struct, converting SCSI byte order
|
|
|
|
* to host native byte order in the volume serial number. The volume
|
|
|
|
* label as returned by the changer is transferred to user mode as
|
|
|
|
* nul-terminated string. Volume labels are truncated at the first
|
|
|
|
* space, as suggested by SCSI-2.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<CH_VOLTAG_MAXLEN; i++) {
|
|
|
|
char c = voltag->vif[i];
|
|
|
|
if (c && c != ' ')
|
|
|
|
uvoltag->cv_volid[i] = c;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uvoltag->cv_serial = scsi_2btoul(voltag->vsn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-04-19 20:03:51 +00:00
|
|
|
* Copy an element status descriptor to a user-mode
|
1998-09-15 06:36:34 +00:00
|
|
|
* changer_element_status structure.
|
|
|
|
*/
|
2013-04-19 20:03:51 +00:00
|
|
|
static void
|
1998-09-15 06:36:34 +00:00
|
|
|
copy_element_status(struct ch_softc *softc,
|
|
|
|
u_int16_t flags,
|
|
|
|
struct read_element_status_descriptor *desc,
|
2013-04-19 20:03:51 +00:00
|
|
|
struct changer_element_status *ces,
|
|
|
|
int scsi_version)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
|
|
|
u_int16_t eaddr = scsi_2btoul(desc->eaddr);
|
|
|
|
u_int16_t et;
|
2013-04-19 20:03:51 +00:00
|
|
|
struct volume_tag *pvol_tag = NULL, *avol_tag = NULL;
|
|
|
|
struct read_element_status_device_id *devid = NULL;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
ces->ces_int_addr = eaddr;
|
|
|
|
/* set up logical address in element status */
|
|
|
|
for (et = CHET_MT; et <= CHET_DT; et++) {
|
|
|
|
if ((softc->sc_firsts[et] <= eaddr)
|
|
|
|
&& ((softc->sc_firsts[et] + softc->sc_counts[et])
|
|
|
|
> eaddr)) {
|
|
|
|
ces->ces_addr = eaddr - softc->sc_firsts[et];
|
|
|
|
ces->ces_type = et;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ces->ces_flags = desc->flags1;
|
|
|
|
|
|
|
|
ces->ces_sensecode = desc->sense_code;
|
|
|
|
ces->ces_sensequal = desc->sense_qual;
|
|
|
|
|
|
|
|
if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
|
|
|
|
ces->ces_flags |= CES_INVERT;
|
|
|
|
|
|
|
|
if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
|
|
|
|
|
|
|
|
eaddr = scsi_2btoul(desc->ssea);
|
|
|
|
|
|
|
|
/* convert source address to logical format */
|
|
|
|
for (et = CHET_MT; et <= CHET_DT; et++) {
|
|
|
|
if ((softc->sc_firsts[et] <= eaddr)
|
|
|
|
&& ((softc->sc_firsts[et] + softc->sc_counts[et])
|
|
|
|
> eaddr)) {
|
2013-04-19 20:03:51 +00:00
|
|
|
ces->ces_source_addr =
|
1998-09-15 06:36:34 +00:00
|
|
|
eaddr - softc->sc_firsts[et];
|
|
|
|
ces->ces_source_type = et;
|
|
|
|
ces->ces_flags |= CES_SOURCE_VALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ces->ces_flags & CES_SOURCE_VALID))
|
|
|
|
printf("ch: warning: could not map element source "
|
2000-04-02 07:49:09 +00:00
|
|
|
"address %ud to a valid element type\n",
|
1998-09-15 06:36:34 +00:00
|
|
|
eaddr);
|
|
|
|
}
|
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
/*
|
|
|
|
* pvoltag and avoltag are common between SCSI-2 and later versions
|
|
|
|
*/
|
1998-09-15 06:36:34 +00:00
|
|
|
if (flags & READ_ELEMENT_STATUS_PVOLTAG)
|
2013-04-19 20:03:51 +00:00
|
|
|
pvol_tag = &desc->voltag_devid.pvoltag;
|
1998-09-15 06:36:34 +00:00
|
|
|
if (flags & READ_ELEMENT_STATUS_AVOLTAG)
|
2013-04-19 20:03:51 +00:00
|
|
|
avol_tag = (flags & READ_ELEMENT_STATUS_PVOLTAG) ?
|
|
|
|
&desc->voltag_devid.voltag[1] :&desc->voltag_devid.pvoltag;
|
|
|
|
/*
|
|
|
|
* For SCSI-3 and later, element status can carry designator and
|
|
|
|
* other information.
|
|
|
|
*/
|
|
|
|
if (scsi_version >= SCSI_REV_SPC) {
|
|
|
|
if ((flags & READ_ELEMENT_STATUS_PVOLTAG) ^
|
|
|
|
(flags & READ_ELEMENT_STATUS_AVOLTAG))
|
|
|
|
devid = &desc->voltag_devid.pvol_and_devid.devid;
|
|
|
|
else if (!(flags & READ_ELEMENT_STATUS_PVOLTAG) &&
|
|
|
|
!(flags & READ_ELEMENT_STATUS_AVOLTAG))
|
|
|
|
devid = &desc->voltag_devid.devid;
|
|
|
|
else /* Have both PVOLTAG and AVOLTAG */
|
|
|
|
devid = &desc->voltag_devid.vol_tags_and_devid.devid;
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
if (pvol_tag)
|
|
|
|
copy_voltag(&(ces->ces_pvoltag), pvol_tag);
|
|
|
|
if (avol_tag)
|
|
|
|
copy_voltag(&(ces->ces_pvoltag), avol_tag);
|
|
|
|
if (devid != NULL) {
|
|
|
|
if (devid->designator_length > 0) {
|
|
|
|
bcopy((void *)devid->designator,
|
|
|
|
(void *)ces->ces_designator,
|
|
|
|
devid->designator_length);
|
|
|
|
ces->ces_designator_length = devid->designator_length;
|
|
|
|
/*
|
|
|
|
* Make sure we are always NUL terminated. The
|
2013-04-20 14:33:55 +00:00
|
|
|
* This won't matter for the binary code set,
|
|
|
|
* since the user will only pay attention to the
|
|
|
|
* length field.
|
2013-04-19 20:03:51 +00:00
|
|
|
*/
|
2013-04-20 14:33:55 +00:00
|
|
|
ces->ces_designator[devid->designator_length]= '\0';
|
2013-04-19 20:03:51 +00:00
|
|
|
}
|
|
|
|
if (devid->piv_assoc_designator_type &
|
|
|
|
READ_ELEMENT_STATUS_PIV_SET) {
|
|
|
|
ces->ces_flags |= CES_PIV;
|
|
|
|
ces->ces_protocol_id =
|
|
|
|
READ_ELEMENT_STATUS_PROTOCOL_ID(
|
|
|
|
devid->prot_code_set);
|
|
|
|
}
|
|
|
|
ces->ces_code_set =
|
|
|
|
READ_ELEMENT_STATUS_CODE_SET(devid->prot_code_set);
|
|
|
|
ces->ces_assoc = READ_ELEMENT_STATUS_ASSOCIATION(
|
|
|
|
devid->piv_assoc_designator_type);
|
|
|
|
ces->ces_designator_type = READ_ELEMENT_STATUS_DESIGNATOR_TYPE(
|
|
|
|
devid->piv_assoc_designator_type);
|
|
|
|
} else if (scsi_version > SCSI_REV_2) {
|
|
|
|
/* SCSI-SPC and No devid, no designator */
|
|
|
|
ces->ces_designator_length = 0;
|
|
|
|
ces->ces_designator[0] = '\0';
|
|
|
|
ces->ces_protocol_id = CES_PROTOCOL_ID_FCP_4;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
if (scsi_version <= SCSI_REV_2) {
|
|
|
|
if (desc->dt_or_obsolete.scsi_2.dt_scsi_flags &
|
|
|
|
READ_ELEMENT_STATUS_DT_IDVALID) {
|
|
|
|
ces->ces_flags |= CES_SCSIID_VALID;
|
|
|
|
ces->ces_scsi_id =
|
|
|
|
desc->dt_or_obsolete.scsi_2.dt_scsi_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->dt_or_obsolete.scsi_2.dt_scsi_addr &
|
|
|
|
READ_ELEMENT_STATUS_DT_LUVALID) {
|
|
|
|
ces->ces_flags |= CES_LUN_VALID;
|
|
|
|
ces->ces_scsi_lun =
|
|
|
|
desc->dt_or_obsolete.scsi_2.dt_scsi_flags &
|
|
|
|
READ_ELEMENT_STATUS_DT_LUNMASK;
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-19 20:03:51 +00:00
|
|
|
chgetelemstatus(struct cam_periph *periph, int scsi_version, u_long cmd,
|
1998-09-15 06:36:34 +00:00
|
|
|
struct changer_element_status_request *cesr)
|
|
|
|
{
|
|
|
|
struct read_element_status_header *st_hdr;
|
|
|
|
struct read_element_status_page_header *pg_hdr;
|
|
|
|
struct read_element_status_descriptor *desc;
|
|
|
|
caddr_t data = NULL;
|
|
|
|
size_t size, desclen;
|
|
|
|
int avail, i, error = 0;
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
int curdata, dvcid, sense_flags;
|
|
|
|
int try_no_dvcid = 0;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct changer_element_status *user_data = NULL;
|
|
|
|
struct ch_softc *softc;
|
|
|
|
union ccb *ccb;
|
|
|
|
int chet = cesr->cesr_element_type;
|
|
|
|
int want_voltags = (cesr->cesr_flags & CESR_VOLTAGS) ? 1 : 0;
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
/* perform argument checking */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a range check on the cesr_element_{base,count}
|
|
|
|
* request argument fields.
|
|
|
|
*/
|
|
|
|
if ((softc->sc_counts[chet] - cesr->cesr_element_base) <= 0
|
|
|
|
|| (cesr->cesr_element_base + cesr->cesr_element_count)
|
|
|
|
> softc->sc_counts[chet])
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request one descriptor for the given element type. This
|
|
|
|
* is used to determine the size of the descriptor so that
|
|
|
|
* we can allocate enough storage for all of them. We assume
|
|
|
|
* that the first one can fit into 1k.
|
|
|
|
*/
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unlock(periph);
|
2003-02-19 05:47:46 +00:00
|
|
|
data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
sense_flags = SF_RETRY_UA;
|
|
|
|
if (softc->quirks & CH_Q_NO_DVCID) {
|
|
|
|
dvcid = 0;
|
|
|
|
curdata = 0;
|
|
|
|
} else {
|
|
|
|
dvcid = 1;
|
|
|
|
curdata = 1;
|
|
|
|
/*
|
|
|
|
* Don't print anything for an Illegal Request, because
|
|
|
|
* these flags can cause some changers to complain. We'll
|
|
|
|
* retry without them if we get an error.
|
|
|
|
*/
|
|
|
|
sense_flags |= SF_QUIET_IR;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry_einval:
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
scsi_read_element_status(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* voltag */ want_voltags,
|
|
|
|
/* sea */ softc->sc_firsts[chet],
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
/* curdata */ curdata,
|
2013-07-15 16:38:48 +00:00
|
|
|
/* dvcid */ dvcid,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* count */ 1,
|
|
|
|
/* data_ptr */ data,
|
|
|
|
/* dxfer_len */ 1024,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
/*sense_flags*/ sense_flags,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
/*
|
|
|
|
* An Illegal Request sense key (only used if there is no asc/ascq)
|
|
|
|
* or 0x24,0x00 for an ASC/ASCQ both map to EINVAL. If dvcid or
|
|
|
|
* curdata are set (we set both or neither), try turning them off
|
|
|
|
* and see if the command is successful.
|
|
|
|
*/
|
|
|
|
if ((error == EINVAL)
|
|
|
|
&& (dvcid || curdata)) {
|
|
|
|
dvcid = 0;
|
|
|
|
curdata = 0;
|
|
|
|
error = 0;
|
|
|
|
/* At this point we want to report any Illegal Request */
|
|
|
|
sense_flags &= ~SF_QUIET_IR;
|
|
|
|
try_no_dvcid = 1;
|
|
|
|
goto retry_einval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In this case, we tried a read element status with dvcid and
|
|
|
|
* curdata set, and it failed. We retried without those bits, and
|
|
|
|
* it succeeded. Suggest to the user that he set a quirk, so we
|
|
|
|
* don't go through the retry process the first time in the future.
|
|
|
|
* This should only happen on changers that claim SCSI-3 or higher,
|
|
|
|
* but don't support these bits.
|
|
|
|
*/
|
|
|
|
if ((try_no_dvcid != 0)
|
|
|
|
&& (error == 0))
|
|
|
|
softc->quirks |= CH_Q_NO_DVCID;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
if (error)
|
|
|
|
goto done;
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unlock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
st_hdr = (struct read_element_status_header *)data;
|
1999-08-24 00:04:45 +00:00
|
|
|
pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
|
1998-09-15 06:36:34 +00:00
|
|
|
sizeof(struct read_element_status_header));
|
|
|
|
desclen = scsi_2btoul(pg_hdr->edl);
|
|
|
|
|
|
|
|
size = sizeof(struct read_element_status_header) +
|
|
|
|
sizeof(struct read_element_status_page_header) +
|
|
|
|
(desclen * cesr->cesr_element_count);
|
|
|
|
/*
|
|
|
|
* Reallocate storage for descriptors and get them from the
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
free(data, M_DEVBUF);
|
2003-02-19 05:47:46 +00:00
|
|
|
data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
scsi_read_element_status(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* voltag */ want_voltags,
|
|
|
|
/* sea */ softc->sc_firsts[chet]
|
|
|
|
+ cesr->cesr_element_base,
|
Fix a problem with READ ELEMENT STATUS that occurs on some
changers that don't support the DVCID and CURDATA bits that were
introduced in the SMC spec.
These changers will return an Illegal Request type error if the
bits are set. This causes "chio status" to fail.
The fix is two-fold. First, for changers that claim to be SCSI-2
or older, don't set the DVCID and CURDATA bits for READ ELEMENT
STATUS. For newer changers (SCSI-3 and newer), we default to
setting the new bits, but back off and try the READ ELEMENT STATUS
without the bits if we get an Illegal Request type error.
This has been tested on a Qualstar TLS-8211, which is a SCSI-2
changer that does not support the new bits, and a Spectra T-380,
which is a SCSI-3 changer that does support the new bits. In the
absence of a SCSI-3 changer that does not support the bits, I
tested that with some error injection code. (The SMC spec says
that support for CURDATA is mandatory, and DVCID is optional.)
scsi_ch.c: Add a new quirk, CH_Q_NO_DVCID that gets set for
SCSI-2 and older libraries, or newer libraries that
report errors when the DVCID/CURDATA bits are set.
In chgetelemstatus(), use the new quirk to
determine whether or not to set DVCID and CURDATA.
If we get an error with the bits set, back off and
try without the bits. Set the quirk flag if the
read element status succeeds without the bits set.
Increase the READ ELEMENT STATUS timeout to 60
seconds after testing with a Spectra T-380. The
previous value was 10 seconds, and too short for
the T-380. This may be decreased later after
some additional testing and investigation.
Tested by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
Sponsored by: Spectra Logic
MFC after: 3 days
2013-07-12 17:09:50 +00:00
|
|
|
/* curdata */ curdata,
|
2013-07-15 16:38:48 +00:00
|
|
|
/* dvcid */ dvcid,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* count */ cesr->cesr_element_count,
|
|
|
|
/* data_ptr */ data,
|
|
|
|
/* dxfer_len */ size,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_READ_ELEMENT_STATUS);
|
2013-04-19 20:03:51 +00:00
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
goto done;
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_unlock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the user status array.
|
|
|
|
*/
|
|
|
|
st_hdr = (struct read_element_status_header *)data;
|
2005-03-26 04:21:11 +00:00
|
|
|
pg_hdr = (struct read_element_status_page_header *)((uintptr_t)st_hdr +
|
|
|
|
sizeof(struct read_element_status_header));
|
1998-09-15 06:36:34 +00:00
|
|
|
avail = scsi_2btoul(st_hdr->count);
|
|
|
|
|
|
|
|
if (avail != cesr->cesr_element_count) {
|
2006-12-05 07:45:28 +00:00
|
|
|
xpt_print(periph->path,
|
|
|
|
"warning, READ ELEMENT STATUS avail != count\n");
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
user_data = (struct changer_element_status *)
|
|
|
|
malloc(avail * sizeof(struct changer_element_status),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_DEVBUF, M_WAITOK | M_ZERO);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-08-24 00:04:45 +00:00
|
|
|
desc = (struct read_element_status_descriptor *)((uintptr_t)data +
|
1998-09-15 06:36:34 +00:00
|
|
|
sizeof(struct read_element_status_header) +
|
|
|
|
sizeof(struct read_element_status_page_header));
|
|
|
|
/*
|
|
|
|
* Set up the individual element status structures
|
|
|
|
*/
|
|
|
|
for (i = 0; i < avail; ++i) {
|
2013-04-19 20:03:51 +00:00
|
|
|
struct changer_element_status *ces;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
/*
|
|
|
|
* In the changer_element_status structure, fields from
|
|
|
|
* the beginning to the field of ces_scsi_lun are common
|
|
|
|
* between SCSI-2 and SCSI-3, while all the rest are new
|
|
|
|
* from SCSI-3. In order to maintain backward compatibility
|
|
|
|
* of the chio command, the ces pointer, below, is computed
|
|
|
|
* such that it lines up with the structure boundary
|
|
|
|
* corresponding to the SCSI version.
|
|
|
|
*/
|
|
|
|
ces = cmd == OCHIOGSTATUS ?
|
|
|
|
(struct changer_element_status *)
|
|
|
|
((unsigned char *)user_data + i *
|
|
|
|
(offsetof(struct changer_element_status,ces_scsi_lun)+1)):
|
|
|
|
&user_data[i];
|
|
|
|
|
|
|
|
copy_element_status(softc, pg_hdr->flags, desc,
|
|
|
|
ces, scsi_version);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-08-24 00:04:45 +00:00
|
|
|
desc = (struct read_element_status_descriptor *)
|
2013-04-19 20:03:51 +00:00
|
|
|
((unsigned char *)desc + desclen);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy element status structures out to userspace. */
|
2013-04-19 20:03:51 +00:00
|
|
|
if (cmd == OCHIOGSTATUS)
|
|
|
|
error = copyout(user_data,
|
|
|
|
cesr->cesr_element_status,
|
|
|
|
avail* (offsetof(struct changer_element_status,
|
|
|
|
ces_scsi_lun) + 1));
|
|
|
|
else
|
|
|
|
error = copyout(user_data,
|
|
|
|
cesr->cesr_element_status,
|
|
|
|
avail * sizeof(struct changer_element_status));
|
|
|
|
|
2007-04-15 08:49:19 +00:00
|
|
|
cam_periph_lock(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
if (data != NULL)
|
|
|
|
free(data, M_DEVBUF);
|
|
|
|
if (user_data != NULL)
|
|
|
|
free(user_data, M_DEVBUF);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chielem(struct cam_periph *periph,
|
|
|
|
unsigned int timeout)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
struct ch_softc *softc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
timeout = CH_TIMEOUT_INITIALIZE_ELEMENT_STATUS;
|
|
|
|
} else {
|
|
|
|
timeout *= 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
scsi_initialize_element_status(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ timeout);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chsetvoltag(struct cam_periph *periph,
|
|
|
|
struct changer_set_voltag_request *csvr)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
struct ch_softc *softc;
|
|
|
|
u_int16_t ea;
|
|
|
|
u_int8_t sac;
|
|
|
|
struct scsi_send_volume_tag_parameters ssvtp;
|
|
|
|
int error;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
|
|
|
bzero(&ssvtp, sizeof(ssvtp));
|
|
|
|
for (i=0; i<sizeof(ssvtp.vitf); i++) {
|
|
|
|
ssvtp.vitf[i] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check arguments.
|
|
|
|
*/
|
|
|
|
if (csvr->csvr_type > CHET_DT)
|
|
|
|
return EINVAL;
|
|
|
|
if (csvr->csvr_addr > (softc->sc_counts[csvr->csvr_type] - 1))
|
|
|
|
return ENODEV;
|
|
|
|
|
|
|
|
ea = softc->sc_firsts[csvr->csvr_type] + csvr->csvr_addr;
|
|
|
|
|
|
|
|
if (csvr->csvr_flags & CSVR_ALTERNATE) {
|
|
|
|
switch (csvr->csvr_flags & CSVR_MODE_MASK) {
|
|
|
|
case CSVR_MODE_SET:
|
|
|
|
sac = SEND_VOLUME_TAG_ASSERT_ALTERNATE;
|
|
|
|
break;
|
|
|
|
case CSVR_MODE_REPLACE:
|
|
|
|
sac = SEND_VOLUME_TAG_REPLACE_ALTERNATE;
|
|
|
|
break;
|
|
|
|
case CSVR_MODE_CLEAR:
|
|
|
|
sac = SEND_VOLUME_TAG_UNDEFINED_ALTERNATE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (csvr->csvr_flags & CSVR_MODE_MASK) {
|
|
|
|
case CSVR_MODE_SET:
|
|
|
|
sac = SEND_VOLUME_TAG_ASSERT_PRIMARY;
|
|
|
|
break;
|
|
|
|
case CSVR_MODE_REPLACE:
|
|
|
|
sac = SEND_VOLUME_TAG_REPLACE_PRIMARY;
|
|
|
|
break;
|
|
|
|
case CSVR_MODE_CLEAR:
|
|
|
|
sac = SEND_VOLUME_TAG_UNDEFINED_PRIMARY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ssvtp.vitf, csvr->csvr_voltag.cv_volid,
|
|
|
|
min(strlen(csvr->csvr_voltag.cv_volid), sizeof(ssvtp.vitf)));
|
|
|
|
scsi_ulto2b(csvr->csvr_voltag.cv_serial, ssvtp.minvsn);
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
scsi_send_volume_tag(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
|
|
|
/* element_address */ ea,
|
|
|
|
/* send_action_code */ sac,
|
|
|
|
/* parameters */ &ssvtp,
|
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_SEND_VOLTAG);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
chgetparams(struct cam_periph *periph)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
struct ch_softc *softc;
|
1998-10-02 05:25:49 +00:00
|
|
|
void *mode_buffer;
|
|
|
|
int mode_buffer_len;
|
|
|
|
struct page_element_address_assignment *ea;
|
|
|
|
struct page_device_capabilities *cap;
|
|
|
|
int error, from, dbd;
|
1998-09-15 06:36:34 +00:00
|
|
|
u_int8_t *moves, *exchanges;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
softc = (struct ch_softc *)periph->softc;
|
|
|
|
|
2009-10-23 08:27:55 +00:00
|
|
|
ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
/*
|
|
|
|
* The scsi_mode_sense_data structure is just a convenience
|
|
|
|
* structure that allows us to easily calculate the worst-case
|
|
|
|
* storage size of the mode sense buffer.
|
|
|
|
*/
|
|
|
|
mode_buffer_len = sizeof(struct scsi_mode_sense_data);
|
|
|
|
|
2007-05-14 21:48:53 +00:00
|
|
|
mode_buffer = malloc(mode_buffer_len, M_SCSICH, M_NOWAIT);
|
1998-10-02 05:25:49 +00:00
|
|
|
|
|
|
|
if (mode_buffer == NULL) {
|
1998-09-15 06:36:34 +00:00
|
|
|
printf("chgetparams: couldn't malloc mode sense data\n");
|
|
|
|
return(ENOSPC);
|
|
|
|
}
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
bzero(mode_buffer, mode_buffer_len);
|
|
|
|
|
|
|
|
if (softc->quirks & CH_Q_NO_DBD)
|
|
|
|
dbd = FALSE;
|
|
|
|
else
|
|
|
|
dbd = TRUE;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the element address assignment page.
|
|
|
|
*/
|
|
|
|
scsi_mode_sense(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* dbd */ dbd,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* page_code */ SMS_PAGE_CTRL_CURRENT,
|
|
|
|
/* page */ CH_ELEMENT_ADDR_ASSIGN_PAGE,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* param_buf */ (u_int8_t *)mode_buffer,
|
|
|
|
/* param_len */ mode_buffer_len,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_MODE_SENSE);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/* sense_flags */ SF_RETRY_UA|SF_NO_PRINT,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (error) {
|
1998-10-02 05:25:49 +00:00
|
|
|
if (dbd) {
|
|
|
|
struct scsi_mode_sense_6 *sms;
|
|
|
|
|
|
|
|
sms = (struct scsi_mode_sense_6 *)
|
|
|
|
ccb->csio.cdb_io.cdb_bytes;
|
|
|
|
|
|
|
|
sms->byte2 &= ~SMS_DBD;
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror,
|
|
|
|
/*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-10-02 05:25:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Since we disabled sense printing above, print
|
|
|
|
* out the sense here since we got an error.
|
|
|
|
*/
|
|
|
|
scsi_sense_print(&ccb->csio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
2006-12-05 07:45:28 +00:00
|
|
|
xpt_print(periph->path,
|
|
|
|
"chgetparams: error getting element "
|
|
|
|
"address page\n");
|
1998-10-02 05:25:49 +00:00
|
|
|
xpt_release_ccb(ccb);
|
2007-05-14 21:48:53 +00:00
|
|
|
free(mode_buffer, M_SCSICH);
|
1998-10-02 05:25:49 +00:00
|
|
|
return(error);
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
ea = (struct page_element_address_assignment *)
|
|
|
|
find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
|
|
|
|
|
|
|
|
softc->sc_firsts[CHET_MT] = scsi_2btoul(ea->mtea);
|
|
|
|
softc->sc_counts[CHET_MT] = scsi_2btoul(ea->nmte);
|
|
|
|
softc->sc_firsts[CHET_ST] = scsi_2btoul(ea->fsea);
|
|
|
|
softc->sc_counts[CHET_ST] = scsi_2btoul(ea->nse);
|
|
|
|
softc->sc_firsts[CHET_IE] = scsi_2btoul(ea->fieea);
|
|
|
|
softc->sc_counts[CHET_IE] = scsi_2btoul(ea->niee);
|
|
|
|
softc->sc_firsts[CHET_DT] = scsi_2btoul(ea->fdtea);
|
|
|
|
softc->sc_counts[CHET_DT] = scsi_2btoul(ea->ndte);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
bzero(mode_buffer, mode_buffer_len);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now get the device capabilities page.
|
|
|
|
*/
|
|
|
|
scsi_mode_sense(&ccb->csio,
|
|
|
|
/* retries */ 1,
|
|
|
|
/* cbfcnp */ chdone,
|
|
|
|
/* tag_action */ MSG_SIMPLE_Q_TAG,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* dbd */ dbd,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* page_code */ SMS_PAGE_CTRL_CURRENT,
|
|
|
|
/* page */ CH_DEVICE_CAP_PAGE,
|
1998-10-02 05:25:49 +00:00
|
|
|
/* param_buf */ (u_int8_t *)mode_buffer,
|
|
|
|
/* param_len */ mode_buffer_len,
|
1998-09-15 06:36:34 +00:00
|
|
|
/* sense_len */ SSD_FULL_SIZE,
|
|
|
|
/* timeout */ CH_TIMEOUT_MODE_SENSE);
|
|
|
|
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror, /*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/* sense_flags */ SF_RETRY_UA | SF_NO_PRINT,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (error) {
|
1998-10-02 05:25:49 +00:00
|
|
|
if (dbd) {
|
|
|
|
struct scsi_mode_sense_6 *sms;
|
|
|
|
|
|
|
|
sms = (struct scsi_mode_sense_6 *)
|
|
|
|
ccb->csio.cdb_io.cdb_bytes;
|
|
|
|
|
|
|
|
sms->byte2 &= ~SMS_DBD;
|
Rewrite of the CAM error recovery code.
Some of the major changes include:
- The SCSI error handling portion of cam_periph_error() has
been broken out into a number of subfunctions to better
modularize the code that handles the hierarchy of SCSI errors.
As a result, the code is now much easier to read.
- String handling and error printing has been significantly
revamped. We now use sbufs to do string formatting instead
of using printfs (for the kernel) and snprintf/strncat (for
userland) as before.
There is a new catchall error printing routine,
cam_error_print() and its string-based counterpart,
cam_error_string() that allow the kernel and userland
applications to pass in a CCB and have errors printed out
properly, whether or not they're SCSI errors. Among other
things, this helped eliminate a fair amount of duplicate code
in camcontrol.
We now print out more information than before, including
the CAM status and SCSI status and the error recovery action
taken to remedy the problem.
- sbufs are now available in userland, via libsbuf. This
change was necessary since most of the error printing code
is shared between libcam and the kernel.
- A new transfer settings interface is included in this checkin.
This code is #ifdef'ed out, and is primarily intended to aid
discussion with HBA driver authors on the final form the
interface should take. There is example code in the ahc(4)
driver that implements the HBA driver side of the new
interface. The new transfer settings code won't be enabled
until we're ready to switch all HBA drivers over to the new
interface.
src/Makefile.inc1,
lib/Makefile: Add libsbuf. It must be built before libcam,
since libcam uses sbuf routines.
libcam/Makefile: libcam now depends on libsbuf.
libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the
sbuf sources from sys/kern.
bsd.libnames.mk: Add LIBSBUF.
camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically
linked, we can't depend on the dynamic linker
to pull in libsbuf.
camcontrol.c: Use cam_error_print() instead of checking for
CAM_SCSI_STATUS_ERROR on every failed CCB.
sbuf.9: Change the prototypes for sbuf_cat() and
sbuf_cpy() so that the source string is now a
const char *. This is more in line wth the
standard system string functions, and helps
eliminate warnings when dealing with a const
source buffer.
Fix a typo.
cam.c: Add description strings for the various CAM
error status values, as well as routines to
look up those strings.
Add new cam_error_string() and
cam_error_print() routines for userland and
the kernel.
cam.h: Add a new CAM flag, CAM_RETRY_SELTO.
Add enumerated types for the various options
available with cam_error_print() and
cam_error_string().
cam_ccb.h: Add new transfer negotiation structures/types.
Change inq_len in the ccb_getdev structure to
be "reserved". This field has never been
filled in, and will be removed when we next
bump the CAM version.
cam_debug.h: Fix typo.
cam_periph.c: Modularize cam_periph_error(). The SCSI error
handling part of cam_periph_error() is now
in camperiphscsistatuserror() and
camperiphscsisenseerror().
In cam_periph_lock(), increase the reference
count on the periph while we wait for our lock
attempt to succeed so that the periph won't go
away while we're sleeping.
cam_xpt.c: Add new transfer negotiation code. (ifdefed
out)
Add a new function, xpt_path_string(). This
is a string/sbuf analog to xpt_print_path().
scsi_all.c: Revamp string handing and error printing code.
We now use sbufs for much of the string
formatting code. More of that code is shared
between userland the kernel.
scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly
useful in the first place.
Add a new error action, SS_REQSENSE. (Send a
request sense and then retry the command.)
This is useful when the controller hasn't
performed autosense for some reason.
Change the default actions around a bit.
scsi_cd.c,
scsi_da.c,
scsi_pt.c,
scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection
timeouts shouldn't be covered by a sense flag.
scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO.
Get rid of the last vestiges of a read/write
interface.
libkern/bsearch.c,
sys/libkern.h,
conf/files: Add bsearch.c, which is needed for some of the
new table lookup routines.
aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if
CAM_NEW_TRAN_CODE is defined.
sbuf.h,
subr_sbuf.c: Add the appropriate #ifdefs so sbufs can
compile and run in userland.
Change sbuf_printf() to use vsnprintf()
instead of kvprintf(), which is only available
in the kernel.
Change the source string for sbuf_cpy() and
sbuf_cat() to be a const char *.
Add __BEGIN_DECLS and __END_DECLS around
function prototypes since they're now exported
to userland.
kdump/mkioctls: Include stdio.h before cam.h since cam.h now
includes a function with a FILE * argument.
Submitted by: gibbs (mostly)
Reviewed by: jdp, marcel (libsbuf makefile changes)
Reviewed by: des (sbuf changes)
Reviewed by: ken
2001-03-27 05:45:52 +00:00
|
|
|
error = cam_periph_runccb(ccb, cherror,
|
|
|
|
/*cam_flags*/ CAM_RETRY_SELTO,
|
|
|
|
/*sense_flags*/ SF_RETRY_UA,
|
2003-03-08 21:44:46 +00:00
|
|
|
softc->device_stats);
|
1998-10-02 05:25:49 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Since we disabled sense printing above, print
|
|
|
|
* out the sense here since we got an error.
|
|
|
|
*/
|
|
|
|
scsi_sense_print(&ccb->csio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
2006-12-05 07:45:28 +00:00
|
|
|
xpt_print(periph->path,
|
|
|
|
"chgetparams: error getting device "
|
|
|
|
"capabilities page\n");
|
1998-10-02 05:25:49 +00:00
|
|
|
xpt_release_ccb(ccb);
|
2007-05-14 21:48:53 +00:00
|
|
|
free(mode_buffer, M_SCSICH);
|
1998-10-02 05:25:49 +00:00
|
|
|
return(error);
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
1998-10-02 05:25:49 +00:00
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
cap = (struct page_device_capabilities *)
|
|
|
|
find_mode_page_6((struct scsi_mode_header_6 *)mode_buffer);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
bzero(softc->sc_movemask, sizeof(softc->sc_movemask));
|
|
|
|
bzero(softc->sc_exchangemask, sizeof(softc->sc_exchangemask));
|
2003-05-31 16:54:37 +00:00
|
|
|
moves = cap->move_from;
|
|
|
|
exchanges = cap->exchange_with;
|
|
|
|
for (from = CHET_MT; from <= CHET_MAX; ++from) {
|
1998-09-15 06:36:34 +00:00
|
|
|
softc->sc_movemask[from] = moves[from];
|
|
|
|
softc->sc_exchangemask[from] = exchanges[from];
|
|
|
|
}
|
|
|
|
|
2007-05-14 21:48:53 +00:00
|
|
|
free(mode_buffer, M_SCSICH);
|
1998-10-02 05:25:49 +00:00
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2013-04-19 20:03:51 +00:00
|
|
|
static int
|
|
|
|
chscsiversion(struct cam_periph *periph)
|
|
|
|
{
|
|
|
|
struct scsi_inquiry_data *inq_data;
|
|
|
|
struct ccb_getdev *cgd;
|
|
|
|
int dev_scsi_version;
|
|
|
|
struct cam_sim *sim;
|
|
|
|
|
|
|
|
sim = xpt_path_sim(periph->path);
|
|
|
|
mtx_assert(sim->mtx, MA_OWNED);
|
|
|
|
if ((cgd = (struct ccb_getdev *)xpt_alloc_ccb_nowait()) == NULL)
|
|
|
|
return (-1);
|
|
|
|
/*
|
|
|
|
* Get the device information.
|
|
|
|
*/
|
|
|
|
xpt_setup_ccb(&cgd->ccb_h,
|
|
|
|
periph->path,
|
|
|
|
CAM_PRIORITY_NORMAL);
|
|
|
|
cgd->ccb_h.func_code = XPT_GDEV_TYPE;
|
|
|
|
xpt_action((union ccb *)cgd);
|
|
|
|
|
|
|
|
if (cgd->ccb_h.status != CAM_REQ_CMP) {
|
|
|
|
xpt_free_ccb((union ccb *)cgd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inq_data = &cgd->inq_data;
|
|
|
|
dev_scsi_version = inq_data->version;
|
|
|
|
xpt_free_ccb((union ccb *)cgd);
|
|
|
|
|
|
|
|
return dev_scsi_version;
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
void
|
|
|
|
scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action, u_int32_t tea, u_int32_t src,
|
|
|
|
u_int32_t dst, int invert, u_int8_t sense_len,
|
|
|
|
u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_move_medium *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_move_medium *)&csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = MOVE_MEDIUM;
|
|
|
|
|
|
|
|
scsi_ulto2b(tea, scsi_cmd->tea);
|
|
|
|
scsi_ulto2b(src, scsi_cmd->src);
|
|
|
|
scsi_ulto2b(dst, scsi_cmd->dst);
|
|
|
|
|
|
|
|
if (invert)
|
|
|
|
scsi_cmd->invert |= MOVE_MEDIUM_INVERT;
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_NONE,
|
|
|
|
tag_action,
|
|
|
|
/*data_ptr*/ NULL,
|
|
|
|
/*dxfer_len*/ 0,
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action, u_int32_t tea, u_int32_t src,
|
|
|
|
u_int32_t dst1, u_int32_t dst2, int invert1,
|
|
|
|
int invert2, u_int8_t sense_len, u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_exchange_medium *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_exchange_medium *)&csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = EXCHANGE_MEDIUM;
|
|
|
|
|
|
|
|
scsi_ulto2b(tea, scsi_cmd->tea);
|
|
|
|
scsi_ulto2b(src, scsi_cmd->src);
|
|
|
|
scsi_ulto2b(dst1, scsi_cmd->fdst);
|
|
|
|
scsi_ulto2b(dst2, scsi_cmd->sdst);
|
|
|
|
|
|
|
|
if (invert1)
|
|
|
|
scsi_cmd->invert |= EXCHANGE_MEDIUM_INV1;
|
|
|
|
|
|
|
|
if (invert2)
|
|
|
|
scsi_cmd->invert |= EXCHANGE_MEDIUM_INV2;
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_NONE,
|
|
|
|
tag_action,
|
|
|
|
/*data_ptr*/ NULL,
|
|
|
|
/*dxfer_len*/ 0,
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action, u_int32_t tea, u_int32_t dst,
|
|
|
|
int invert, u_int8_t sense_len, u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_position_to_element *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_position_to_element *)&csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = POSITION_TO_ELEMENT;
|
|
|
|
|
|
|
|
scsi_ulto2b(tea, scsi_cmd->tea);
|
|
|
|
scsi_ulto2b(dst, scsi_cmd->dst);
|
|
|
|
|
|
|
|
if (invert)
|
|
|
|
scsi_cmd->invert |= POSITION_TO_ELEMENT_INVERT;
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_NONE,
|
|
|
|
tag_action,
|
|
|
|
/*data_ptr*/ NULL,
|
|
|
|
/*dxfer_len*/ 0,
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action, int voltag, u_int32_t sea,
|
2013-04-19 20:03:51 +00:00
|
|
|
int curdata, int dvcid,
|
1998-09-15 06:36:34 +00:00
|
|
|
u_int32_t count, u_int8_t *data_ptr,
|
|
|
|
u_int32_t dxfer_len, u_int8_t sense_len,
|
|
|
|
u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_read_element_status *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_read_element_status *)&csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = READ_ELEMENT_STATUS;
|
|
|
|
|
|
|
|
scsi_ulto2b(sea, scsi_cmd->sea);
|
|
|
|
scsi_ulto2b(count, scsi_cmd->count);
|
|
|
|
scsi_ulto3b(dxfer_len, scsi_cmd->len);
|
2013-04-19 20:03:51 +00:00
|
|
|
if (dvcid)
|
|
|
|
scsi_cmd->flags |= READ_ELEMENT_STATUS_DVCID;
|
|
|
|
if (curdata)
|
|
|
|
scsi_cmd->flags |= READ_ELEMENT_STATUS_CURDATA;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (voltag)
|
|
|
|
scsi_cmd->byte2 |= READ_ELEMENT_STATUS_VOLTAG;
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_IN,
|
|
|
|
tag_action,
|
|
|
|
data_ptr,
|
|
|
|
dxfer_len,
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action, u_int8_t sense_len,
|
|
|
|
u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_initialize_element_status *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_initialize_element_status *)
|
|
|
|
&csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = INITIALIZE_ELEMENT_STATUS;
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_NONE,
|
|
|
|
tag_action,
|
|
|
|
/* data_ptr */ NULL,
|
|
|
|
/* dxfer_len */ 0,
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries,
|
|
|
|
void (*cbfcnp)(struct cam_periph *, union ccb *),
|
|
|
|
u_int8_t tag_action,
|
|
|
|
u_int16_t element_address,
|
|
|
|
u_int8_t send_action_code,
|
|
|
|
struct scsi_send_volume_tag_parameters *parameters,
|
|
|
|
u_int8_t sense_len, u_int32_t timeout)
|
|
|
|
{
|
|
|
|
struct scsi_send_volume_tag *scsi_cmd;
|
|
|
|
|
|
|
|
scsi_cmd = (struct scsi_send_volume_tag *) &csio->cdb_io.cdb_bytes;
|
|
|
|
bzero(scsi_cmd, sizeof(*scsi_cmd));
|
|
|
|
|
|
|
|
scsi_cmd->opcode = SEND_VOLUME_TAG;
|
|
|
|
scsi_ulto2b(element_address, scsi_cmd->ea);
|
|
|
|
scsi_cmd->sac = send_action_code;
|
|
|
|
scsi_ulto2b(sizeof(*parameters), scsi_cmd->pll);
|
|
|
|
|
|
|
|
cam_fill_csio(csio,
|
|
|
|
retries,
|
|
|
|
cbfcnp,
|
|
|
|
/*flags*/ CAM_DIR_OUT,
|
|
|
|
tag_action,
|
|
|
|
/* data_ptr */ (u_int8_t *) parameters,
|
|
|
|
sizeof(*parameters),
|
|
|
|
sense_len,
|
|
|
|
sizeof(*scsi_cmd),
|
|
|
|
timeout);
|
|
|
|
}
|