2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-18 14:26:50 +00:00
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
2003-10-18 05:41:31 +00:00
|
|
|
* Copyright (C) 2003
|
|
|
|
* Hidetoshi Shimokawa. All rights reserved.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2003-10-18 05:41:31 +00:00
|
|
|
* 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 acknowledgement:
|
|
|
|
*
|
|
|
|
* This product includes software developed by Hidetoshi Shimokawa.
|
|
|
|
*
|
|
|
|
* 4. Neither the name of the author nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2003-10-18 05:41:31 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
2014-09-27 16:50:21 +00:00
|
|
|
*
|
2003-10-18 05:41:31 +00:00
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/malloc.h>
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
#include <sys/endian.h>
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/firewirereg.h>
|
|
|
|
#include <dev/firewire/iec13213.h>
|
|
|
|
#include <dev/firewire/sbp.h>
|
|
|
|
#include <dev/firewire/fwmem.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/cam_sim.h>
|
|
|
|
#include <cam/cam_xpt_sim.h>
|
|
|
|
#include <cam/cam_debug.h>
|
|
|
|
#include <cam/cam_periph.h>
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
2012-01-25 23:33:50 +00:00
|
|
|
#include <cam/scsi/scsi_message.h>
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
#define SBP_TARG_RECV_LEN 8
|
|
|
|
#define MAX_INITIATORS 8
|
|
|
|
#define MAX_LUN 63
|
|
|
|
#define MAX_LOGINS 63
|
|
|
|
#define MAX_NODES 63
|
2003-10-18 05:41:31 +00:00
|
|
|
/*
|
|
|
|
* management/command block agent registers
|
|
|
|
*
|
|
|
|
* BASE 0xffff f001 0000 management port
|
2003-12-11 03:42:40 +00:00
|
|
|
* BASE 0xffff f001 0020 command port for login id 0
|
|
|
|
* BASE 0xffff f001 0040 command port for login id 1
|
2003-10-18 05:41:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define SBP_TARG_MGM 0x10000 /* offset from 0xffff f000 000 */
|
|
|
|
#define SBP_TARG_BIND_HI 0xffff
|
|
|
|
#define SBP_TARG_BIND_LO(l) (0xf0000000 + SBP_TARG_MGM + 0x20 * ((l) + 1))
|
|
|
|
#define SBP_TARG_BIND_START (((u_int64_t)SBP_TARG_BIND_HI << 32) | \
|
|
|
|
SBP_TARG_BIND_LO(-1))
|
|
|
|
#define SBP_TARG_BIND_END (((u_int64_t)SBP_TARG_BIND_HI << 32) | \
|
2003-12-11 03:42:40 +00:00
|
|
|
SBP_TARG_BIND_LO(MAX_LOGINS))
|
|
|
|
#define SBP_TARG_LOGIN_ID(lo) (((lo) - SBP_TARG_BIND_LO(0))/0x20)
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
#define FETCH_MGM 0
|
|
|
|
#define FETCH_CMD 1
|
|
|
|
#define FETCH_POINTER 2
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
#define F_LINK_ACTIVE (1 << 0)
|
|
|
|
#define F_ATIO_STARVED (1 << 1)
|
|
|
|
#define F_LOGIN (1 << 2)
|
|
|
|
#define F_HOLD (1 << 3)
|
|
|
|
#define F_FREEZED (1 << 4)
|
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_SBP_TARG, "sbp_targ", "SBP-II/FireWire target mode");
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
static int debug = 0;
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, sbp_targ_debug, CTLFLAG_RW, &debug, 0,
|
|
|
|
"SBP target mode debug flag");
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login {
|
|
|
|
struct sbp_targ_lstate *lstate;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct fw_device *fwdev;
|
|
|
|
struct sbp_login_res loginres;
|
2014-09-27 16:50:21 +00:00
|
|
|
uint16_t fifo_hi;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t last_hi;
|
2014-09-27 16:50:21 +00:00
|
|
|
uint32_t fifo_lo;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t last_lo;
|
2003-10-18 05:41:31 +00:00
|
|
|
STAILQ_HEAD(, orb_info) orbs;
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_ENTRY(sbp_targ_login) link;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t hold_sec;
|
|
|
|
uint16_t id;
|
2014-09-27 16:50:21 +00:00
|
|
|
uint8_t flags;
|
|
|
|
uint8_t spd;
|
2003-12-11 03:42:40 +00:00
|
|
|
struct callout hold_callout;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sbp_targ_lstate {
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t lun;
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct cam_path *path;
|
|
|
|
struct ccb_hdr_slist accept_tios;
|
|
|
|
struct ccb_hdr_slist immed_notifies;
|
|
|
|
struct crom_chunk model;
|
2014-09-27 16:50:21 +00:00
|
|
|
uint32_t flags;
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_HEAD(, sbp_targ_login) logins;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sbp_targ_softc {
|
|
|
|
struct firewire_dev_comm fd;
|
|
|
|
struct cam_sim *sim;
|
|
|
|
struct cam_path *path;
|
|
|
|
struct fw_bind fwb;
|
|
|
|
int ndevs;
|
|
|
|
int flags;
|
|
|
|
struct crom_chunk unit;
|
|
|
|
struct sbp_targ_lstate *lstate[MAX_LUN];
|
|
|
|
struct sbp_targ_lstate *black_hole;
|
|
|
|
struct sbp_targ_login *logins[MAX_LOGINS];
|
2007-06-06 14:31:36 +00:00
|
|
|
struct mtx mtx;
|
2003-10-18 05:41:31 +00:00
|
|
|
};
|
2007-06-06 14:31:36 +00:00
|
|
|
#define SBP_LOCK(sc) mtx_lock(&(sc)->mtx)
|
|
|
|
#define SBP_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
struct corb4 {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t n:1,
|
2003-10-18 05:41:31 +00:00
|
|
|
rq_fmt:2,
|
|
|
|
:1,
|
|
|
|
dir:1,
|
|
|
|
spd:3,
|
|
|
|
max_payload:4,
|
|
|
|
page_table_present:1,
|
|
|
|
page_size:3,
|
|
|
|
data_size:16;
|
|
|
|
#else
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t data_size:16,
|
2003-10-18 05:41:31 +00:00
|
|
|
page_size:3,
|
|
|
|
page_table_present:1,
|
|
|
|
max_payload:4,
|
|
|
|
spd:3,
|
|
|
|
dir:1,
|
|
|
|
:1,
|
|
|
|
rq_fmt:2,
|
|
|
|
n:1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct morb4 {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t n:1,
|
2003-10-18 05:41:31 +00:00
|
|
|
rq_fmt:2,
|
|
|
|
:9,
|
|
|
|
fun:4,
|
|
|
|
id:16;
|
|
|
|
#else
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t id:16,
|
2003-10-18 05:41:31 +00:00
|
|
|
fun:4,
|
|
|
|
:9,
|
|
|
|
rq_fmt:2,
|
|
|
|
n:1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Urestricted page table format
|
|
|
|
* states that the segment length
|
|
|
|
* and high base addr are in the first
|
|
|
|
* 32 bits and the base low is in
|
|
|
|
* the second
|
|
|
|
*/
|
|
|
|
struct unrestricted_page_table_fmt {
|
|
|
|
uint16_t segment_len;
|
|
|
|
uint16_t segment_base_high;
|
|
|
|
uint32_t segment_base_low;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
struct orb_info {
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct fw_device *fwdev;
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login;
|
2003-10-18 05:41:31 +00:00
|
|
|
union ccb *ccb;
|
|
|
|
struct ccb_accept_tio *atio;
|
2014-09-27 16:50:21 +00:00
|
|
|
uint8_t state;
|
2003-10-18 05:41:31 +00:00
|
|
|
#define ORBI_STATUS_NONE 0
|
|
|
|
#define ORBI_STATUS_FETCH 1
|
|
|
|
#define ORBI_STATUS_ATIO 2
|
|
|
|
#define ORBI_STATUS_CTIO 3
|
|
|
|
#define ORBI_STATUS_STATUS 4
|
|
|
|
#define ORBI_STATUS_POINTER 5
|
|
|
|
#define ORBI_STATUS_ABORTED 7
|
2014-09-27 16:50:21 +00:00
|
|
|
uint8_t refcount;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t orb_hi;
|
|
|
|
uint32_t orb_lo;
|
|
|
|
uint32_t data_hi;
|
|
|
|
uint32_t data_lo;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct corb4 orb4;
|
|
|
|
STAILQ_ENTRY(orb_info) link;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t orb[8];
|
2012-01-25 23:33:50 +00:00
|
|
|
struct unrestricted_page_table_fmt *page_table;
|
|
|
|
struct unrestricted_page_table_fmt *cur_pte;
|
|
|
|
struct unrestricted_page_table_fmt *last_pte;
|
|
|
|
uint32_t last_block_read;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct sbp_status status;
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *orb_fun_name[] = {
|
|
|
|
ORB_FUN_NAMES
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sbp_targ_recv(struct fw_xfer *);
|
|
|
|
static void sbp_targ_fetch_orb(struct sbp_targ_softc *, struct fw_device *,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t, uint32_t, struct sbp_targ_login *, int);
|
2012-01-25 23:33:50 +00:00
|
|
|
static void sbp_targ_xfer_pt(struct orb_info *);
|
2007-06-06 14:31:36 +00:00
|
|
|
static void sbp_targ_abort(struct sbp_targ_softc *, struct orb_info *);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
BUS_ADD_CHILD(parent, 0, "sbp_targ", device_get_unit(parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sbp_targ_probe(device_t dev)
|
|
|
|
{
|
|
|
|
device_t pa;
|
|
|
|
|
|
|
|
pa = device_get_parent(dev);
|
2014-09-27 16:50:21 +00:00
|
|
|
if (device_get_unit(dev) != device_get_unit(pa)) {
|
|
|
|
return (ENXIO);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device_set_desc(dev, "SBP-2/SCSI over FireWire target mode");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_dealloc_login(struct sbp_targ_login *login)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi, *next;
|
|
|
|
|
|
|
|
if (login == NULL) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: login = NULL\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (orbi = STAILQ_FIRST(&login->orbs); orbi != NULL; orbi = next) {
|
|
|
|
next = STAILQ_NEXT(orbi, link);
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
2003-12-11 03:42:40 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = NULL;
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
|
|
|
callout_stop(&login->hold_callout);
|
|
|
|
|
|
|
|
STAILQ_REMOVE(&login->lstate->logins, login, sbp_targ_login, link);
|
|
|
|
login->lstate->sc->logins[login->id] = NULL;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free login %p\n", __func__, login);
|
2003-12-11 03:42:40 +00:00
|
|
|
free((void *)login, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
login = NULL;
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_hold_expire(void *arg)
|
|
|
|
{
|
|
|
|
struct sbp_targ_login *login;
|
|
|
|
|
|
|
|
login = (struct sbp_targ_login *)arg;
|
|
|
|
|
|
|
|
if (login->flags & F_HOLD) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: login_id=%d expired\n", __func__, login->id);
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_dealloc_login(login);
|
|
|
|
} else {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: login_id=%d not hold\n", __func__, login->id);
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_post_busreset(void *arg)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct crom_src *src;
|
|
|
|
struct crom_chunk *root;
|
|
|
|
struct crom_chunk *unit;
|
|
|
|
struct sbp_targ_lstate *lstate;
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login;
|
2003-10-18 05:41:31 +00:00
|
|
|
int i;
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
sc = (struct sbp_targ_softc *)arg;
|
2003-10-18 05:41:31 +00:00
|
|
|
src = sc->fd.fc->crom_src;
|
|
|
|
root = sc->fd.fc->crom_root;
|
|
|
|
|
|
|
|
unit = &sc->unit;
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
if ((sc->flags & F_FREEZED) == 0) {
|
|
|
|
sc->flags |= F_FREEZED;
|
|
|
|
xpt_freeze_simq(sc->sim, /*count*/1);
|
|
|
|
} else {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: already freezed\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
bzero(unit, sizeof(struct crom_chunk));
|
|
|
|
|
|
|
|
crom_add_chunk(src, root, unit, CROM_UDIR);
|
|
|
|
crom_add_entry(unit, CSRKEY_SPEC, CSRVAL_ANSIT10);
|
|
|
|
crom_add_entry(unit, CSRKEY_VER, CSRVAL_T10SBP2);
|
|
|
|
crom_add_entry(unit, CSRKEY_COM_SPEC, CSRVAL_ANSIT10);
|
|
|
|
crom_add_entry(unit, CSRKEY_COM_SET, CSRVAL_SCSI);
|
|
|
|
|
|
|
|
crom_add_entry(unit, CROM_MGM, SBP_TARG_MGM >> 2);
|
|
|
|
crom_add_entry(unit, CSRKEY_UNIT_CH, (10<<8) | 8);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < MAX_LUN; i++) {
|
2003-10-18 05:41:31 +00:00
|
|
|
lstate = sc->lstate[i];
|
|
|
|
if (lstate == NULL)
|
|
|
|
continue;
|
|
|
|
crom_add_entry(unit, CSRKEY_FIRM_VER, 1);
|
|
|
|
crom_add_entry(unit, CROM_LUN, i);
|
|
|
|
crom_add_entry(unit, CSRKEY_MODEL, 1);
|
|
|
|
crom_add_simple_text(src, unit, &lstate->model, "TargetMode");
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
|
|
|
|
/* Process for reconnection hold time */
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < MAX_LOGINS; i++) {
|
2003-12-11 03:42:40 +00:00
|
|
|
login = sc->logins[i];
|
|
|
|
if (login == NULL)
|
|
|
|
continue;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(sc, STAILQ_FIRST(&login->orbs));
|
2003-12-11 03:42:40 +00:00
|
|
|
if (login->flags & F_LOGIN) {
|
|
|
|
login->flags |= F_HOLD;
|
|
|
|
callout_reset(&login->hold_callout,
|
2014-09-27 16:50:21 +00:00
|
|
|
hz * login->hold_sec,
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_hold_expire, (void *)login);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_post_explore(void *arg)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *)arg;
|
|
|
|
sc->flags &= ~F_FREEZED;
|
|
|
|
xpt_release_simq(sc->sim, /*run queue*/TRUE);
|
|
|
|
return;
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cam_status
|
|
|
|
sbp_targ_find_devs(struct sbp_targ_softc *sc, union ccb *ccb,
|
|
|
|
struct sbp_targ_lstate **lstate, int notfound_failure)
|
|
|
|
{
|
|
|
|
u_int lun;
|
|
|
|
|
|
|
|
/* XXX 0 is the only vaild target_id */
|
|
|
|
if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD &&
|
|
|
|
ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) {
|
|
|
|
*lstate = sc->black_hole;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("setting black hole for this target id(%d)\n", ccb->ccb_h.target_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
return (CAM_REQ_CMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
lun = ccb->ccb_h.target_lun;
|
|
|
|
if (lun >= MAX_LUN)
|
|
|
|
return (CAM_LUN_INVALID);
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
*lstate = sc->lstate[lun];
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
if (notfound_failure != 0 && *lstate == NULL) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: lstate for lun is invalid, target(%d), lun(%d)\n",
|
|
|
|
__func__, ccb->ccb_h.target_id, lun);
|
2003-10-18 05:41:31 +00:00
|
|
|
return (CAM_PATH_INVALID);
|
2012-01-25 23:33:50 +00:00
|
|
|
} else
|
|
|
|
if (debug)
|
|
|
|
printf("%s: setting lstate for tgt(%d) lun(%d)\n",
|
|
|
|
__func__,ccb->ccb_h.target_id, lun);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
return (CAM_REQ_CMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_en_lun(struct sbp_targ_softc *sc, union ccb *ccb)
|
|
|
|
{
|
|
|
|
struct ccb_en_lun *cel = &ccb->cel;
|
|
|
|
struct sbp_targ_lstate *lstate;
|
|
|
|
cam_status status;
|
|
|
|
|
|
|
|
status = sbp_targ_find_devs(sc, ccb, &lstate, 0);
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
ccb->ccb_h.status = status;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cel->enable != 0) {
|
|
|
|
if (lstate != NULL) {
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Lun already enabled\n");
|
|
|
|
ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cel->grp6_len != 0 || cel->grp7_len != 0) {
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
printf("Non-zero Group Codes\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lstate = (struct sbp_targ_lstate *)
|
|
|
|
malloc(sizeof(*lstate), M_SBP_TARG, M_NOWAIT | M_ZERO);
|
|
|
|
if (lstate == NULL) {
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Couldn't allocate lstate\n");
|
|
|
|
ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
|
|
|
|
return;
|
2012-01-25 23:33:50 +00:00
|
|
|
} else {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: malloc'd lstate %p\n",__func__, lstate);
|
|
|
|
}
|
|
|
|
if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD) {
|
2003-10-18 05:41:31 +00:00
|
|
|
sc->black_hole = lstate;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("Blackhole set due to target id == %d\n",
|
|
|
|
ccb->ccb_h.target_id);
|
|
|
|
} else
|
2003-10-18 05:41:31 +00:00
|
|
|
sc->lstate[ccb->ccb_h.target_lun] = lstate;
|
2012-01-25 23:33:50 +00:00
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
memset(lstate, 0, sizeof(*lstate));
|
|
|
|
lstate->sc = sc;
|
|
|
|
status = xpt_create_path(&lstate->path, /*periph*/NULL,
|
|
|
|
xpt_path_path_id(ccb->ccb_h.path),
|
|
|
|
xpt_path_target_id(ccb->ccb_h.path),
|
|
|
|
xpt_path_lun_id(ccb->ccb_h.path));
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
free(lstate, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
lstate = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Couldn't allocate path\n");
|
|
|
|
ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SLIST_INIT(&lstate->accept_tios);
|
|
|
|
SLIST_INIT(&lstate->immed_notifies);
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_INIT(&lstate->logins);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Lun now enabled for target mode\n");
|
|
|
|
/* bus reset */
|
|
|
|
sc->fd.fc->ibr(sc->fd.fc);
|
|
|
|
} else {
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login, *next;
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
if (lstate == NULL) {
|
|
|
|
ccb->ccb_h.status = CAM_LUN_INVALID;
|
2012-01-25 23:33:50 +00:00
|
|
|
printf("Invalid lstate for this target\n");
|
2003-10-18 05:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
|
|
|
|
if (SLIST_FIRST(&lstate->accept_tios) != NULL) {
|
|
|
|
printf("ATIOs pending\n");
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SLIST_FIRST(&lstate->immed_notifies) != NULL) {
|
|
|
|
printf("INOTs pending\n");
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ccb->ccb_h.status != CAM_REQ_CMP) {
|
2012-01-25 23:33:50 +00:00
|
|
|
printf("status != CAM_REQ_CMP\n");
|
2003-10-18 05:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Target mode disabled\n");
|
|
|
|
xpt_free_path(lstate->path);
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
for (login = STAILQ_FIRST(&lstate->logins); login != NULL;
|
|
|
|
login = next) {
|
|
|
|
next = STAILQ_NEXT(login, link);
|
|
|
|
sbp_targ_dealloc_login(login);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD)
|
|
|
|
sc->black_hole = NULL;
|
|
|
|
else
|
|
|
|
sc->lstate[ccb->ccb_h.target_lun] = NULL;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free lstate %p\n", __func__, lstate);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(lstate, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
lstate = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
/* bus reset */
|
|
|
|
sc->fd.fc->ibr(sc->fd.fc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_send_lstate_events(struct sbp_targ_softc *sc,
|
|
|
|
struct sbp_targ_lstate *lstate)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct ccb_hdr *ccbh;
|
2012-06-26 14:51:35 +00:00
|
|
|
struct ccb_immediate_notify *inot;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: not implemented yet\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
sbp_targ_remove_orb_info_locked(struct sbp_targ_login *login, struct orb_info *orbi)
|
|
|
|
{
|
|
|
|
STAILQ_REMOVE(&login->orbs, orbi, orb_info, link);
|
|
|
|
}
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
static __inline void
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_remove_orb_info(struct sbp_targ_login *login, struct orb_info *orbi)
|
2003-10-18 05:41:31 +00:00
|
|
|
{
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(orbi->sc);
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_REMOVE(&login->orbs, orbi, orb_info, link);
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_UNLOCK(orbi->sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tag_id/init_id encoding
|
|
|
|
*
|
|
|
|
* tag_id and init_id has only 32bit for each.
|
|
|
|
* scsi_target can handle very limited number(up to 15) of init_id.
|
|
|
|
* we have to encode 48bit orb and 64bit EUI64 into these
|
|
|
|
* variables.
|
|
|
|
*
|
|
|
|
* tag_id represents lower 32bit of ORB address.
|
2003-12-11 03:42:40 +00:00
|
|
|
* init_id represents login_id.
|
2003-10-18 05:41:31 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct orb_info *
|
|
|
|
sbp_targ_get_orb_info(struct sbp_targ_lstate *lstate,
|
|
|
|
u_int tag_id, u_int init_id)
|
|
|
|
{
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct orb_info *orbi;
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
login = lstate->sc->logins[init_id];
|
|
|
|
if (login == NULL) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: no such login\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
STAILQ_FOREACH(orbi, &login->orbs, link)
|
|
|
|
if (orbi->orb_lo == tag_id)
|
2003-10-18 05:41:31 +00:00
|
|
|
goto found;
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: orb not found tag_id=0x%08x init_id=%d\n",
|
2012-01-25 23:33:50 +00:00
|
|
|
__func__, tag_id, init_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
return (NULL);
|
|
|
|
found:
|
|
|
|
return (orbi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(struct sbp_targ_softc *sc, struct orb_info *orbi)
|
2003-10-18 05:41:31 +00:00
|
|
|
{
|
|
|
|
struct orb_info *norbi;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
for (; orbi != NULL; orbi = norbi) {
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: status=%d ccb=%p\n", __func__, orbi->state, orbi->ccb);
|
2003-10-18 05:41:31 +00:00
|
|
|
norbi = STAILQ_NEXT(orbi, link);
|
|
|
|
if (orbi->state != ORBI_STATUS_ABORTED) {
|
|
|
|
if (orbi->ccb != NULL) {
|
|
|
|
orbi->ccb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done(orbi->ccb);
|
|
|
|
orbi->ccb = NULL;
|
|
|
|
}
|
|
|
|
if (orbi->state <= ORBI_STATUS_ATIO) {
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_remove_orb_info_locked(orbi->login, orbi);
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
} else
|
|
|
|
orbi->state = ORBI_STATUS_ABORTED;
|
|
|
|
}
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_UNLOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_free_orbi(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
|
|
|
|
|
|
|
if (xfer->resp != 0) {
|
|
|
|
/* XXX */
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
|
|
|
if ( orbi->page_table != NULL ) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi->page_table %p\n", __func__, orbi->page_table);
|
|
|
|
free(orbi->page_table, M_SBP_TARG);
|
|
|
|
orbi->page_table = NULL;
|
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_status_FIFO(struct orb_info *orbi,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t fifo_hi, uint32_t fifo_lo, int dequeue)
|
2003-10-18 05:41:31 +00:00
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
|
|
|
|
if (dequeue)
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_remove_orb_info(orbi->login, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
xfer = fwmem_write_block(orbi->fwdev, (void *)orbi,
|
2012-01-25 23:33:50 +00:00
|
|
|
/*spd*/FWSPD_S400, fifo_hi, fifo_lo,
|
2004-05-22 16:14:17 +00:00
|
|
|
sizeof(uint32_t) * (orbi->status.len + 1), (char *)&orbi->status,
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_free_orbi);
|
|
|
|
|
|
|
|
if (xfer == NULL) {
|
|
|
|
/* XXX */
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer == NULL\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
/*
|
|
|
|
* Generate the appropriate CAM status for the
|
|
|
|
* target.
|
|
|
|
*/
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_send_status(struct orb_info *orbi, union ccb *ccb)
|
|
|
|
{
|
|
|
|
struct sbp_status *sbp_status;
|
2007-06-08 01:34:04 +00:00
|
|
|
#if 0
|
2007-06-06 14:31:36 +00:00
|
|
|
struct orb_info *norbi;
|
2007-06-08 01:34:04 +00:00
|
|
|
#endif
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sbp_status = &orbi->status;
|
|
|
|
|
|
|
|
orbi->state = ORBI_STATUS_STATUS;
|
|
|
|
|
|
|
|
sbp_status->resp = 0; /* XXX */
|
|
|
|
sbp_status->status = 0; /* XXX */
|
|
|
|
sbp_status->dead = 0; /* XXX */
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
ccb->ccb_h.status= CAM_REQ_CMP;
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
switch (ccb->csio.scsi_status) {
|
|
|
|
case SCSI_STATUS_OK:
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: STATUS_OK\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_status->len = 1;
|
|
|
|
break;
|
|
|
|
case SCSI_STATUS_CHECK_COND:
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: STATUS SCSI_STATUS_CHECK_COND\n", __func__);
|
|
|
|
goto process_scsi_status;
|
2003-10-18 05:41:31 +00:00
|
|
|
case SCSI_STATUS_BUSY:
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: STATUS SCSI_STATUS_BUSY\n", __func__);
|
|
|
|
goto process_scsi_status;
|
2003-10-18 05:41:31 +00:00
|
|
|
case SCSI_STATUS_CMD_TERMINATED:
|
2012-01-25 23:33:50 +00:00
|
|
|
process_scsi_status:
|
2003-10-18 05:41:31 +00:00
|
|
|
{
|
|
|
|
struct sbp_cmd_status *sbp_cmd_status;
|
|
|
|
struct scsi_sense_data *sense;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
int error_code, sense_key, asc, ascq;
|
|
|
|
uint8_t stream_bits;
|
|
|
|
uint8_t sks[3];
|
|
|
|
uint64_t info;
|
|
|
|
int64_t sinfo;
|
|
|
|
int sense_len;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sbp_cmd_status = (struct sbp_cmd_status *)&sbp_status->data[0];
|
|
|
|
sbp_cmd_status->status = ccb->csio.scsi_status;
|
|
|
|
sense = &ccb->csio.sense_data;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
#if 0 /* XXX What we should do? */
|
|
|
|
#if 0
|
|
|
|
sbp_targ_abort(orbi->sc, STAILQ_NEXT(orbi, link));
|
|
|
|
#else
|
|
|
|
norbi = STAILQ_NEXT(orbi, link);
|
|
|
|
while (norbi) {
|
|
|
|
printf("%s: status=%d\n", __func__, norbi->state);
|
|
|
|
if (norbi->ccb != NULL) {
|
|
|
|
norbi->ccb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done(norbi->ccb);
|
|
|
|
norbi->ccb = NULL;
|
|
|
|
}
|
|
|
|
sbp_targ_remove_orb_info_locked(orbi->login, norbi);
|
|
|
|
norbi = STAILQ_NEXT(norbi, link);
|
|
|
|
free(norbi, M_SBP_TARG);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sense_len = ccb->csio.sense_len - ccb->csio.sense_resid;
|
|
|
|
scsi_extract_sense_len(sense, sense_len, &error_code,
|
|
|
|
&sense_key, &asc, &ascq, /*show_errors*/ 0);
|
|
|
|
|
|
|
|
switch (error_code) {
|
|
|
|
case SSD_CURRENT_ERROR:
|
|
|
|
case SSD_DESC_CURRENT_ERROR:
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_cmd_status->sfmt = SBP_SFMT_CURR;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_cmd_status->sfmt = SBP_SFMT_DEFER;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info,
|
|
|
|
&sinfo) == 0) {
|
|
|
|
uint32_t info_trunc;
|
|
|
|
sbp_cmd_status->valid = 1;
|
|
|
|
info_trunc = info;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sbp_cmd_status->info = htobe32(info_trunc);
|
|
|
|
} else {
|
|
|
|
sbp_cmd_status->valid = 0;
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sbp_cmd_status->s_key = sense_key;
|
|
|
|
|
|
|
|
if (scsi_get_stream_info(sense, sense_len, NULL,
|
|
|
|
&stream_bits) == 0) {
|
|
|
|
sbp_cmd_status->mark =
|
|
|
|
(stream_bits & SSD_FILEMARK) ? 1 : 0;
|
|
|
|
sbp_cmd_status->eom =
|
|
|
|
(stream_bits & SSD_EOM) ? 1 : 0;
|
|
|
|
sbp_cmd_status->ill_len =
|
|
|
|
(stream_bits & SSD_ILI) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
sbp_cmd_status->mark = 0;
|
|
|
|
sbp_cmd_status->eom = 0;
|
|
|
|
sbp_cmd_status->ill_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* add_sense_code(_qual), info, cmd_spec_info */
|
|
|
|
sbp_status->len = 4;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
|
|
|
|
&info, &sinfo) == 0) {
|
|
|
|
uint32_t cmdspec_trunc;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
cmdspec_trunc = info;
|
|
|
|
|
|
|
|
sbp_cmd_status->cdb = htobe32(cmdspec_trunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
sbp_cmd_status->s_code = asc;
|
|
|
|
sbp_cmd_status->s_qlfr = ascq;
|
|
|
|
|
|
|
|
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, &info,
|
|
|
|
&sinfo) == 0) {
|
|
|
|
sbp_cmd_status->fru = (uint8_t)info;
|
|
|
|
sbp_status->len = 5;
|
|
|
|
} else {
|
|
|
|
sbp_cmd_status->fru = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scsi_get_sks(sense, sense_len, sks) == 0) {
|
|
|
|
bcopy(sks, &sbp_cmd_status->s_keydep[0], sizeof(sks));
|
|
|
|
sbp_status->len = 5;
|
2012-01-25 23:33:50 +00:00
|
|
|
ccb->ccb_h.status |= CAM_SENT_SENSE;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: unknown scsi status 0x%x\n", __func__,
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_status->status);
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
|
|
|
|
sbp_targ_status_FIFO(orbi,
|
|
|
|
orbi->login->fifo_hi, orbi->login->fifo_lo, /*dequeue*/1);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
/*
|
|
|
|
* Invoked as a callback handler from fwmem_read/write_block
|
|
|
|
*
|
|
|
|
* Process read/write of initiator address space
|
|
|
|
* completion and pass status onto the backend target.
|
|
|
|
* If this is a partial read/write for a CCB then
|
|
|
|
* we decrement the orbi's refcount to indicate
|
|
|
|
* the status of the read/write is complete
|
|
|
|
*/
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_cam_done(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
|
|
|
union ccb *ccb;
|
|
|
|
|
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: resp=%d refcount=%d\n", __func__,
|
2003-10-18 05:41:31 +00:00
|
|
|
xfer->resp, orbi->refcount);
|
|
|
|
|
|
|
|
if (xfer->resp != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.resp = SBP_TRANS_FAIL;
|
2004-01-23 17:37:09 +00:00
|
|
|
orbi->status.status = OBJ_DATA | SBE_TIMEOUT/*XXX*/;
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.dead = 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(orbi->sc, STAILQ_NEXT(orbi, link));
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
orbi->refcount--;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
ccb = orbi->ccb;
|
|
|
|
if (orbi->refcount == 0) {
|
2007-06-06 14:31:36 +00:00
|
|
|
orbi->ccb = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->state == ORBI_STATUS_ABORTED) {
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: orbi aborted\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_remove_orb_info(orbi->login, orbi);
|
2012-01-25 23:33:50 +00:00
|
|
|
if (orbi->page_table != NULL) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi->page_table %p\n",
|
|
|
|
__func__, orbi->page_table);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi->page_table, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = NULL;
|
|
|
|
} else if (orbi->status.resp == ORBI_STATUS_NONE) {
|
|
|
|
if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: CAM_SEND_STATUS set %0x\n", __func__, ccb->ccb_h.flags);
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_send_status(orbi, ccb);
|
2012-01-25 23:33:50 +00:00
|
|
|
} else {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: CAM_SEND_STATUS not set %0x\n", __func__, ccb->ccb_h.flags);
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
} else {
|
|
|
|
orbi->status.len = 1;
|
|
|
|
sbp_targ_status_FIFO(orbi,
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login->fifo_hi, orbi->login->fifo_lo,
|
2003-10-18 05:41:31 +00:00
|
|
|
/*dequeue*/1);
|
|
|
|
ccb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done(ccb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cam_status
|
|
|
|
sbp_targ_abort_ccb(struct sbp_targ_softc *sc, union ccb *ccb)
|
|
|
|
{
|
|
|
|
union ccb *accb;
|
|
|
|
struct sbp_targ_lstate *lstate;
|
|
|
|
struct ccb_hdr_slist *list;
|
|
|
|
struct ccb_hdr *curelm;
|
|
|
|
int found;
|
|
|
|
cam_status status;
|
|
|
|
|
|
|
|
status = sbp_targ_find_devs(sc, ccb, &lstate, 0);
|
|
|
|
if (status != CAM_REQ_CMP)
|
|
|
|
return (status);
|
|
|
|
|
|
|
|
accb = ccb->cab.abort_ccb;
|
|
|
|
|
|
|
|
if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO)
|
|
|
|
list = &lstate->accept_tios;
|
2012-06-26 14:51:35 +00:00
|
|
|
else if (accb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY)
|
2003-10-18 05:41:31 +00:00
|
|
|
list = &lstate->immed_notifies;
|
|
|
|
else
|
|
|
|
return (CAM_UA_ABORT);
|
|
|
|
|
|
|
|
curelm = SLIST_FIRST(list);
|
|
|
|
found = 0;
|
|
|
|
if (curelm == &accb->ccb_h) {
|
|
|
|
found = 1;
|
|
|
|
SLIST_REMOVE_HEAD(list, sim_links.sle);
|
|
|
|
} else {
|
2014-09-27 16:50:21 +00:00
|
|
|
while (curelm != NULL) {
|
2003-10-18 05:41:31 +00:00
|
|
|
struct ccb_hdr *nextelm;
|
|
|
|
|
|
|
|
nextelm = SLIST_NEXT(curelm, sim_links.sle);
|
|
|
|
if (nextelm == &accb->ccb_h) {
|
|
|
|
found = 1;
|
|
|
|
SLIST_NEXT(curelm, sim_links.sle) =
|
|
|
|
SLIST_NEXT(nextelm, sim_links.sle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curelm = nextelm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
accb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done(accb);
|
|
|
|
return (CAM_REQ_CMP);
|
|
|
|
}
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: not found\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
return (CAM_PATH_INVALID);
|
|
|
|
}
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
/*
|
|
|
|
* directly execute a read or write to the initiator
|
|
|
|
* address space and set hand(sbp_targ_cam_done) to
|
|
|
|
* process the completion from the SIM to the target.
|
|
|
|
* set orbi->refcount to inidicate that a read/write
|
|
|
|
* is inflight to/from the initiator.
|
|
|
|
*/
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_xfer_buf(struct orb_info *orbi, u_int offset,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t dst_hi, uint32_t dst_lo, u_int size,
|
2003-10-18 05:41:31 +00:00
|
|
|
void (*hand)(struct fw_xfer *))
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
u_int len, ccb_dir, off = 0;
|
|
|
|
char *ptr;
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
if (debug > 1)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: offset=%d size=%d\n", __func__, offset, size);
|
2003-10-18 05:41:31 +00:00
|
|
|
ccb_dir = orbi->ccb->ccb_h.flags & CAM_DIR_MASK;
|
|
|
|
ptr = (char *)orbi->ccb->csio.data_ptr + offset;
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
/* XXX assume dst_lo + off doesn't overflow */
|
|
|
|
len = MIN(size, 2048 /* XXX */);
|
|
|
|
size -= len;
|
|
|
|
orbi->refcount ++;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (ccb_dir == CAM_DIR_OUT) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: CAM_DIR_OUT --> read block in?\n",__func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
xfer = fwmem_read_block(orbi->fwdev,
|
2012-01-25 23:33:50 +00:00
|
|
|
(void *)orbi, /*spd*/FWSPD_S400,
|
2003-10-18 05:41:31 +00:00
|
|
|
dst_hi, dst_lo + off, len,
|
|
|
|
ptr + off, hand);
|
2012-01-25 23:33:50 +00:00
|
|
|
} else {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: CAM_DIR_IN --> write block out?\n",__func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
xfer = fwmem_write_block(orbi->fwdev,
|
2012-01-25 23:33:50 +00:00
|
|
|
(void *)orbi, /*spd*/FWSPD_S400,
|
2003-10-18 05:41:31 +00:00
|
|
|
dst_hi, dst_lo + off, len,
|
|
|
|
ptr + off, hand);
|
2012-01-25 23:33:50 +00:00
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
if (xfer == NULL) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer == NULL", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
/* XXX what should we do?? */
|
2014-09-27 16:50:21 +00:00
|
|
|
orbi->refcount--;
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
off += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_pt_done(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
2012-01-25 23:33:50 +00:00
|
|
|
struct unrestricted_page_table_fmt *pt;
|
|
|
|
uint32_t i;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
2012-01-25 23:33:50 +00:00
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->state == ORBI_STATUS_ABORTED) {
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: orbi aborted\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_remove_orb_info(orbi->login, orbi);
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug) {
|
|
|
|
printf("%s: free orbi->page_table %p\n", __func__, orbi->page_table);
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi->page_table, M_SBP_TARG);
|
|
|
|
free(orbi, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xfer->resp != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.resp = SBP_TRANS_FAIL;
|
2004-01-23 17:37:09 +00:00
|
|
|
orbi->status.status = OBJ_PT | SBE_TIMEOUT/*XXX*/;
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.len = 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(orbi->sc, STAILQ_NEXT(orbi, link));
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi->page_table %p\n", __func__, orbi->page_table);
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_status_FIFO(orbi,
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login->fifo_hi, orbi->login->fifo_lo, /*dequeue*/1);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi->page_table, M_SBP_TARG);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi->page_table = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi->refcount++;
|
|
|
|
/*
|
2016-05-03 03:41:25 +00:00
|
|
|
* Set endianness here so we don't have
|
2012-01-25 23:33:50 +00:00
|
|
|
* to deal with is later
|
|
|
|
*/
|
|
|
|
for (i = 0, pt = orbi->page_table; i < orbi->orb4.data_size; i++, pt++) {
|
|
|
|
pt->segment_len = ntohs(pt->segment_len);
|
|
|
|
if (debug)
|
|
|
|
printf("%s:segment_len = %u\n", __func__,pt->segment_len);
|
|
|
|
pt->segment_base_high = ntohs(pt->segment_base_high);
|
|
|
|
pt->segment_base_low = ntohl(pt->segment_base_low);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
2012-01-25 23:33:50 +00:00
|
|
|
|
|
|
|
sbp_targ_xfer_pt(orbi);
|
|
|
|
|
|
|
|
orbi->refcount--;
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->refcount == 0)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: refcount == 0\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
static void sbp_targ_xfer_pt(struct orb_info *orbi)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
uint32_t res, offset, len;
|
|
|
|
|
|
|
|
ccb = orbi->ccb;
|
|
|
|
if (debug)
|
|
|
|
printf("%s: dxfer_len=%d\n", __func__, ccb->csio.dxfer_len);
|
|
|
|
res = ccb->csio.dxfer_len;
|
|
|
|
/*
|
|
|
|
* If the page table required multiple CTIO's to
|
|
|
|
* complete, then cur_pte is non NULL
|
|
|
|
* and we need to start from the last position
|
|
|
|
* If this is the first pass over a page table
|
|
|
|
* then we just start at the beginning of the page
|
|
|
|
* table.
|
|
|
|
*
|
|
|
|
* Parse the unrestricted page table and figure out where we need
|
|
|
|
* to shove the data from this read request.
|
|
|
|
*/
|
|
|
|
for (offset = 0, len = 0; (res != 0) && (orbi->cur_pte < orbi->last_pte); offset += len) {
|
|
|
|
len = MIN(orbi->cur_pte->segment_len, res);
|
|
|
|
res -= len;
|
|
|
|
if (debug)
|
|
|
|
printf("%s:page_table: %04x:%08x segment_len(%u) res(%u) len(%u)\n",
|
|
|
|
__func__, orbi->cur_pte->segment_base_high,
|
|
|
|
orbi->cur_pte->segment_base_low,
|
|
|
|
orbi->cur_pte->segment_len,
|
|
|
|
res, len);
|
|
|
|
sbp_targ_xfer_buf(orbi, offset,
|
|
|
|
orbi->cur_pte->segment_base_high,
|
|
|
|
orbi->cur_pte->segment_base_low,
|
|
|
|
len, sbp_targ_cam_done);
|
|
|
|
/*
|
|
|
|
* If we have only written partially to
|
|
|
|
* this page table, then we need to save
|
|
|
|
* our position for the next CTIO. If we
|
|
|
|
* have completed the page table, then we
|
|
|
|
* are safe to move on to the next entry.
|
|
|
|
*/
|
|
|
|
if (len == orbi->cur_pte->segment_len) {
|
|
|
|
orbi->cur_pte++;
|
|
|
|
} else {
|
|
|
|
uint32_t saved_base_low;
|
|
|
|
|
|
|
|
/* Handle transfers that cross a 4GB boundary. */
|
|
|
|
saved_base_low = orbi->cur_pte->segment_base_low;
|
|
|
|
orbi->cur_pte->segment_base_low += len;
|
|
|
|
if (orbi->cur_pte->segment_base_low < saved_base_low)
|
|
|
|
orbi->cur_pte->segment_base_high++;
|
|
|
|
|
|
|
|
orbi->cur_pte->segment_len -= len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug) {
|
|
|
|
printf("%s: base_low(%08x) page_table_off(%p) last_block(%u)\n",
|
|
|
|
__func__, orbi->cur_pte->segment_base_low,
|
|
|
|
orbi->cur_pte, orbi->last_block_read);
|
|
|
|
}
|
|
|
|
if (res != 0)
|
|
|
|
printf("Warning - short pt encountered. "
|
|
|
|
"Could not transfer all data.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create page table in local memory
|
|
|
|
* and transfer it from the initiator
|
|
|
|
* in order to know where we are supposed
|
|
|
|
* to put the data.
|
|
|
|
*/
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_fetch_pt(struct orb_info *orbi)
|
|
|
|
{
|
|
|
|
struct fw_xfer *xfer;
|
|
|
|
|
2012-01-25 23:33:50 +00:00
|
|
|
/*
|
|
|
|
* Pull in page table from initiator
|
|
|
|
* and setup for data from our
|
|
|
|
* backend device.
|
|
|
|
*/
|
|
|
|
if (orbi->page_table == NULL) {
|
|
|
|
orbi->page_table = malloc(orbi->orb4.data_size*
|
|
|
|
sizeof(struct unrestricted_page_table_fmt),
|
|
|
|
M_SBP_TARG, M_NOWAIT|M_ZERO);
|
|
|
|
if (orbi->page_table == NULL)
|
|
|
|
goto error;
|
|
|
|
orbi->cur_pte = orbi->page_table;
|
|
|
|
orbi->last_pte = orbi->page_table + orbi->orb4.data_size;
|
|
|
|
orbi->last_block_read = orbi->orb4.data_size;
|
|
|
|
if (debug && orbi->page_table != NULL)
|
|
|
|
printf("%s: malloc'd orbi->page_table(%p), orb4.data_size(%u)\n",
|
|
|
|
__func__, orbi->page_table, orbi->orb4.data_size);
|
|
|
|
|
|
|
|
xfer = fwmem_read_block(orbi->fwdev, (void *)orbi, /*spd*/FWSPD_S400,
|
|
|
|
orbi->data_hi, orbi->data_lo, orbi->orb4.data_size*
|
|
|
|
sizeof(struct unrestricted_page_table_fmt),
|
|
|
|
(void *)orbi->page_table, sbp_targ_pt_done);
|
|
|
|
|
|
|
|
if (xfer != NULL)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This is a CTIO for a page table we have
|
|
|
|
* already malloc'd, so just directly invoke
|
|
|
|
* the xfer function on the orbi.
|
|
|
|
*/
|
|
|
|
sbp_targ_xfer_pt(orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
return;
|
2012-01-25 23:33:50 +00:00
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
error:
|
|
|
|
orbi->ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi->page_table %p due to xfer == NULL\n", __func__, orbi->page_table);
|
|
|
|
if (orbi->page_table != NULL) {
|
|
|
|
free(orbi->page_table, M_SBP_TARG);
|
|
|
|
orbi->page_table = NULL;
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
xpt_done(orbi->ccb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_action1(struct cam_sim *sim, union ccb *ccb)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct sbp_targ_lstate *lstate;
|
|
|
|
cam_status status;
|
|
|
|
u_int ccb_dir;
|
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *)cam_sim_softc(sim);
|
|
|
|
|
|
|
|
status = sbp_targ_find_devs(sc, ccb, &lstate, TRUE);
|
|
|
|
|
|
|
|
switch (ccb->ccb_h.func_code) {
|
|
|
|
case XPT_CONT_TARGET_IO:
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
|
|
|
|
|
|
|
if (debug)
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: XPT_CONT_TARGET_IO (0x%08x)\n",
|
|
|
|
__func__, ccb->csio.tag_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
ccb->ccb_h.status = status;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX transfer from/to initiator */
|
|
|
|
orbi = sbp_targ_get_orb_info(lstate,
|
|
|
|
ccb->csio.tag_id, ccb->csio.init_id);
|
|
|
|
if (orbi == NULL) {
|
|
|
|
ccb->ccb_h.status = CAM_REQ_ABORTED; /* XXX */
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (orbi->state == ORBI_STATUS_ABORTED) {
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: ctio aborted\n", __func__);
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_remove_orb_info_locked(orbi->login, orbi);
|
2012-01-25 23:33:50 +00:00
|
|
|
if (debug)
|
|
|
|
printf("%s: free orbi %p\n", __func__, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2007-06-06 14:31:36 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done(ccb);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
orbi->state = ORBI_STATUS_CTIO;
|
|
|
|
|
|
|
|
orbi->ccb = ccb;
|
|
|
|
ccb_dir = ccb->ccb_h.flags & CAM_DIR_MASK;
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
if (ccb->csio.dxfer_len == 0)
|
|
|
|
ccb_dir = CAM_DIR_NONE;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (ccb_dir == CAM_DIR_IN && orbi->orb4.dir == 0)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: direction mismatch\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
/* check page table */
|
|
|
|
if (ccb_dir != CAM_DIR_NONE && orbi->orb4.page_table_present) {
|
|
|
|
if (debug)
|
|
|
|
printf("%s: page_table_present\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->orb4.page_size != 0) {
|
|
|
|
printf("%s: unsupported pagesize %d != 0\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, orbi->orb4.page_size);
|
2003-10-18 05:41:31 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sbp_targ_fetch_pt(orbi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
2012-01-25 23:33:50 +00:00
|
|
|
if (ccb_dir != CAM_DIR_NONE) {
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_xfer_buf(orbi, 0, orbi->data_hi,
|
|
|
|
orbi->data_lo,
|
|
|
|
MIN(orbi->orb4.data_size, ccb->csio.dxfer_len),
|
|
|
|
sbp_targ_cam_done);
|
2012-01-25 23:33:50 +00:00
|
|
|
if ( orbi->orb4.data_size > ccb->csio.dxfer_len ) {
|
|
|
|
orbi->data_lo += ccb->csio.dxfer_len;
|
|
|
|
orbi->orb4.data_size -= ccb->csio.dxfer_len;
|
|
|
|
}
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
if (ccb_dir == CAM_DIR_NONE) {
|
2007-06-06 14:31:36 +00:00
|
|
|
if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
|
|
|
|
/* XXX */
|
|
|
|
SBP_UNLOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_send_status(orbi, ccb);
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(sc);
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
ccb->ccb_h.status = status;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SLIST_INSERT_HEAD(&lstate->accept_tios, &ccb->ccb_h,
|
|
|
|
sim_links.sle);
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INPROG;
|
2003-12-11 03:42:40 +00:00
|
|
|
if ((lstate->flags & F_ATIO_STARVED) != 0) {
|
|
|
|
struct sbp_targ_login *login;
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: new atio arrived\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
lstate->flags &= ~F_ATIO_STARVED;
|
|
|
|
STAILQ_FOREACH(login, &lstate->logins, link)
|
|
|
|
if ((login->flags & F_ATIO_STARVED) != 0) {
|
|
|
|
login->flags &= ~F_ATIO_STARVED;
|
|
|
|
sbp_targ_fetch_orb(lstate->sc,
|
|
|
|
login->fwdev,
|
|
|
|
login->last_hi, login->last_lo,
|
|
|
|
login, FETCH_CMD);
|
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-06-26 14:51:35 +00:00
|
|
|
case XPT_NOTIFY_ACKNOWLEDGE: /* recycle notify ack */
|
|
|
|
case XPT_IMMEDIATE_NOTIFY: /* Add Immediate Notify Resource */
|
2003-10-18 05:41:31 +00:00
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
ccb->ccb_h.status = status;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SLIST_INSERT_HEAD(&lstate->immed_notifies, &ccb->ccb_h,
|
|
|
|
sim_links.sle);
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INPROG;
|
|
|
|
sbp_targ_send_lstate_events(sc, lstate);
|
|
|
|
break;
|
|
|
|
case XPT_EN_LUN:
|
|
|
|
sbp_targ_en_lun(sc, ccb);
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_PATH_INQ:
|
|
|
|
{
|
|
|
|
struct ccb_pathinq *cpi = &ccb->cpi;
|
|
|
|
|
|
|
|
cpi->version_num = 1; /* XXX??? */
|
|
|
|
cpi->hba_inquiry = PI_TAG_ABLE;
|
|
|
|
cpi->target_sprt = PIT_PROCESSOR
|
|
|
|
| PIT_DISCONNECT
|
|
|
|
| PIT_TERM_IO;
|
2012-01-25 23:33:50 +00:00
|
|
|
cpi->transport = XPORT_SPI; /* FIXME add XPORT_FW type to cam */
|
2017-02-27 17:50:38 +00:00
|
|
|
cpi->hba_misc = PIM_NOINITIATOR | PIM_NOBUSRESET |
|
|
|
|
PIM_NO_6_BYTE;
|
2003-10-18 05:41:31 +00:00
|
|
|
cpi->hba_eng_cnt = 0;
|
|
|
|
cpi->max_target = 7; /* XXX */
|
|
|
|
cpi->max_lun = MAX_LUN - 1;
|
|
|
|
cpi->initiator_id = 7; /* XXX */
|
|
|
|
cpi->bus_id = sim->bus_id;
|
|
|
|
cpi->base_transfer_speed = 400 * 1000 / 8;
|
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, "SBP_TARG", HBA_IDLEN);
|
|
|
|
strlcpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
|
2003-10-18 05:41:31 +00:00
|
|
|
cpi->unit_number = sim->unit_number;
|
|
|
|
|
|
|
|
cpi->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_ABORT:
|
|
|
|
{
|
|
|
|
union ccb *accb = ccb->cab.abort_ccb;
|
|
|
|
|
|
|
|
switch (accb->ccb_h.func_code) {
|
|
|
|
case XPT_ACCEPT_TARGET_IO:
|
2012-06-26 14:51:35 +00:00
|
|
|
case XPT_IMMEDIATE_NOTIFY:
|
2003-10-18 05:41:31 +00:00
|
|
|
ccb->ccb_h.status = sbp_targ_abort_ccb(sc, ccb);
|
|
|
|
break;
|
|
|
|
case XPT_CONT_TARGET_IO:
|
|
|
|
/* XXX */
|
|
|
|
ccb->ccb_h.status = CAM_UA_ABORT;
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-27 16:50:21 +00:00
|
|
|
printf("%s: aborting unknown function %d\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, accb->ccb_h.func_code);
|
2003-10-18 05:41:31 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
2012-01-25 23:33:50 +00:00
|
|
|
#ifdef CAM_NEW_TRAN_CODE
|
|
|
|
case XPT_SET_TRAN_SETTINGS:
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_GET_TRAN_SETTINGS:
|
|
|
|
{
|
|
|
|
struct ccb_trans_settings *cts = &ccb->cts;
|
|
|
|
struct ccb_trans_settings_scsi *scsi =
|
|
|
|
&cts->proto_specific.scsi;
|
|
|
|
struct ccb_trans_settings_spi *spi =
|
|
|
|
&cts->xport_specific.spi;
|
|
|
|
|
|
|
|
cts->protocol = PROTO_SCSI;
|
|
|
|
cts->protocol_version = SCSI_REV_2;
|
|
|
|
cts->transport = XPORT_FW; /* should have a FireWire */
|
|
|
|
cts->transport_version = 2;
|
|
|
|
spi->valid = CTS_SPI_VALID_DISC;
|
|
|
|
spi->flags = CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
scsi->valid = CTS_SCSI_VALID_TQ;
|
|
|
|
scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
|
|
|
|
#if 0
|
|
|
|
printf("%s:%d:%d XPT_GET_TRAN_SETTINGS:\n",
|
|
|
|
device_get_nameunit(sc->fd.dev),
|
|
|
|
ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
|
|
|
|
#endif
|
|
|
|
cts->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
default:
|
2012-01-25 23:33:50 +00:00
|
|
|
printf("%s: unknown function 0x%x\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, ccb->ccb_h.func_code);
|
2012-01-25 23:33:50 +00:00
|
|
|
ccb->ccb_h.status = CAM_PROVIDE_FAIL;
|
2003-10-18 05:41:31 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_action(struct cam_sim *sim, union ccb *ccb)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
sbp_targ_action1(sim, ccb);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_poll(struct cam_sim *sim)
|
|
|
|
{
|
|
|
|
/* XXX */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_cmd_handler(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct fw_pkt *fp;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t *orb;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct corb4 *orb4;
|
|
|
|
struct orb_info *orbi;
|
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
u_char *bytes;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
|
|
|
if (xfer->resp != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.resp = SBP_TRANS_FAIL;
|
2004-01-23 17:37:09 +00:00
|
|
|
orbi->status.status = OBJ_ORB | SBE_TIMEOUT/*XXX*/;
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.len = 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(orbi->sc, STAILQ_NEXT(orbi, link));
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sbp_targ_status_FIFO(orbi,
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login->fifo_hi, orbi->login->fifo_lo, /*dequeue*/1);
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fp = &xfer->recv.hdr;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
atio = orbi->atio;
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->state == ORBI_STATUS_ABORTED) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: aborted\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_remove_orb_info(orbi->login, orbi);
|
2003-10-18 05:41:31 +00:00
|
|
|
free(orbi, M_SBP_TARG);
|
2007-06-06 14:31:36 +00:00
|
|
|
atio->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
xpt_done((union ccb*)atio);
|
2003-10-18 05:41:31 +00:00
|
|
|
goto done0;
|
|
|
|
}
|
|
|
|
orbi->state = ORBI_STATUS_ATIO;
|
|
|
|
|
|
|
|
orb = orbi->orb;
|
|
|
|
/* swap payload except SCSI command */
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < 5; i++)
|
2003-10-18 05:41:31 +00:00
|
|
|
orb[i] = ntohl(orb[i]);
|
|
|
|
|
|
|
|
orb4 = (struct corb4 *)&orb[4];
|
|
|
|
if (orb4->rq_fmt != 0) {
|
|
|
|
/* XXX */
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: rq_fmt(%d) != 0\n", __func__, orb4->rq_fmt);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
atio->ccb_h.target_id = 0; /* XXX */
|
2003-12-11 03:42:40 +00:00
|
|
|
atio->ccb_h.target_lun = orbi->login->lstate->lun;
|
2003-10-18 05:41:31 +00:00
|
|
|
atio->sense_len = 0;
|
2012-01-25 23:33:50 +00:00
|
|
|
atio->tag_action = MSG_SIMPLE_TASK;
|
2003-10-18 05:41:31 +00:00
|
|
|
atio->tag_id = orbi->orb_lo;
|
2003-12-11 03:42:40 +00:00
|
|
|
atio->init_id = orbi->login->id;
|
|
|
|
|
2013-10-21 06:04:39 +00:00
|
|
|
atio->ccb_h.flags |= CAM_TAG_ACTION_VALID;
|
2007-06-06 14:31:36 +00:00
|
|
|
bytes = (u_char *)&orb[5];
|
2003-10-18 05:41:31 +00:00
|
|
|
if (debug)
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: %p %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
__func__, (void *)atio,
|
2003-10-18 05:41:31 +00:00
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4],
|
|
|
|
bytes[5], bytes[6], bytes[7], bytes[8], bytes[9]);
|
|
|
|
switch (bytes[0] >> 5) {
|
|
|
|
case 0:
|
|
|
|
atio->cdb_len = 6;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
atio->cdb_len = 10;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
atio->cdb_len = 16;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
atio->cdb_len = 12;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
/* Only copy the opcode. */
|
|
|
|
atio->cdb_len = 1;
|
|
|
|
printf("Reserved or VU command code type encountered\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(atio->cdb_io.cdb_bytes, bytes, atio->cdb_len);
|
|
|
|
|
|
|
|
atio->ccb_h.status |= CAM_CDB_RECVD;
|
|
|
|
|
|
|
|
/* next ORB */
|
|
|
|
if ((orb[0] & (1<<31)) == 0) {
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: fetch next orb\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.src = SRC_NEXT_EXISTS;
|
|
|
|
sbp_targ_fetch_orb(orbi->sc, orbi->fwdev,
|
2003-12-11 03:42:40 +00:00
|
|
|
orb[0], orb[1], orbi->login, FETCH_CMD);
|
2003-10-18 05:41:31 +00:00
|
|
|
} else {
|
|
|
|
orbi->status.src = SRC_NO_NEXT;
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login->flags &= ~F_LINK_ACTIVE;
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
orbi->data_hi = orb[2];
|
|
|
|
orbi->data_lo = orb[3];
|
|
|
|
orbi->orb4 = *orb4;
|
|
|
|
|
|
|
|
xpt_done((union ccb*)atio);
|
|
|
|
done0:
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
static struct sbp_targ_login *
|
|
|
|
sbp_targ_get_login(struct sbp_targ_softc *sc, struct fw_device *fwdev, int lun)
|
|
|
|
{
|
|
|
|
struct sbp_targ_lstate *lstate;
|
|
|
|
struct sbp_targ_login *login;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
lstate = sc->lstate[lun];
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_FOREACH(login, &lstate->logins, link)
|
|
|
|
if (login->fwdev == fwdev)
|
|
|
|
return (login);
|
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < MAX_LOGINS; i++)
|
2003-12-11 03:42:40 +00:00
|
|
|
if (sc->logins[i] == NULL)
|
|
|
|
goto found;
|
|
|
|
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: increase MAX_LOGIN\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
found:
|
|
|
|
login = (struct sbp_targ_login *)malloc(
|
|
|
|
sizeof(struct sbp_targ_login), M_SBP_TARG, M_NOWAIT | M_ZERO);
|
|
|
|
|
|
|
|
if (login == NULL) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: malloc failed\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-05-11 14:51:13 +00:00
|
|
|
login->id = i;
|
2003-12-11 03:42:40 +00:00
|
|
|
login->fwdev = fwdev;
|
|
|
|
login->lstate = lstate;
|
|
|
|
login->last_hi = 0xffff;
|
|
|
|
login->last_lo = 0xffffffff;
|
|
|
|
login->hold_sec = 1;
|
|
|
|
STAILQ_INIT(&login->orbs);
|
|
|
|
CALLOUT_INIT(&login->hold_callout);
|
|
|
|
sc->logins[i] = login;
|
|
|
|
return (login);
|
|
|
|
}
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
static void
|
|
|
|
sbp_targ_mgm_handler(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct sbp_targ_lstate *lstate;
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct fw_pkt *fp;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t *orb;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct morb4 *orb4;
|
|
|
|
struct orb_info *orbi;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
|
|
|
if (xfer->resp != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.resp = SBP_TRANS_FAIL;
|
2004-01-23 17:37:09 +00:00
|
|
|
orbi->status.status = OBJ_ORB | SBE_TIMEOUT/*XXX*/;
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.len = 1;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(orbi->sc, STAILQ_NEXT(orbi, link));
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sbp_targ_status_FIFO(orbi,
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login->fifo_hi, orbi->login->fifo_lo, /*dequeue*/0);
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fp = &xfer->recv.hdr;
|
|
|
|
|
|
|
|
orb = orbi->orb;
|
|
|
|
/* swap payload */
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2003-10-18 05:41:31 +00:00
|
|
|
orb[i] = ntohl(orb[i]);
|
|
|
|
}
|
|
|
|
orb4 = (struct morb4 *)&orb[4];
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: %s\n", __func__, orb_fun_name[orb4->fun]);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
orbi->status.src = SRC_NO_NEXT;
|
|
|
|
|
|
|
|
switch (orb4->fun << 16) {
|
|
|
|
case ORB_FUN_LGI:
|
|
|
|
{
|
2003-12-11 03:42:40 +00:00
|
|
|
int exclusive = 0, lun;
|
|
|
|
|
|
|
|
if (orb[4] & ORB_EXV)
|
|
|
|
exclusive = 1;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
lun = orb4->id;
|
|
|
|
lstate = orbi->sc->lstate[lun];
|
|
|
|
|
|
|
|
if (lun >= MAX_LUN || lstate == NULL ||
|
2014-09-27 16:50:21 +00:00
|
|
|
(exclusive &&
|
2003-12-11 03:42:40 +00:00
|
|
|
STAILQ_FIRST(&lstate->logins) != NULL &&
|
|
|
|
STAILQ_FIRST(&lstate->logins)->fwdev != orbi->fwdev)
|
2014-09-27 16:50:21 +00:00
|
|
|
) {
|
2003-10-18 05:41:31 +00:00
|
|
|
/* error */
|
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.status = STATUS_ACCESS_DENY;
|
|
|
|
orbi->status.len = 1;
|
|
|
|
break;
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
|
|
|
|
/* allocate login */
|
|
|
|
login = sbp_targ_get_login(orbi->sc, orbi->fwdev, lun);
|
|
|
|
if (login == NULL) {
|
|
|
|
printf("%s: sbp_targ_get_login failed\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.status = STATUS_RES_UNAVAIL;
|
|
|
|
orbi->status.len = 1;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: login id=%d\n", __func__, login->id);
|
2003-12-11 03:42:40 +00:00
|
|
|
|
|
|
|
login->fifo_hi = orb[6];
|
|
|
|
login->fifo_lo = orb[7];
|
2004-05-22 16:14:17 +00:00
|
|
|
login->loginres.len = htons(sizeof(uint32_t) * 4);
|
2003-12-11 03:42:40 +00:00
|
|
|
login->loginres.id = htons(login->id);
|
|
|
|
login->loginres.cmd_hi = htons(SBP_TARG_BIND_HI);
|
|
|
|
login->loginres.cmd_lo = htonl(SBP_TARG_BIND_LO(login->id));
|
|
|
|
login->loginres.recon_hold = htons(login->hold_sec);
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
STAILQ_INSERT_TAIL(&lstate->logins, login, link);
|
2012-01-25 23:33:50 +00:00
|
|
|
fwmem_write_block(orbi->fwdev, NULL, /*spd*/FWSPD_S400, orb[2], orb[3],
|
2003-12-11 03:42:40 +00:00
|
|
|
sizeof(struct sbp_login_res), (void *)&login->loginres,
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_asy_callback_free);
|
2003-12-13 15:33:45 +00:00
|
|
|
/* XXX return status after loginres is successfully written */
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ORB_FUN_RCN:
|
2003-12-11 03:42:40 +00:00
|
|
|
login = orbi->sc->logins[orb4->id];
|
|
|
|
if (login != NULL && login->fwdev == orbi->fwdev) {
|
|
|
|
login->flags &= ~F_HOLD;
|
|
|
|
callout_stop(&login->hold_callout);
|
|
|
|
printf("%s: reconnected id=%d\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, login->id);
|
2003-12-11 03:42:40 +00:00
|
|
|
} else {
|
|
|
|
orbi->status.dead = 1;
|
|
|
|
orbi->status.status = STATUS_ACCESS_DENY;
|
|
|
|
printf("%s: reconnection faild id=%d\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, orb4->id);
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ORB_FUN_LGO:
|
|
|
|
login = orbi->sc->logins[orb4->id];
|
|
|
|
if (login->fwdev != orbi->fwdev) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: wrong initiator\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sbp_targ_dealloc_login(login);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: %s not implemented yet\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, orb_fun_name[orb4->fun]);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
orbi->status.len = 1;
|
|
|
|
sbp_targ_status_FIFO(orbi, orb[6], orb[7], /*dequeue*/0);
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_pointer_handler(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t orb0, orb1;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
orbi = (struct orb_info *)xfer->sc;
|
|
|
|
if (xfer->resp != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer->resp = %d\n", __func__, xfer->resp);
|
2003-10-18 05:41:31 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
orb0 = ntohl(orbi->orb[0]);
|
|
|
|
orb1 = ntohl(orbi->orb[1]);
|
2013-11-30 22:17:27 +00:00
|
|
|
if ((orb0 & (1U << 31)) != 0) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: invalid pointer\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_fetch_orb(orbi->login->lstate->sc, orbi->fwdev,
|
2004-05-22 16:14:17 +00:00
|
|
|
(uint16_t)orb0, orb1, orbi->login, FETCH_CMD);
|
2003-10-18 05:41:31 +00:00
|
|
|
done:
|
|
|
|
free(orbi, M_SBP_TARG);
|
|
|
|
fw_xfer_free(xfer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_fetch_orb(struct sbp_targ_softc *sc, struct fw_device *fwdev,
|
2004-05-22 16:14:17 +00:00
|
|
|
uint16_t orb_hi, uint32_t orb_lo, struct sbp_targ_login *login,
|
2003-10-18 05:41:31 +00:00
|
|
|
int mode)
|
|
|
|
{
|
|
|
|
struct orb_info *orbi;
|
|
|
|
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: fetch orb %04x:%08x\n", __func__, orb_hi, orb_lo);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi = malloc(sizeof(struct orb_info), M_SBP_TARG, M_NOWAIT | M_ZERO);
|
|
|
|
if (orbi == NULL) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: malloc failed\n", __func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
orbi->sc = sc;
|
|
|
|
orbi->fwdev = fwdev;
|
2003-12-11 03:42:40 +00:00
|
|
|
orbi->login = login;
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->orb_hi = orb_hi;
|
|
|
|
orbi->orb_lo = orb_lo;
|
|
|
|
orbi->status.orb_hi = htons(orb_hi);
|
|
|
|
orbi->status.orb_lo = htonl(orb_lo);
|
2012-01-25 23:33:50 +00:00
|
|
|
orbi->page_table = NULL;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case FETCH_MGM:
|
2012-01-25 23:33:50 +00:00
|
|
|
fwmem_read_block(fwdev, (void *)orbi, /*spd*/FWSPD_S400, orb_hi, orb_lo,
|
2004-05-22 16:14:17 +00:00
|
|
|
sizeof(uint32_t) * 8, &orbi->orb[0],
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_mgm_handler);
|
|
|
|
break;
|
|
|
|
case FETCH_CMD:
|
|
|
|
orbi->state = ORBI_STATUS_FETCH;
|
2003-12-11 03:42:40 +00:00
|
|
|
login->last_hi = orb_hi;
|
|
|
|
login->last_lo = orb_lo;
|
|
|
|
login->flags |= F_LINK_ACTIVE;
|
2003-10-18 05:41:31 +00:00
|
|
|
/* dequeue */
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
orbi->atio = (struct ccb_accept_tio *)
|
2003-12-11 03:42:40 +00:00
|
|
|
SLIST_FIRST(&login->lstate->accept_tios);
|
2003-10-18 05:41:31 +00:00
|
|
|
if (orbi->atio == NULL) {
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_UNLOCK(sc);
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: no free atio\n", __func__);
|
2003-12-11 03:42:40 +00:00
|
|
|
login->lstate->flags |= F_ATIO_STARVED;
|
|
|
|
login->flags |= F_ATIO_STARVED;
|
|
|
|
#if 0
|
|
|
|
/* XXX ?? */
|
|
|
|
login->fwdev = fwdev;
|
|
|
|
#endif
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
SLIST_REMOVE_HEAD(&login->lstate->accept_tios, sim_links.sle);
|
2007-06-06 14:31:36 +00:00
|
|
|
STAILQ_INSERT_TAIL(&login->orbs, orbi, link);
|
|
|
|
SBP_UNLOCK(sc);
|
2012-01-25 23:33:50 +00:00
|
|
|
fwmem_read_block(fwdev, (void *)orbi, /*spd*/FWSPD_S400, orb_hi, orb_lo,
|
2004-05-22 16:14:17 +00:00
|
|
|
sizeof(uint32_t) * 8, &orbi->orb[0],
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_cmd_handler);
|
|
|
|
break;
|
|
|
|
case FETCH_POINTER:
|
|
|
|
orbi->state = ORBI_STATUS_POINTER;
|
2003-12-11 03:42:40 +00:00
|
|
|
login->flags |= F_LINK_ACTIVE;
|
2012-01-25 23:33:50 +00:00
|
|
|
fwmem_read_block(fwdev, (void *)orbi, /*spd*/FWSPD_S400, orb_hi, orb_lo,
|
2004-05-22 16:14:17 +00:00
|
|
|
sizeof(uint32_t) * 2, &orbi->orb[0],
|
2003-10-18 05:41:31 +00:00
|
|
|
sbp_targ_pointer_handler);
|
|
|
|
break;
|
|
|
|
default:
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: invalid mode %d\n", __func__, mode);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_resp_callback(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (debug)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: xfer=%p\n", __func__, xfer);
|
2003-10-18 05:41:31 +00:00
|
|
|
sc = (struct sbp_targ_softc *)xfer->sc;
|
|
|
|
fw_xfer_unload(xfer);
|
|
|
|
xfer->recv.pay_len = SBP_TARG_RECV_LEN;
|
2007-03-16 05:39:33 +00:00
|
|
|
xfer->hand = sbp_targ_recv;
|
2003-10-18 05:41:31 +00:00
|
|
|
s = splfw();
|
|
|
|
STAILQ_INSERT_TAIL(&sc->fwb.xferlist, xfer, link);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_cmd(struct fw_xfer *xfer, struct fw_device *fwdev, int login_id,
|
|
|
|
int reg)
|
2003-10-18 05:41:31 +00:00
|
|
|
{
|
2003-12-11 03:42:40 +00:00
|
|
|
struct sbp_targ_login *login;
|
2003-10-18 05:41:31 +00:00
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
int rtcode = 0;
|
|
|
|
|
2003-12-11 03:42:40 +00:00
|
|
|
if (login_id < 0 || login_id >= MAX_LOGINS)
|
2014-09-27 16:50:21 +00:00
|
|
|
return (RESP_ADDRESS_ERROR);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *)xfer->sc;
|
2003-12-11 03:42:40 +00:00
|
|
|
login = sc->logins[login_id];
|
|
|
|
if (login == NULL)
|
2014-09-27 16:50:21 +00:00
|
|
|
return (RESP_ADDRESS_ERROR);
|
2003-12-11 03:42:40 +00:00
|
|
|
|
|
|
|
if (login->fwdev != fwdev) {
|
|
|
|
/* XXX */
|
2014-09-27 16:50:21 +00:00
|
|
|
return (RESP_ADDRESS_ERROR);
|
2003-12-11 03:42:40 +00:00
|
|
|
}
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case 0x08: /* ORB_POINTER */
|
|
|
|
if (debug)
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: ORB_POINTER(%d)\n", __func__, login_id);
|
2003-12-11 03:42:40 +00:00
|
|
|
if ((login->flags & F_LINK_ACTIVE) != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("link active (ORB_POINTER)\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sbp_targ_fetch_orb(sc, fwdev,
|
2003-10-18 05:41:31 +00:00
|
|
|
ntohl(xfer->recv.payload[0]),
|
|
|
|
ntohl(xfer->recv.payload[1]),
|
2003-12-11 03:42:40 +00:00
|
|
|
login, FETCH_CMD);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
case 0x04: /* AGENT_RESET */
|
|
|
|
if (debug)
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: AGENT RESET(%d)\n", __func__, login_id);
|
2003-12-11 03:42:40 +00:00
|
|
|
login->last_hi = 0xffff;
|
|
|
|
login->last_lo = 0xffffffff;
|
2007-06-06 14:31:36 +00:00
|
|
|
sbp_targ_abort(sc, STAILQ_FIRST(&login->orbs));
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
case 0x10: /* DOORBELL */
|
|
|
|
if (debug)
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: DOORBELL(%d)\n", __func__, login_id);
|
2003-12-11 03:42:40 +00:00
|
|
|
if (login->last_hi == 0xffff &&
|
|
|
|
login->last_lo == 0xffffffff) {
|
2003-10-18 05:41:31 +00:00
|
|
|
printf("%s: no previous pointer(DOORBELL)\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
if ((login->flags & F_LINK_ACTIVE) != 0) {
|
2003-10-18 05:41:31 +00:00
|
|
|
if (debug)
|
|
|
|
printf("link active (DOORBELL)\n");
|
|
|
|
break;
|
|
|
|
}
|
2003-12-11 03:42:40 +00:00
|
|
|
sbp_targ_fetch_orb(sc, fwdev,
|
|
|
|
login->last_hi, login->last_lo,
|
|
|
|
login, FETCH_POINTER);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
case 0x00: /* AGENT_STATE */
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: AGENT_STATE (%d:ignore)\n", __func__, login_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
case 0x14: /* UNSOLICITED_STATE_ENABLE */
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: UNSOLICITED_STATE_ENABLE (%d:ignore)\n",
|
|
|
|
__func__, login_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-06-06 14:31:36 +00:00
|
|
|
printf("%s: invalid register %d(%d)\n",
|
|
|
|
__func__, reg, login_id);
|
2003-10-18 05:41:31 +00:00
|
|
|
rtcode = RESP_ADDRESS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rtcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sbp_targ_mgm(struct fw_xfer *xfer, struct fw_device *fwdev)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct fw_pkt *fp;
|
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *)xfer->sc;
|
|
|
|
|
|
|
|
fp = &xfer->recv.hdr;
|
2014-09-27 16:50:21 +00:00
|
|
|
if (fp->mode.wreqb.tcode != FWTCODE_WREQB) {
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: tcode = %d\n", __func__, fp->mode.wreqb.tcode);
|
2014-09-27 16:50:21 +00:00
|
|
|
return (RESP_TYPE_ERROR);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sbp_targ_fetch_orb(sc, fwdev,
|
|
|
|
ntohl(xfer->recv.payload[0]),
|
|
|
|
ntohl(xfer->recv.payload[1]),
|
|
|
|
NULL, FETCH_MGM);
|
2014-09-27 16:50:21 +00:00
|
|
|
|
|
|
|
return (0);
|
2003-10-18 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sbp_targ_recv(struct fw_xfer *xfer)
|
|
|
|
{
|
|
|
|
struct fw_pkt *fp, *sfp;
|
|
|
|
struct fw_device *fwdev;
|
2004-05-22 16:14:17 +00:00
|
|
|
uint32_t lo;
|
2003-10-18 05:41:31 +00:00
|
|
|
int s, rtcode;
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
|
|
|
|
s = splfw();
|
|
|
|
sc = (struct sbp_targ_softc *)xfer->sc;
|
|
|
|
fp = &xfer->recv.hdr;
|
|
|
|
fwdev = fw_noderesolve_nodeid(sc->fd.fc, fp->mode.wreqb.src & 0x3f);
|
|
|
|
if (fwdev == NULL) {
|
|
|
|
printf("%s: cannot resolve nodeid=%d\n",
|
2004-03-26 23:17:10 +00:00
|
|
|
__func__, fp->mode.wreqb.src & 0x3f);
|
2003-10-18 05:41:31 +00:00
|
|
|
rtcode = RESP_TYPE_ERROR; /* XXX */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
lo = fp->mode.wreqb.dest_lo;
|
2007-06-06 14:31:36 +00:00
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
if (lo == SBP_TARG_BIND_LO(-1))
|
|
|
|
rtcode = sbp_targ_mgm(xfer, fwdev);
|
|
|
|
else if (lo >= SBP_TARG_BIND_LO(0))
|
2003-12-11 03:42:40 +00:00
|
|
|
rtcode = sbp_targ_cmd(xfer, fwdev, SBP_TARG_LOGIN_ID(lo),
|
|
|
|
lo % 0x20);
|
2003-10-18 05:41:31 +00:00
|
|
|
else
|
|
|
|
rtcode = RESP_ADDRESS_ERROR;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (rtcode != 0)
|
2004-03-26 23:17:10 +00:00
|
|
|
printf("%s: rtcode = %d\n", __func__, rtcode);
|
2003-10-18 05:41:31 +00:00
|
|
|
sfp = &xfer->send.hdr;
|
2012-01-25 23:33:50 +00:00
|
|
|
xfer->send.spd = FWSPD_S400;
|
2007-03-16 05:39:33 +00:00
|
|
|
xfer->hand = sbp_targ_resp_callback;
|
2003-10-18 05:41:31 +00:00
|
|
|
sfp->mode.wres.dst = fp->mode.wreqb.src;
|
|
|
|
sfp->mode.wres.tlrt = fp->mode.wreqb.tlrt;
|
|
|
|
sfp->mode.wres.tcode = FWTCODE_WRES;
|
|
|
|
sfp->mode.wres.rtcode = rtcode;
|
|
|
|
sfp->mode.wres.pri = 0;
|
|
|
|
|
|
|
|
fw_asyreq(xfer->fc, -1, xfer);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sbp_targ_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct cam_devq *devq;
|
2007-06-06 14:31:36 +00:00
|
|
|
struct firewire_comm *fc;
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *) device_get_softc(dev);
|
|
|
|
bzero((void *)sc, sizeof(struct sbp_targ_softc));
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
mtx_init(&sc->mtx, "sbp_targ", NULL, MTX_DEF);
|
|
|
|
sc->fd.fc = fc = device_get_ivars(dev);
|
2003-10-18 05:41:31 +00:00
|
|
|
sc->fd.dev = dev;
|
2003-12-11 03:42:40 +00:00
|
|
|
sc->fd.post_explore = (void *) sbp_targ_post_explore;
|
2003-10-18 05:41:31 +00:00
|
|
|
sc->fd.post_busreset = (void *) sbp_targ_post_busreset;
|
|
|
|
|
2007-05-11 14:51:13 +00:00
|
|
|
devq = cam_simq_alloc(/*maxopenings*/MAX_LUN*MAX_INITIATORS);
|
2003-10-18 05:41:31 +00:00
|
|
|
if (devq == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
sc->sim = cam_sim_alloc(sbp_targ_action, sbp_targ_poll,
|
2007-06-06 14:31:36 +00:00
|
|
|
"sbp_targ", sc, device_get_unit(dev), &sc->mtx,
|
2003-10-18 05:41:31 +00:00
|
|
|
/*untagged*/ 1, /*tagged*/ 1, devq);
|
|
|
|
if (sc->sim == NULL) {
|
|
|
|
cam_simq_free(devq);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(sc);
|
2007-06-17 05:55:54 +00:00
|
|
|
if (xpt_bus_register(sc->sim, dev, /*bus*/0) != CAM_SUCCESS)
|
2003-10-18 05:41:31 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (xpt_create_path(&sc->path, /*periph*/ NULL, cam_sim_path(sc->sim),
|
|
|
|
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
|
|
|
|
xpt_bus_deregister(cam_sim_path(sc->sim));
|
|
|
|
goto fail;
|
|
|
|
}
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_UNLOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
|
|
|
sc->fwb.start = SBP_TARG_BIND_START;
|
|
|
|
sc->fwb.end = SBP_TARG_BIND_END;
|
|
|
|
|
|
|
|
/* pre-allocate xfer */
|
|
|
|
STAILQ_INIT(&sc->fwb.xferlist);
|
2007-04-30 13:41:40 +00:00
|
|
|
fw_xferlist_add(&sc->fwb.xferlist, M_SBP_TARG,
|
|
|
|
/*send*/ 0, /*recv*/ SBP_TARG_RECV_LEN, MAX_LUN /* XXX */,
|
2007-06-06 14:31:36 +00:00
|
|
|
fc, (void *)sc, sbp_targ_recv);
|
|
|
|
fw_bindadd(fc, &sc->fwb);
|
2003-10-18 05:41:31 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_UNLOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
cam_sim_free(sc->sim, /*free_devq*/TRUE);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sbp_targ_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct sbp_targ_softc *sc;
|
|
|
|
struct sbp_targ_lstate *lstate;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = (struct sbp_targ_softc *)device_get_softc(dev);
|
|
|
|
sc->fd.post_busreset = NULL;
|
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
SBP_LOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
xpt_free_path(sc->path);
|
|
|
|
xpt_bus_deregister(cam_sim_path(sc->sim));
|
2014-09-27 16:50:21 +00:00
|
|
|
cam_sim_free(sc->sim, /*free_devq*/TRUE);
|
2017-02-28 05:24:06 +00:00
|
|
|
SBP_UNLOCK(sc);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2014-09-27 16:50:21 +00:00
|
|
|
for (i = 0; i < MAX_LUN; i++) {
|
2003-10-18 05:41:31 +00:00
|
|
|
lstate = sc->lstate[i];
|
|
|
|
if (lstate != NULL) {
|
|
|
|
xpt_free_path(lstate->path);
|
|
|
|
free(lstate, M_SBP_TARG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->black_hole != NULL) {
|
|
|
|
xpt_free_path(sc->black_hole->path);
|
|
|
|
free(sc->black_hole, M_SBP_TARG);
|
|
|
|
}
|
2014-09-27 16:50:21 +00:00
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
fw_bindremove(sc->fd.fc, &sc->fwb);
|
2007-04-30 13:41:40 +00:00
|
|
|
fw_xferlist_remove(&sc->fwb.xferlist);
|
2003-10-18 05:41:31 +00:00
|
|
|
|
2007-06-06 14:31:36 +00:00
|
|
|
mtx_destroy(&sc->mtx);
|
|
|
|
|
2003-10-18 05:41:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static devclass_t sbp_targ_devclass;
|
|
|
|
|
|
|
|
static device_method_t sbp_targ_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_identify, sbp_targ_identify),
|
|
|
|
DEVMETHOD(device_probe, sbp_targ_probe),
|
|
|
|
DEVMETHOD(device_attach, sbp_targ_attach),
|
|
|
|
DEVMETHOD(device_detach, sbp_targ_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t sbp_targ_driver = {
|
|
|
|
"sbp_targ",
|
|
|
|
sbp_targ_methods,
|
|
|
|
sizeof(struct sbp_targ_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(sbp_targ, firewire, sbp_targ_driver, sbp_targ_devclass, 0, 0);
|
|
|
|
MODULE_VERSION(sbp_targ, 1);
|
|
|
|
MODULE_DEPEND(sbp_targ, firewire, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(sbp_targ, cam, 1, 1, 1);
|