2000-08-30 07:52:50 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* 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
|
2007-12-02 18:48:17 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2000-08-30 07:52:50 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2007-12-02 18:48:17 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-08-30 07:52:50 +00:00
|
|
|
*
|
|
|
|
* 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-08-24 17:55:58 +00:00
|
|
|
*/
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2002-10-30 22:00:11 +00:00
|
|
|
* Copyright (c) 2002 Eric Moore
|
|
|
|
* Copyright (c) 2002 LSI Logic Corporation
|
|
|
|
* 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
|
2007-12-02 18:48:17 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2002-10-30 22:00:11 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2007-12-02 18:48:17 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-10-18 21:29:14 +00:00
|
|
|
* 3. The party using or redistributing the source code and binary forms
|
2007-12-02 18:48:17 +00:00
|
|
|
* agrees to the disclaimer below and the terms and conditions set forth
|
|
|
|
* herein.
|
2002-10-18 21:29:14 +00:00
|
|
|
*
|
2002-10-30 22:00:11 +00:00
|
|
|
* 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.
|
2000-08-30 07:52:50 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2008-11-03 00:53:54 +00:00
|
|
|
#include <sys/module.h>
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2005-08-08 12:16:21 +00:00
|
|
|
#include <sys/bio.h>
|
2000-08-30 07:52:50 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/cam_sim.h>
|
|
|
|
#include <cam/cam_xpt.h>
|
|
|
|
#include <cam/cam_xpt_sim.h>
|
|
|
|
#include <cam/cam_debug.h>
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
#include <cam/scsi/scsi_message.h>
|
|
|
|
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/amr/amrreg.h>
|
|
|
|
#include <dev/amr/amrvar.h>
|
|
|
|
|
2008-11-03 00:53:54 +00:00
|
|
|
static int amr_cam_probe(device_t dev);
|
|
|
|
static int amr_cam_attach(device_t dev);
|
|
|
|
static int amr_cam_detach(device_t dev);
|
2007-12-02 18:48:17 +00:00
|
|
|
static void amr_cam_action(struct cam_sim *sim, union ccb *ccb);
|
|
|
|
static void amr_cam_poll(struct cam_sim *sim);
|
|
|
|
static void amr_cam_complete(struct amr_command *ac);
|
2008-11-03 00:53:54 +00:00
|
|
|
static int amr_cam_command(struct amr_softc *sc, struct amr_command **acp);
|
|
|
|
|
|
|
|
static devclass_t amr_pass_devclass;
|
|
|
|
|
|
|
|
static device_method_t amr_pass_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, amr_cam_probe),
|
|
|
|
DEVMETHOD(device_attach, amr_cam_attach),
|
|
|
|
DEVMETHOD(device_detach, amr_cam_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t amr_pass_driver = {
|
|
|
|
"amrp",
|
|
|
|
amr_pass_methods,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(amrp, amr, amr_pass_driver, amr_pass_devclass, 0, 0);
|
|
|
|
MODULE_DEPEND(amrp, cam, 1, 1, 1);
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_AMRCAM, "amrcam", "AMR CAM memory");
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/***********************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Enqueue/dequeue functions
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
amr_enqueue_ccb(struct amr_softc *sc, union ccb *ccb)
|
|
|
|
{
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
TAILQ_INSERT_TAIL(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
amr_requeue_ccb(struct amr_softc *sc, union ccb *ccb)
|
|
|
|
{
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
TAILQ_INSERT_HEAD(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline union ccb *
|
|
|
|
amr_dequeue_ccb(struct amr_softc *sc)
|
|
|
|
{
|
2007-12-02 18:48:17 +00:00
|
|
|
union ccb *ccb;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
if ((ccb = (union ccb *)TAILQ_FIRST(&sc->amr_cam_ccbq)) != NULL)
|
|
|
|
TAILQ_REMOVE(&sc->amr_cam_ccbq, &ccb->ccb_h, sim_links.tqe);
|
|
|
|
return(ccb);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 00:53:54 +00:00
|
|
|
static int
|
|
|
|
amr_cam_probe(device_t dev)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-08-30 07:52:50 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Attach our 'real' SCSI channels to CAM
|
|
|
|
*/
|
2008-11-03 00:53:54 +00:00
|
|
|
static int
|
|
|
|
amr_cam_attach(device_t dev)
|
2000-08-30 07:52:50 +00:00
|
|
|
{
|
2008-11-03 00:53:54 +00:00
|
|
|
struct amr_softc *sc;
|
2007-12-02 18:48:17 +00:00
|
|
|
struct cam_devq *devq;
|
2008-11-03 00:53:54 +00:00
|
|
|
int chn, error;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
/* initialise the ccb queue */
|
|
|
|
TAILQ_INIT(&sc->amr_cam_ccbq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a devq for all our channels combined. This should
|
|
|
|
* allow for the maximum number of SCSI commands we will accept
|
|
|
|
* at one time. Save the pointer in the softc so we can find it later
|
|
|
|
* during detach.
|
|
|
|
*/
|
|
|
|
if ((devq = cam_simq_alloc(AMR_MAX_SCSI_CMDS)) == NULL)
|
2008-11-03 00:53:54 +00:00
|
|
|
return(ENOMEM);
|
2007-12-02 18:48:17 +00:00
|
|
|
sc->amr_cam_devq = devq;
|
2002-10-18 21:29:14 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/*
|
|
|
|
* Iterate over our channels, registering them with CAM
|
|
|
|
*/
|
|
|
|
for (chn = 0; chn < sc->amr_maxchan; chn++) {
|
|
|
|
|
|
|
|
/* allocate a sim */
|
|
|
|
if ((sc->amr_cam_sim[chn] = cam_sim_alloc(amr_cam_action,
|
|
|
|
amr_cam_poll, "amr", sc, device_get_unit(sc->amr_dev),
|
|
|
|
&sc->amr_list_lock, 1, AMR_MAX_SCSI_CMDS, devq)) == NULL) {
|
|
|
|
cam_simq_free(devq);
|
|
|
|
device_printf(sc->amr_dev, "CAM SIM attach failed\n");
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register the bus ID so we can get it later */
|
|
|
|
mtx_lock(&sc->amr_list_lock);
|
|
|
|
error = xpt_bus_register(sc->amr_cam_sim[chn], sc->amr_dev,chn);
|
|
|
|
mtx_unlock(&sc->amr_list_lock);
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->amr_dev,
|
|
|
|
"CAM XPT bus registration failed\n");
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
2007-12-02 18:48:17 +00:00
|
|
|
/*
|
|
|
|
* XXX we should scan the config and work out which devices are
|
|
|
|
* actually protected.
|
|
|
|
*/
|
2008-11-03 00:53:54 +00:00
|
|
|
sc->amr_cam_command = amr_cam_command;
|
2007-12-02 18:48:17 +00:00
|
|
|
return(0);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Disconnect ourselves from CAM
|
|
|
|
*/
|
2008-11-03 00:53:54 +00:00
|
|
|
static int
|
|
|
|
amr_cam_detach(device_t dev)
|
2000-08-30 07:52:50 +00:00
|
|
|
{
|
2008-11-03 00:53:54 +00:00
|
|
|
struct amr_softc *sc;
|
2007-12-02 18:48:17 +00:00
|
|
|
int chn;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2008-11-03 00:53:54 +00:00
|
|
|
sc = device_get_softc(dev);
|
2007-12-02 18:48:17 +00:00
|
|
|
mtx_lock(&sc->amr_list_lock);
|
|
|
|
for (chn = 0; chn < sc->amr_maxchan; chn++) {
|
|
|
|
/*
|
|
|
|
* If a sim was allocated for this channel, free it
|
|
|
|
*/
|
|
|
|
if (sc->amr_cam_sim[chn] != NULL) {
|
|
|
|
xpt_bus_deregister(cam_sim_path(sc->amr_cam_sim[chn]));
|
|
|
|
cam_sim_free(sc->amr_cam_sim[chn], FALSE);
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
2007-12-02 18:48:17 +00:00
|
|
|
mtx_unlock(&sc->amr_list_lock);
|
2005-01-10 02:34:26 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/* Now free the devq */
|
|
|
|
if (sc->amr_cam_devq != NULL)
|
|
|
|
cam_simq_free(sc->amr_cam_devq);
|
2008-11-03 00:53:54 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/***********************************************************************
|
|
|
|
***********************************************************************
|
|
|
|
CAM passthrough interface
|
|
|
|
***********************************************************************
|
|
|
|
***********************************************************************/
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/***********************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Handle a request for action from CAM
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_cam_action(struct cam_sim *sim, union ccb *ccb)
|
|
|
|
{
|
2007-12-02 18:48:17 +00:00
|
|
|
struct amr_softc *sc = cam_sim_softc(sim);
|
|
|
|
|
|
|
|
switch(ccb->ccb_h.func_code) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform SCSI I/O to a physical device.
|
|
|
|
*/
|
|
|
|
case XPT_SCSI_IO:
|
|
|
|
{
|
|
|
|
struct ccb_hdr *ccbh = &ccb->ccb_h;
|
|
|
|
struct ccb_scsiio *csio = &ccb->csio;
|
|
|
|
|
|
|
|
/* Validate the CCB */
|
|
|
|
ccbh->status = CAM_REQ_INPROG;
|
|
|
|
|
|
|
|
/* check the CDB length */
|
|
|
|
if (csio->cdb_len > AMR_MAX_EXTCDB_LEN)
|
2007-12-12 05:55:03 +00:00
|
|
|
ccbh->status = CAM_REQ_INVALID;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
if ((csio->cdb_len > AMR_MAX_CDB_LEN) &&
|
|
|
|
(sc->support_ext_cdb == 0))
|
2007-12-12 05:55:03 +00:00
|
|
|
ccbh->status = CAM_REQ_INVALID;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
/* check that the CDB pointer is not to a physical address */
|
|
|
|
if ((ccbh->flags & CAM_CDB_POINTER) &&
|
|
|
|
(ccbh->flags & CAM_CDB_PHYS))
|
2007-12-12 05:55:03 +00:00
|
|
|
ccbh->status = CAM_REQ_INVALID;
|
2007-12-02 18:48:17 +00:00
|
|
|
/*
|
|
|
|
* if there is data transfer, it must be to/from a virtual
|
|
|
|
* address
|
|
|
|
*/
|
|
|
|
if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
|
2013-02-12 16:57:20 +00:00
|
|
|
if ((ccbh->flags & CAM_DATA_MASK) != CAM_DATA_VADDR)
|
2007-12-02 18:48:17 +00:00
|
|
|
/* we can't map it */
|
2007-12-12 05:55:03 +00:00
|
|
|
ccbh->status = CAM_REQ_INVALID;
|
2007-12-02 18:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the command is to a LUN other than 0, fail it.
|
|
|
|
* This is probably incorrect, but during testing the
|
|
|
|
* firmware did not seem to respect the LUN field, and thus
|
|
|
|
* devices appear echoed.
|
|
|
|
*/
|
|
|
|
if (csio->ccb_h.target_lun != 0)
|
2007-12-12 05:55:03 +00:00
|
|
|
ccbh->status = CAM_DEV_NOT_THERE;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
/* if we're happy with the request, queue it for attention */
|
|
|
|
if (ccbh->status == CAM_REQ_INPROG) {
|
|
|
|
|
|
|
|
/* save the channel number in the ccb */
|
|
|
|
csio->ccb_h.sim_priv.entries[0].field= cam_sim_bus(sim);
|
|
|
|
|
|
|
|
amr_enqueue_ccb(sc, ccb);
|
|
|
|
amr_startio(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XPT_CALC_GEOMETRY:
|
|
|
|
{
|
|
|
|
cam_calc_geometry(&ccb->ccg, /*extended*/1);
|
|
|
|
break;
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-12-02 18:48:17 +00:00
|
|
|
* Return path stats. Some of these should probably be amended.
|
2000-08-30 07:52:50 +00:00
|
|
|
*/
|
2007-12-02 18:48:17 +00:00
|
|
|
case XPT_PATH_INQ:
|
|
|
|
{
|
|
|
|
struct ccb_pathinq *cpi = & ccb->cpi;
|
|
|
|
|
|
|
|
debug(3, "XPT_PATH_INQ");
|
|
|
|
cpi->version_num = 1; /* XXX??? */
|
|
|
|
cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
|
|
|
|
cpi->target_sprt = 0;
|
|
|
|
cpi->hba_misc = PIM_NOBUSRESET|PIM_SEQSCAN;
|
|
|
|
cpi->hba_eng_cnt = 0;
|
|
|
|
cpi->max_target = AMR_MAX_TARGETS;
|
|
|
|
cpi->max_lun = 0 /* AMR_MAX_LUNS*/;
|
|
|
|
cpi->initiator_id = 7; /* XXX variable? */
|
Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)
The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".
This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.
PR: 215474
Reported by: Coverity
CID: 1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID: 1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID: 1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID: 1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID: 1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID: 1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID: 1010035 1010036 1010042 1010041 1010040 1010039
Reviewed by: imp, sephe, slm
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D9037
Differential Revision: https://reviews.freebsd.org/D9038
2017-01-04 20:26:42 +00:00
|
|
|
strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
|
|
|
|
strlcpy(cpi->hba_vid, "LSI", HBA_IDLEN);
|
|
|
|
strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
|
2007-12-02 18:48:17 +00:00
|
|
|
cpi->unit_number = cam_sim_unit(sim);
|
|
|
|
cpi->bus_id = cam_sim_bus(sim);
|
|
|
|
cpi->base_transfer_speed = 132 * 1024; /* XXX */
|
|
|
|
cpi->transport = XPORT_SPI;
|
|
|
|
cpi->transport_version = 2;
|
|
|
|
cpi->protocol = PROTO_SCSI;
|
|
|
|
cpi->protocol_version = SCSI_REV_2;
|
|
|
|
cpi->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
case XPT_RESET_BUS:
|
|
|
|
{
|
|
|
|
struct ccb_pathinq *cpi = & ccb->cpi;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
debug(1, "XPT_RESET_BUS");
|
|
|
|
cpi->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
case XPT_RESET_DEV:
|
|
|
|
{
|
|
|
|
debug(1, "XPT_RESET_DEV");
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
case XPT_GET_TRAN_SETTINGS:
|
|
|
|
{
|
|
|
|
struct ccb_trans_settings *cts = &(ccb->cts);
|
|
|
|
|
|
|
|
debug(3, "XPT_GET_TRAN_SETTINGS");
|
|
|
|
|
|
|
|
struct ccb_trans_settings_scsi *scsi;
|
|
|
|
struct ccb_trans_settings_spi *spi;
|
|
|
|
|
|
|
|
scsi = &cts->proto_specific.scsi;
|
|
|
|
spi = &cts->xport_specific.spi;
|
|
|
|
|
|
|
|
cts->protocol = PROTO_SCSI;
|
|
|
|
cts->protocol_version = SCSI_REV_2;
|
|
|
|
cts->transport = XPORT_SPI;
|
|
|
|
cts->transport_version = 2;
|
|
|
|
|
|
|
|
if (cts->type == CTS_TYPE_USER_SETTINGS) {
|
|
|
|
ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi->flags = CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
spi->bus_width = MSG_EXT_WDTR_BUS_32_BIT;
|
|
|
|
spi->sync_period = 6; /* 40MHz how wide is this bus? */
|
|
|
|
spi->sync_offset = 31; /* How to extract this from board? */
|
|
|
|
|
|
|
|
spi->valid = CTS_SPI_VALID_SYNC_RATE
|
|
|
|
| CTS_SPI_VALID_SYNC_OFFSET
|
|
|
|
| CTS_SPI_VALID_BUS_WIDTH
|
|
|
|
| CTS_SPI_VALID_DISC;
|
|
|
|
scsi->valid = CTS_SCSI_VALID_TQ;
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XPT_SET_TRAN_SETTINGS:
|
|
|
|
debug(3, "XPT_SET_TRAN_SETTINGS");
|
2006-10-31 05:53:29 +00:00
|
|
|
ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
|
|
|
|
break;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reject anything else as unsupported.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
/* we can't do this */
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
break;
|
2006-10-31 05:53:29 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
mtx_assert(&sc->amr_list_lock, MA_OWNED);
|
|
|
|
xpt_done(ccb);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Convert a CAM CCB off the top of the CCB queue to a passthrough SCSI
|
|
|
|
* command.
|
2000-08-30 07:52:50 +00:00
|
|
|
*/
|
2008-11-03 00:53:54 +00:00
|
|
|
static int
|
2000-08-30 07:52:50 +00:00
|
|
|
amr_cam_command(struct amr_softc *sc, struct amr_command **acp)
|
|
|
|
{
|
2007-12-02 18:48:17 +00:00
|
|
|
struct amr_command *ac;
|
|
|
|
struct amr_passthrough *ap;
|
|
|
|
struct amr_ext_passthrough *aep;
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
int bus, target, error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
ac = NULL;
|
|
|
|
ap = NULL;
|
|
|
|
aep = NULL;
|
|
|
|
|
|
|
|
/* check to see if there is a ccb for us to work with */
|
|
|
|
if ((csio = (struct ccb_scsiio *)amr_dequeue_ccb(sc)) == NULL)
|
2000-08-30 07:52:50 +00:00
|
|
|
goto out;
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/* get bus/target, XXX validate against protected devices? */
|
|
|
|
bus = csio->ccb_h.sim_priv.entries[0].field;
|
|
|
|
target = csio->ccb_h.target_id;
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/*
|
|
|
|
* Build a passthrough command.
|
|
|
|
*/
|
2000-08-30 07:52:50 +00:00
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
/* construct command */
|
|
|
|
if ((ac = amr_alloccmd(sc)) == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/* construct passthrough */
|
|
|
|
if (sc->support_ext_cdb ) {
|
2007-12-12 05:55:03 +00:00
|
|
|
aep = &ac->ac_ccb->ccb_epthru;
|
2007-12-02 18:48:17 +00:00
|
|
|
aep->ap_timeout = 2;
|
|
|
|
aep->ap_ars = 1;
|
|
|
|
aep->ap_request_sense_length = 14;
|
|
|
|
aep->ap_islogical = 0;
|
|
|
|
aep->ap_channel = bus;
|
|
|
|
aep->ap_scsi_id = target;
|
|
|
|
aep->ap_logical_drive_no = csio->ccb_h.target_lun;
|
|
|
|
aep->ap_cdb_length = csio->cdb_len;
|
|
|
|
aep->ap_data_transfer_length = csio->dxfer_len;
|
|
|
|
if (csio->ccb_h.flags & CAM_CDB_POINTER) {
|
|
|
|
bcopy(csio->cdb_io.cdb_ptr, aep->ap_cdb, csio->cdb_len);
|
|
|
|
} else {
|
|
|
|
bcopy(csio->cdb_io.cdb_bytes, aep->ap_cdb,
|
|
|
|
csio->cdb_len);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* we leave the data s/g list and s/g count to the map routine
|
|
|
|
* later
|
|
|
|
*/
|
|
|
|
|
|
|
|
debug(2, " COMMAND %x/%d+%d to %d:%d:%d", aep->ap_cdb[0],
|
|
|
|
aep->ap_cdb_length, csio->dxfer_len, aep->ap_channel,
|
|
|
|
aep->ap_scsi_id, aep->ap_logical_drive_no);
|
|
|
|
|
|
|
|
} else {
|
2007-12-12 05:55:03 +00:00
|
|
|
ap = &ac->ac_ccb->ccb_pthru;
|
2007-12-02 18:48:17 +00:00
|
|
|
ap->ap_timeout = 0;
|
|
|
|
ap->ap_ars = 1;
|
|
|
|
ap->ap_request_sense_length = 14;
|
|
|
|
ap->ap_islogical = 0;
|
|
|
|
ap->ap_channel = bus;
|
|
|
|
ap->ap_scsi_id = target;
|
|
|
|
ap->ap_logical_drive_no = csio->ccb_h.target_lun;
|
|
|
|
ap->ap_cdb_length = csio->cdb_len;
|
|
|
|
ap->ap_data_transfer_length = csio->dxfer_len;
|
|
|
|
if (csio->ccb_h.flags & CAM_CDB_POINTER) {
|
|
|
|
bcopy(csio->cdb_io.cdb_ptr, ap->ap_cdb, csio->cdb_len);
|
|
|
|
} else {
|
|
|
|
bcopy(csio->cdb_io.cdb_bytes, ap->ap_cdb,
|
|
|
|
csio->cdb_len);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* we leave the data s/g list and s/g count to the map routine
|
|
|
|
* later
|
|
|
|
*/
|
|
|
|
|
|
|
|
debug(2, " COMMAND %x/%d+%d to %d:%d:%d", ap->ap_cdb[0],
|
|
|
|
ap->ap_cdb_length, csio->dxfer_len, ap->ap_channel,
|
|
|
|
ap->ap_scsi_id, ap->ap_logical_drive_no);
|
|
|
|
}
|
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_CCB;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
ac->ac_data = csio->data_ptr;
|
|
|
|
ac->ac_length = csio->dxfer_len;
|
2007-12-02 18:48:17 +00:00
|
|
|
if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
|
2007-12-12 05:55:03 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_DATAIN;
|
2007-12-02 18:48:17 +00:00
|
|
|
if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
|
2007-12-12 05:55:03 +00:00
|
|
|
ac->ac_flags |= AMR_CMD_DATAOUT;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
|
|
|
ac->ac_private = csio;
|
2007-12-02 19:50:01 +00:00
|
|
|
ac->ac_complete = amr_cam_complete;
|
2007-12-02 18:48:17 +00:00
|
|
|
if ( sc->support_ext_cdb ) {
|
|
|
|
ac->ac_mailbox.mb_command = AMR_CMD_EXTPASS;
|
|
|
|
} else {
|
|
|
|
ac->ac_mailbox.mb_command = AMR_CMD_PASS;
|
|
|
|
}
|
2000-08-30 07:52:50 +00:00
|
|
|
|
|
|
|
out:
|
2007-12-02 18:48:17 +00:00
|
|
|
if (error != 0) {
|
|
|
|
if (ac != NULL)
|
|
|
|
amr_releasecmd(ac);
|
|
|
|
if (csio != NULL)
|
|
|
|
/* put it back and try again later */
|
|
|
|
amr_requeue_ccb(sc, (union ccb *)csio);
|
|
|
|
}
|
|
|
|
*acp = ac;
|
|
|
|
return(error);
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/***********************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Check for interrupt status
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_cam_poll(struct cam_sim *sim)
|
|
|
|
{
|
2005-01-16 07:34:26 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
amr_done(cam_sim_softc(sim));
|
2000-08-30 07:52:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/**********************************************************************
|
2000-08-30 07:52:50 +00:00
|
|
|
* Handle completion of a command submitted via CAM.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
amr_cam_complete(struct amr_command *ac)
|
|
|
|
{
|
2007-12-02 18:48:17 +00:00
|
|
|
struct amr_passthrough *ap;
|
2007-12-02 19:50:01 +00:00
|
|
|
struct amr_ext_passthrough *aep;
|
2007-12-02 18:48:17 +00:00
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
struct scsi_inquiry_data *inq;
|
2007-12-02 19:50:01 +00:00
|
|
|
int scsi_status, cdb0;
|
2007-12-02 18:48:17 +00:00
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
ap = &ac->ac_ccb->ccb_pthru;
|
|
|
|
aep = &ac->ac_ccb->ccb_epthru;
|
2007-12-02 18:48:17 +00:00
|
|
|
csio = (struct ccb_scsiio *)ac->ac_private;
|
|
|
|
inq = (struct scsi_inquiry_data *)csio->data_ptr;
|
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
|
2007-12-02 19:50:01 +00:00
|
|
|
scsi_status = aep->ap_scsi_status;
|
2007-12-12 05:55:03 +00:00
|
|
|
else
|
|
|
|
scsi_status = ap->ap_scsi_status;
|
2007-12-02 18:48:17 +00:00
|
|
|
debug(1, "status 0x%x AP scsi_status 0x%x", ac->ac_status,
|
2007-12-02 19:50:01 +00:00
|
|
|
scsi_status);
|
2007-12-02 18:48:17 +00:00
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
/* Make sure the status is sane */
|
|
|
|
if ((ac->ac_status != AMR_STATUS_SUCCESS) && (scsi_status == 0)) {
|
2007-12-02 18:48:17 +00:00
|
|
|
csio->ccb_h.status = CAM_REQ_CMP_ERR;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-10-30 22:00:11 +00:00
|
|
|
|
2007-12-02 18:48:17 +00:00
|
|
|
/*
|
|
|
|
* Hide disks from CAM so that they're not picked up and treated as
|
|
|
|
* 'normal' disks.
|
|
|
|
*
|
|
|
|
* If the configuration provides a mechanism to mark a disk a "not
|
|
|
|
* managed", we could add handling for that to allow disks to be
|
|
|
|
* selectively visible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* handle passthrough SCSI status */
|
2007-12-02 19:50:01 +00:00
|
|
|
switch(scsi_status) {
|
2007-12-02 18:48:17 +00:00
|
|
|
case 0: /* completed OK */
|
2007-12-12 05:55:03 +00:00
|
|
|
if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
|
2007-12-02 19:50:01 +00:00
|
|
|
cdb0 = aep->ap_cdb[0];
|
2007-12-12 05:55:03 +00:00
|
|
|
else
|
|
|
|
cdb0 = ap->ap_cdb[0];
|
2007-12-02 19:50:01 +00:00
|
|
|
if ((cdb0 == INQUIRY) && (SID_TYPE(inq) == T_DIRECT))
|
2007-12-02 18:48:17 +00:00
|
|
|
inq->device = (inq->device & 0xe0) | T_NODEVICE;
|
|
|
|
csio->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
|
|
|
csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
|
|
|
|
csio->scsi_status = SCSI_STATUS_CHECK_COND;
|
2007-12-12 05:55:03 +00:00
|
|
|
if (ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS)
|
|
|
|
bcopy(aep->ap_request_sense_area, &csio->sense_data,
|
2007-12-02 19:50:01 +00:00
|
|
|
AMR_MAX_REQ_SENSE_LEN);
|
|
|
|
else
|
2007-12-12 05:55:03 +00:00
|
|
|
bcopy(ap->ap_request_sense_area, &csio->sense_data,
|
2007-12-02 19:50:01 +00:00
|
|
|
AMR_MAX_REQ_SENSE_LEN);
|
2007-12-02 18:48:17 +00:00
|
|
|
csio->sense_len = AMR_MAX_REQ_SENSE_LEN;
|
|
|
|
csio->ccb_h.status |= CAM_AUTOSNS_VALID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x08:
|
|
|
|
csio->ccb_h.status = CAM_SCSI_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xf0:
|
|
|
|
case 0xf4:
|
2007-12-02 19:50:01 +00:00
|
|
|
default:
|
2007-12-12 05:55:03 +00:00
|
|
|
/*
|
|
|
|
* Non-zero LUNs are already filtered, so there's no need
|
|
|
|
* to return CAM_DEV_NOT_THERE.
|
|
|
|
*/
|
|
|
|
csio->ccb_h.status = CAM_SEL_TIMEOUT;
|
2007-12-02 18:48:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-28 19:40:17 +00:00
|
|
|
|
|
|
|
out:
|
2007-12-02 18:48:17 +00:00
|
|
|
if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE)
|
|
|
|
debug(2, "%*D\n", imin(csio->dxfer_len, 16), csio->data_ptr,
|
|
|
|
" ");
|
2007-12-02 19:50:01 +00:00
|
|
|
|
2007-12-12 05:55:03 +00:00
|
|
|
mtx_lock(&ac->ac_sc->amr_list_lock);
|
2007-12-02 18:48:17 +00:00
|
|
|
xpt_done((union ccb *)csio);
|
|
|
|
amr_releasecmd(ac);
|
2007-12-02 19:50:01 +00:00
|
|
|
mtx_unlock(&ac->ac_sc->amr_list_lock);
|
2002-10-30 22:00:11 +00:00
|
|
|
}
|