1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Implementation of a simple Target Mode SCSI Proccessor Target driver for CAM.
|
|
|
|
*
|
1999-01-14 05:57:32 +00:00
|
|
|
* Copyright (c) 1998, 1999 Justin T. Gibbs.
|
1998-09-15 06:36:34 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-09-15 06:36:34 +00:00
|
|
|
*/
|
|
|
|
#include <stddef.h> /* For offsetof */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/types.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1998-09-15 06:36:34 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/devicestat.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/select.h> /* For struct selinfo. */
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/cam_extend.h>
|
|
|
|
#include <cam/cam_periph.h>
|
1998-12-15 08:15:15 +00:00
|
|
|
#include <cam/cam_queue.h>
|
1998-09-15 06:36:34 +00:00
|
|
|
#include <cam/cam_xpt_periph.h>
|
|
|
|
#include <cam/cam_debug.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
#include <cam/scsi/scsi_pt.h>
|
|
|
|
#include <cam/scsi/scsi_targetio.h>
|
|
|
|
#include <cam/scsi/scsi_message.h>
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TARG_STATE_NORMAL,
|
|
|
|
TARG_STATE_EXCEPTION,
|
|
|
|
TARG_STATE_TEARDOWN
|
|
|
|
} targ_state;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TARG_FLAG_NONE = 0x00,
|
|
|
|
TARG_FLAG_SEND_EOF = 0x01,
|
1998-12-15 08:15:15 +00:00
|
|
|
TARG_FLAG_RECEIVE_EOF = 0x02,
|
|
|
|
TARG_FLAG_LUN_ENABLED = 0x04
|
1998-09-15 06:36:34 +00:00
|
|
|
} targ_flags;
|
|
|
|
|
|
|
|
typedef enum {
|
1999-08-16 22:39:25 +00:00
|
|
|
TARG_CCB_NONE = 0x00,
|
|
|
|
TARG_CCB_WAITING = 0x01,
|
|
|
|
TARG_CCB_HELDQ = 0x02,
|
|
|
|
TARG_CCB_ABORT_TO_HELDQ = 0x04
|
|
|
|
} targ_ccb_flags;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
#define MAX_ACCEPT 16
|
|
|
|
#define MAX_IMMEDIATE 16
|
|
|
|
#define MAX_BUF_SIZE 256 /* Max inquiry/sense/mode page transfer */
|
2000-01-25 17:42:27 +00:00
|
|
|
#define MAX_INITIATORS 256 /* includes widest fibre channel for now */
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
#define MIN(a, b) ((a > b) ? b : a)
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
#define TARG_CONTROL_UNIT 0xffff00ff
|
|
|
|
#define TARG_IS_CONTROL_DEV(unit) ((unit) == TARG_CONTROL_UNIT)
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
#define TARG_TAG_WILDCARD ((u_int)~0)
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/* Offsets into our private CCB area for storing accept information */
|
1999-08-16 22:39:25 +00:00
|
|
|
#define ccb_flags ppriv_field0
|
1998-09-15 06:36:34 +00:00
|
|
|
#define ccb_descr ppriv_ptr1
|
|
|
|
|
|
|
|
/* We stick a pointer to the originating accept TIO in each continue I/O CCB */
|
|
|
|
#define ccb_atio ppriv_ptr1
|
|
|
|
|
|
|
|
struct targ_softc {
|
1999-08-16 22:39:25 +00:00
|
|
|
/* CTIOs pending on the controller */
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_queue pending_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/* ATIOs awaiting CTIO resources from the XPT */
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_queue work_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ATIOs for SEND operations waiting for 'write'
|
|
|
|
* buffer resources from our userland daemon.
|
|
|
|
*/
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_queue snd_ccb_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ATIOs for RCV operations waiting for 'read'
|
|
|
|
* buffer resources from our userland daemon.
|
|
|
|
*/
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_queue rcv_ccb_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ATIOs for commands unknown to the kernel driver.
|
|
|
|
* These are queued for the userland daemon to
|
|
|
|
* consume.
|
|
|
|
*/
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_queue unknown_atio_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Userland buffers for SEND commands waiting for
|
|
|
|
* SEND ATIOs to be queued by an initiator.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio_queue_head snd_bio_queue;
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Userland buffers for RCV commands waiting for
|
|
|
|
* RCV ATIOs to be queued by an initiator.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio_queue_head rcv_bio_queue;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct devstat device_stats;
|
1999-11-17 04:59:09 +00:00
|
|
|
dev_t targ_dev;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct selinfo snd_select;
|
|
|
|
struct selinfo rcv_select;
|
|
|
|
targ_state state;
|
|
|
|
targ_flags flags;
|
|
|
|
targ_exception exceptions;
|
|
|
|
u_int init_level;
|
|
|
|
u_int inq_data_len;
|
|
|
|
struct scsi_inquiry_data *inq_data;
|
1998-12-17 00:03:14 +00:00
|
|
|
struct ccb_accept_tio *accept_tio_list;
|
1998-12-15 08:15:15 +00:00
|
|
|
struct ccb_hdr_slist immed_notify_slist;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct initiator_state istate[MAX_INITIATORS];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct targ_cmd_desc {
|
1998-12-17 00:03:14 +00:00
|
|
|
struct ccb_accept_tio* atio_link;
|
1998-09-15 06:36:34 +00:00
|
|
|
u_int data_resid; /* How much left to transfer */
|
|
|
|
u_int data_increment;/* Amount to send before next disconnect */
|
|
|
|
void* data; /* The data. Can be from backing_store or not */
|
|
|
|
void* backing_store;/* Backing store allocated for this descriptor*/
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio *bp; /* Buffer for this transfer */
|
1998-09-15 06:36:34 +00:00
|
|
|
u_int max_size; /* Size of backing_store */
|
|
|
|
u_int32_t timeout;
|
|
|
|
u_int8_t status; /* Status to return to initiator */
|
|
|
|
};
|
|
|
|
|
|
|
|
static d_open_t targopen;
|
|
|
|
static d_close_t targclose;
|
|
|
|
static d_read_t targread;
|
|
|
|
static d_write_t targwrite;
|
|
|
|
static d_ioctl_t targioctl;
|
|
|
|
static d_poll_t targpoll;
|
|
|
|
static d_strategy_t targstrategy;
|
|
|
|
|
|
|
|
#define TARG_CDEV_MAJOR 65
|
|
|
|
static struct cdevsw targ_cdevsw = {
|
1999-05-30 16:53:49 +00:00
|
|
|
/* open */ targopen,
|
|
|
|
/* close */ targclose,
|
|
|
|
/* read */ targread,
|
|
|
|
/* write */ targwrite,
|
|
|
|
/* ioctl */ targioctl,
|
|
|
|
/* poll */ targpoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ targstrategy,
|
|
|
|
/* name */ "targ",
|
|
|
|
/* maj */ TARG_CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
|
|
|
/* bmaj */ -1
|
1998-09-15 06:36:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int targsendccb(struct cam_periph *periph, union ccb *ccb,
|
|
|
|
union ccb *inccb);
|
|
|
|
static periph_init_t targinit;
|
|
|
|
static void targasync(void *callback_arg, u_int32_t code,
|
|
|
|
struct cam_path *path, void *arg);
|
1999-03-05 23:25:11 +00:00
|
|
|
static int targallocinstance(struct ioc_alloc_unit *alloc_unit);
|
|
|
|
static int targfreeinstance(struct ioc_alloc_unit *alloc_unit);
|
1998-12-15 08:15:15 +00:00
|
|
|
static cam_status targenlun(struct cam_periph *periph);
|
|
|
|
static cam_status targdislun(struct cam_periph *periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
static periph_ctor_t targctor;
|
|
|
|
static periph_dtor_t targdtor;
|
|
|
|
static void targrunqueue(struct cam_periph *periph,
|
|
|
|
struct targ_softc *softc);
|
|
|
|
static periph_start_t targstart;
|
|
|
|
static void targdone(struct cam_periph *periph,
|
|
|
|
union ccb *done_ccb);
|
|
|
|
static void targfireexception(struct cam_periph *periph,
|
|
|
|
struct targ_softc *softc);
|
1999-08-16 22:39:25 +00:00
|
|
|
static void targinoterror(struct cam_periph *periph,
|
|
|
|
struct targ_softc *softc,
|
|
|
|
struct ccb_immed_notify *inot);
|
1998-09-15 06:36:34 +00:00
|
|
|
static int targerror(union ccb *ccb, u_int32_t cam_flags,
|
|
|
|
u_int32_t sense_flags);
|
|
|
|
static struct targ_cmd_desc* allocdescr(void);
|
|
|
|
static void freedescr(struct targ_cmd_desc *buf);
|
1999-08-16 22:39:25 +00:00
|
|
|
static void fill_sense(struct targ_softc *softc,
|
|
|
|
u_int initiator_id, u_int error_code,
|
|
|
|
u_int sense_key, u_int asc, u_int ascq);
|
|
|
|
static void copy_sense(struct targ_softc *softc,
|
2000-01-25 17:42:27 +00:00
|
|
|
struct initiator_state *istate,
|
|
|
|
u_int8_t *sense_buffer, size_t sense_len);
|
1999-08-16 22:39:25 +00:00
|
|
|
static void set_unit_attention_cond(struct cam_periph *periph,
|
|
|
|
u_int initiator_id, ua_types ua);
|
2000-01-25 17:42:27 +00:00
|
|
|
static void set_ca_condition(struct cam_periph *periph,
|
|
|
|
u_int initiator_id, ca_types ca);
|
1999-08-16 22:39:25 +00:00
|
|
|
static void abort_pending_transactions(struct cam_periph *periph,
|
|
|
|
u_int initiator_id, u_int tag_id,
|
|
|
|
int errno, int to_held_queue);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
static struct periph_driver targdriver =
|
|
|
|
{
|
|
|
|
targinit, "targ",
|
|
|
|
TAILQ_HEAD_INITIALIZER(targdriver.units), /* generation */ 0
|
|
|
|
};
|
|
|
|
|
|
|
|
DATA_SET(periphdriver_set, targdriver);
|
|
|
|
|
|
|
|
static struct extend_array *targperiphs;
|
1999-12-29 22:55:01 +00:00
|
|
|
static dev_t targ_ctl_dev;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
targinit(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Create our extend array for storing the devices we attach to.
|
|
|
|
*/
|
|
|
|
targperiphs = cam_extend_new();
|
|
|
|
if (targperiphs == NULL) {
|
|
|
|
printf("targ: Failed to alloc extend array!\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-12-29 22:55:01 +00:00
|
|
|
targ_ctl_dev = make_dev(&targ_cdevsw, TARG_CONTROL_UNIT, UID_ROOT,
|
|
|
|
GID_OPERATOR, 0600, "%s.ctl", "targ");
|
|
|
|
if (targ_ctl_dev == (dev_t) 0) {
|
|
|
|
printf("targ: failed to create control dev\n");
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
targasync(void *callback_arg, u_int32_t code,
|
|
|
|
struct cam_path *path, void *arg)
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
1999-08-16 22:39:25 +00:00
|
|
|
struct targ_softc *softc;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
periph = (struct cam_periph *)callback_arg;
|
1999-08-16 22:39:25 +00:00
|
|
|
softc = (struct targ_softc *)periph->softc;
|
1998-09-15 06:36:34 +00:00
|
|
|
switch (code) {
|
|
|
|
case AC_PATH_DEREGISTERED:
|
|
|
|
{
|
|
|
|
/* XXX Implement */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
/* Attempt to enable our lun */
|
1998-09-15 06:36:34 +00:00
|
|
|
static cam_status
|
1998-12-15 08:15:15 +00:00
|
|
|
targenlun(struct cam_periph *periph)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
|
|
|
union ccb immed_ccb;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
cam_status status;
|
|
|
|
int i;
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
softc = (struct targ_softc *)periph->softc;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
if ((softc->flags & TARG_FLAG_LUN_ENABLED) != 0)
|
|
|
|
return (CAM_REQ_CMP);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
xpt_setup_ccb(&immed_ccb.ccb_h, periph->path, /*priority*/1);
|
|
|
|
immed_ccb.ccb_h.func_code = XPT_EN_LUN;
|
|
|
|
|
|
|
|
/* Don't need support for any vendor specific commands */
|
|
|
|
immed_ccb.cel.grp6_len = 0;
|
|
|
|
immed_ccb.cel.grp7_len = 0;
|
|
|
|
immed_ccb.cel.enable = 1;
|
|
|
|
xpt_action(&immed_ccb);
|
|
|
|
status = immed_ccb.ccb_h.status;
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
xpt_print_path(periph->path);
|
1999-12-30 02:32:13 +00:00
|
|
|
printf("targenlun - Enable Lun Rejected with status 0x%x\n",
|
1998-09-15 06:36:34 +00:00
|
|
|
status);
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
softc->flags |= TARG_FLAG_LUN_ENABLED;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Build up a buffer of accept target I/O
|
|
|
|
* operations for incoming selections.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_ACCEPT; i++) {
|
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
|
|
|
|
atio = (struct ccb_accept_tio*)malloc(sizeof(*atio), M_DEVBUF,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (atio == NULL) {
|
|
|
|
status = CAM_RESRC_UNAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
atio->ccb_h.ccb_descr = allocdescr();
|
|
|
|
|
|
|
|
if (atio->ccb_h.ccb_descr == NULL) {
|
|
|
|
free(atio, M_DEVBUF);
|
|
|
|
status = CAM_RESRC_UNAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xpt_setup_ccb(&atio->ccb_h, periph->path, /*priority*/1);
|
|
|
|
atio->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
|
|
|
|
atio->ccb_h.cbfcnp = targdone;
|
2000-03-18 22:13:27 +00:00
|
|
|
atio->ccb_h.ccb_flags = TARG_CCB_NONE;
|
1998-09-15 06:36:34 +00:00
|
|
|
xpt_action((union ccb *)atio);
|
|
|
|
status = atio->ccb_h.status;
|
|
|
|
if (status != CAM_REQ_INPROG) {
|
1999-03-05 23:25:11 +00:00
|
|
|
xpt_print_path(periph->path);
|
|
|
|
printf("Queue of atio failed\n");
|
1998-12-17 00:03:14 +00:00
|
|
|
freedescr(atio->ccb_h.ccb_descr);
|
1998-09-15 06:36:34 +00:00
|
|
|
free(atio, M_DEVBUF);
|
|
|
|
break;
|
|
|
|
}
|
1998-12-17 00:03:14 +00:00
|
|
|
((struct targ_cmd_desc*)atio->ccb_h.ccb_descr)->atio_link =
|
|
|
|
softc->accept_tio_list;
|
|
|
|
softc->accept_tio_list = atio;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
xpt_print_path(periph->path);
|
1998-12-15 08:15:15 +00:00
|
|
|
printf("targenlun - Could not allocate accept tio CCBs: "
|
1998-09-15 06:36:34 +00:00
|
|
|
"status = 0x%x\n", status);
|
1998-12-15 08:15:15 +00:00
|
|
|
targdislun(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
return (CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build up a buffer of immediate notify CCBs
|
|
|
|
* so the SIM can tell us of asynchronous target mode events.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_ACCEPT; i++) {
|
|
|
|
struct ccb_immed_notify *inot;
|
|
|
|
|
|
|
|
inot = (struct ccb_immed_notify*)malloc(sizeof(*inot), M_DEVBUF,
|
|
|
|
M_NOWAIT);
|
|
|
|
|
|
|
|
if (inot == NULL) {
|
|
|
|
status = CAM_RESRC_UNAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xpt_setup_ccb(&inot->ccb_h, periph->path, /*priority*/1);
|
|
|
|
inot->ccb_h.func_code = XPT_IMMED_NOTIFY;
|
|
|
|
inot->ccb_h.cbfcnp = targdone;
|
1998-12-15 08:15:15 +00:00
|
|
|
SLIST_INSERT_HEAD(&softc->immed_notify_slist, &inot->ccb_h,
|
|
|
|
periph_links.sle);
|
1999-08-16 22:39:25 +00:00
|
|
|
xpt_action((union ccb *)inot);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
xpt_print_path(periph->path);
|
1998-12-15 08:15:15 +00:00
|
|
|
printf("targenlun - Could not allocate immediate notify CCBs: "
|
1998-09-15 06:36:34 +00:00
|
|
|
"status = 0x%x\n", status);
|
1998-12-15 08:15:15 +00:00
|
|
|
targdislun(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
return (CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (CAM_REQ_CMP);
|
|
|
|
}
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
static cam_status
|
|
|
|
targdislun(struct cam_periph *periph)
|
|
|
|
{
|
|
|
|
union ccb ccb;
|
|
|
|
struct targ_softc *softc;
|
1998-12-17 00:03:14 +00:00
|
|
|
struct ccb_accept_tio* atio;
|
1998-12-15 08:15:15 +00:00
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
if ((softc->flags & TARG_FLAG_LUN_ENABLED) == 0)
|
|
|
|
return CAM_REQ_CMP;
|
|
|
|
|
|
|
|
/* XXX Block for Continue I/O completion */
|
|
|
|
|
|
|
|
/* Kill off all ACCECPT and IMMEDIATE CCBs */
|
1998-12-17 00:03:14 +00:00
|
|
|
while ((atio = softc->accept_tio_list) != NULL) {
|
1999-03-05 23:25:11 +00:00
|
|
|
|
1998-12-17 00:03:14 +00:00
|
|
|
softc->accept_tio_list =
|
|
|
|
((struct targ_cmd_desc*)atio->ccb_h.ccb_descr)->atio_link;
|
1998-12-15 08:15:15 +00:00
|
|
|
xpt_setup_ccb(&ccb.cab.ccb_h, periph->path, /*priority*/1);
|
|
|
|
ccb.cab.ccb_h.func_code = XPT_ABORT;
|
1998-12-17 00:03:14 +00:00
|
|
|
ccb.cab.abort_ccb = (union ccb *)atio;
|
1998-12-15 08:15:15 +00:00
|
|
|
xpt_action(&ccb);
|
|
|
|
}
|
|
|
|
|
1998-12-17 00:03:14 +00:00
|
|
|
while ((ccb_h = SLIST_FIRST(&softc->immed_notify_slist)) != NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&softc->immed_notify_slist, periph_links.sle);
|
1998-12-15 08:15:15 +00:00
|
|
|
xpt_setup_ccb(&ccb.cab.ccb_h, periph->path, /*priority*/1);
|
|
|
|
ccb.cab.ccb_h.func_code = XPT_ABORT;
|
|
|
|
ccb.cab.abort_ccb = (union ccb *)ccb_h;
|
|
|
|
xpt_action(&ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dissable this lun.
|
|
|
|
*/
|
|
|
|
xpt_setup_ccb(&ccb.cel.ccb_h, periph->path, /*priority*/1);
|
|
|
|
ccb.cel.ccb_h.func_code = XPT_EN_LUN;
|
|
|
|
ccb.cel.enable = 0;
|
|
|
|
xpt_action(&ccb);
|
|
|
|
|
|
|
|
if (ccb.cel.ccb_h.status != CAM_REQ_CMP)
|
|
|
|
printf("targdislun - Disabling lun on controller failed "
|
|
|
|
"with status 0x%x\n", ccb.cel.ccb_h.status);
|
|
|
|
else
|
|
|
|
softc->flags &= ~TARG_FLAG_LUN_ENABLED;
|
|
|
|
return (ccb.cel.ccb_h.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cam_status
|
|
|
|
targctor(struct cam_periph *periph, void *arg)
|
|
|
|
{
|
|
|
|
struct ccb_pathinq *cpi;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cpi = (struct ccb_pathinq *)arg;
|
|
|
|
|
|
|
|
/* Allocate our per-instance private storage */
|
|
|
|
softc = (struct targ_softc *)malloc(sizeof(*softc), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (softc == NULL) {
|
|
|
|
printf("targctor: unable to malloc softc\n");
|
|
|
|
return (CAM_REQ_CMP_ERR);
|
|
|
|
}
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
bzero(softc, sizeof(*softc));
|
1998-12-15 08:15:15 +00:00
|
|
|
TAILQ_INIT(&softc->pending_queue);
|
|
|
|
TAILQ_INIT(&softc->work_queue);
|
|
|
|
TAILQ_INIT(&softc->snd_ccb_queue);
|
|
|
|
TAILQ_INIT(&softc->rcv_ccb_queue);
|
|
|
|
TAILQ_INIT(&softc->unknown_atio_queue);
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_init(&softc->snd_bio_queue);
|
|
|
|
bioq_init(&softc->rcv_bio_queue);
|
1998-12-17 00:03:14 +00:00
|
|
|
softc->accept_tio_list = NULL;
|
1998-12-15 08:15:15 +00:00
|
|
|
SLIST_INIT(&softc->immed_notify_slist);
|
|
|
|
softc->state = TARG_STATE_NORMAL;
|
|
|
|
periph->softc = softc;
|
|
|
|
softc->init_level++;
|
|
|
|
|
|
|
|
cam_extend_set(targperiphs, periph->unit_number, periph);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We start out life with a UA to indicate power-on/reset.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_INITIATORS; i++)
|
|
|
|
softc->istate[i].pending_ua = UA_POWER_ON;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an initial inquiry data buffer. We might allow the
|
|
|
|
* user to override this later via an ioctl.
|
|
|
|
*/
|
|
|
|
softc->inq_data_len = sizeof(*softc->inq_data);
|
|
|
|
softc->inq_data = malloc(softc->inq_data_len, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (softc->inq_data == NULL) {
|
|
|
|
printf("targctor - Unable to malloc inquiry data\n");
|
|
|
|
targdtor(periph);
|
1999-03-05 23:25:11 +00:00
|
|
|
return (CAM_RESRC_UNAVAIL);
|
1998-12-15 08:15:15 +00:00
|
|
|
}
|
|
|
|
bzero(softc->inq_data, softc->inq_data_len);
|
|
|
|
softc->inq_data->device = T_PROCESSOR | (SID_QUAL_LU_CONNECTED << 5);
|
|
|
|
softc->inq_data->version = 2;
|
|
|
|
softc->inq_data->response_format = 2; /* SCSI2 Inquiry Format */
|
|
|
|
softc->inq_data->flags =
|
2000-07-14 19:45:43 +00:00
|
|
|
cpi->hba_inquiry & (PI_SDTR_ABLE|PI_WIDE_16|PI_WIDE_32|PI_TAG_ABLE);
|
1998-12-15 08:15:15 +00:00
|
|
|
softc->inq_data->additional_length = softc->inq_data_len - 4;
|
|
|
|
strncpy(softc->inq_data->vendor, "FreeBSD ", SID_VENDOR_SIZE);
|
|
|
|
strncpy(softc->inq_data->product, "TM-PT ", SID_PRODUCT_SIZE);
|
|
|
|
strncpy(softc->inq_data->revision, "0.0 ", SID_REVISION_SIZE);
|
1999-11-17 04:59:09 +00:00
|
|
|
softc->targ_dev = make_dev(&targ_cdevsw, periph->unit_number, UID_ROOT,
|
|
|
|
GID_OPERATOR, 0600, "%s%d",
|
|
|
|
periph->periph_name, periph->unit_number);
|
1998-12-15 08:15:15 +00:00
|
|
|
softc->init_level++;
|
|
|
|
return (CAM_REQ_CMP);
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
static void
|
|
|
|
targdtor(struct cam_periph *periph)
|
|
|
|
{
|
|
|
|
struct targ_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
softc->state = TARG_STATE_TEARDOWN;
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
targdislun(periph);
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
cam_extend_release(targperiphs, periph->unit_number);
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
switch (softc->init_level) {
|
|
|
|
default:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 2:
|
|
|
|
free(softc->inq_data, M_DEVBUF);
|
1999-11-17 04:59:09 +00:00
|
|
|
destroy_dev(softc->targ_dev);
|
1998-09-15 06:36:34 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 1:
|
|
|
|
free(softc, M_DEVBUF);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
panic("targdtor - impossible init level");;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
targopen(dev_t dev, int flags, int fmt, struct proc *p)
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
1999-03-05 23:25:11 +00:00
|
|
|
struct targ_softc *softc;
|
1998-12-15 08:15:15 +00:00
|
|
|
u_int unit;
|
|
|
|
cam_status status;
|
|
|
|
int error;
|
|
|
|
int s;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
unit = minor(dev);
|
1998-12-15 08:15:15 +00:00
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
/* An open of the control device always succeeds */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit))
|
|
|
|
return 0;
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
s = splsoftcam();
|
1998-09-15 06:36:34 +00:00
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
1998-12-15 08:15:15 +00:00
|
|
|
if (periph == NULL) {
|
|
|
|
splx(s);
|
2000-07-14 19:45:43 +00:00
|
|
|
return (ENXIO);
|
1998-12-15 08:15:15 +00:00
|
|
|
}
|
|
|
|
if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-03-05 23:25:11 +00:00
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
if ((softc->flags & TARG_FLAG_LUN_ENABLED) == 0) {
|
|
|
|
if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
|
|
|
|
splx(s);
|
|
|
|
cam_periph_unlock(periph);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
}
|
1998-12-15 08:15:15 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
status = targenlun(periph);
|
|
|
|
switch (status) {
|
|
|
|
case CAM_REQ_CMP:
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case CAM_RESRC_UNAVAIL:
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
case CAM_LUN_ALRDY_ENA:
|
|
|
|
error = EADDRINUSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cam_periph_unlock(periph);
|
1999-12-30 02:32:13 +00:00
|
|
|
if (error) {
|
|
|
|
cam_periph_release(periph);
|
|
|
|
}
|
1998-12-15 08:15:15 +00:00
|
|
|
return (error);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
targclose(dev_t dev, int flag, int fmt, struct proc *p)
|
|
|
|
{
|
1998-12-15 08:15:15 +00:00
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
u_int unit;
|
|
|
|
int s;
|
|
|
|
int error;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
unit = minor(dev);
|
1999-03-05 23:25:11 +00:00
|
|
|
|
|
|
|
/* A close of the control device always succeeds */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit))
|
|
|
|
return 0;
|
|
|
|
|
1998-12-15 08:15:15 +00:00
|
|
|
s = splsoftcam();
|
1998-09-15 06:36:34 +00:00
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
1998-12-15 08:15:15 +00:00
|
|
|
if (periph == NULL) {
|
|
|
|
splx(s);
|
1998-09-15 06:36:34 +00:00
|
|
|
return (ENXIO);
|
1998-12-15 08:15:15 +00:00
|
|
|
}
|
|
|
|
if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
|
|
|
|
return (error);
|
1998-09-15 06:36:34 +00:00
|
|
|
softc = (struct targ_softc *)periph->softc;
|
1998-12-15 08:15:15 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
targdislun(periph);
|
|
|
|
|
|
|
|
cam_periph_unlock(periph);
|
1999-03-05 23:25:11 +00:00
|
|
|
cam_periph_release(periph);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
static int
|
|
|
|
targallocinstance(struct ioc_alloc_unit *alloc_unit)
|
|
|
|
{
|
|
|
|
struct ccb_pathinq cpi;
|
|
|
|
struct cam_path *path;
|
|
|
|
struct cam_periph *periph;
|
|
|
|
cam_status status;
|
|
|
|
int free_path_on_return;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
free_path_on_return = 0;
|
|
|
|
status = xpt_create_path(&path, /*periph*/NULL,
|
|
|
|
alloc_unit->path_id,
|
|
|
|
alloc_unit->target_id,
|
|
|
|
alloc_unit->lun_id);
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
printf("Couldn't Allocate Path %x\n", status);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
1999-10-27 21:49:36 +00:00
|
|
|
free_path_on_return++;
|
|
|
|
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);
|
|
|
|
cpi.ccb_h.func_code = XPT_PATH_INQ;
|
|
|
|
xpt_action((union ccb *)&cpi);
|
|
|
|
status = cpi.ccb_h.status;
|
|
|
|
|
|
|
|
if (status != CAM_REQ_CMP) {
|
|
|
|
printf("Couldn't CPI %x\n", status);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can only alloc units on controllers that support target mode */
|
|
|
|
if ((cpi.target_sprt & PIT_PROCESSOR) == 0) {
|
|
|
|
printf("Controller does not support target mode%x\n", status);
|
|
|
|
status = CAM_PATH_INVALID;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure that we don't already have an instance for this unit. */
|
|
|
|
if ((periph = cam_periph_find(path, "targ")) != NULL) {
|
|
|
|
status = CAM_LUN_ALRDY_ENA;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a peripheral instance for
|
|
|
|
* this target instance.
|
|
|
|
*/
|
|
|
|
status = cam_periph_alloc(targctor, NULL, targdtor, targstart,
|
|
|
|
"targ", CAM_PERIPH_BIO, path, targasync,
|
|
|
|
0, &cpi);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
switch (status) {
|
|
|
|
case CAM_REQ_CMP:
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
|
|
|
|
if ((periph = cam_periph_find(path, "targ")) == NULL)
|
|
|
|
panic("targallocinstance: Succeeded but no periph?");
|
|
|
|
error = 0;
|
|
|
|
alloc_unit->unit = periph->unit_number;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CAM_RESRC_UNAVAIL:
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
case CAM_LUN_ALRDY_ENA:
|
|
|
|
error = EADDRINUSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("targallocinstance: Unexpected CAM status %x\n", status);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case CAM_PATH_INVALID:
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
case CAM_PROVIDE_FAIL:
|
|
|
|
error = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
1999-05-04 19:24:21 +00:00
|
|
|
|
|
|
|
if (free_path_on_return != 0)
|
|
|
|
xpt_free_path(path);
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
targfreeinstance(struct ioc_alloc_unit *alloc_unit)
|
|
|
|
{
|
|
|
|
struct cam_path *path;
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
cam_status status;
|
|
|
|
int free_path_on_return;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
periph = NULL;
|
|
|
|
free_path_on_return = 0;
|
|
|
|
status = xpt_create_path(&path, /*periph*/NULL,
|
|
|
|
alloc_unit->path_id,
|
|
|
|
alloc_unit->target_id,
|
|
|
|
alloc_unit->lun_id);
|
|
|
|
free_path_on_return++;
|
|
|
|
|
|
|
|
if (status != CAM_REQ_CMP)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Find our instance. */
|
|
|
|
if ((periph = cam_periph_find(path, "targ")) == NULL) {
|
|
|
|
xpt_print_path(path);
|
2000-03-18 22:13:27 +00:00
|
|
|
printf("Invalid path specified for freeing target instance\n");
|
1999-03-05 23:25:11 +00:00
|
|
|
status = CAM_PATH_INVALID;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
if ((softc->flags & TARG_FLAG_LUN_ENABLED) != 0) {
|
|
|
|
status = CAM_BUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (free_path_on_return != 0)
|
|
|
|
xpt_free_path(path);
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case CAM_REQ_CMP:
|
|
|
|
if (periph != NULL)
|
|
|
|
cam_periph_invalidate(periph);
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case CAM_RESRC_UNAVAIL:
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
case CAM_LUN_ALRDY_ENA:
|
|
|
|
error = EADDRINUSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("targfreeinstance: Unexpected CAM status %x\n", status);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case CAM_PATH_INVALID:
|
|
|
|
error = ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
static int
|
|
|
|
targioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
u_int unit;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
1999-03-05 23:25:11 +00:00
|
|
|
error = 0;
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit)) {
|
|
|
|
switch (cmd) {
|
|
|
|
case TARGCTLIOALLOCUNIT:
|
|
|
|
error = targallocinstance((struct ioc_alloc_unit*)addr);
|
|
|
|
break;
|
|
|
|
case TARGCTLIOFREEUNIT:
|
|
|
|
error = targfreeinstance((struct ioc_alloc_unit*)addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
|
|
|
if (periph == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
switch (cmd) {
|
|
|
|
case TARGIOCFETCHEXCEPTION:
|
|
|
|
*((targ_exception *)addr) = softc->exceptions;
|
|
|
|
break;
|
|
|
|
case TARGIOCCLEAREXCEPTION:
|
|
|
|
{
|
|
|
|
targ_exception clear_mask;
|
|
|
|
|
|
|
|
clear_mask = *((targ_exception *)addr);
|
|
|
|
if ((clear_mask & TARG_EXCEPT_UNKNOWN_ATIO) != 0) {
|
|
|
|
struct ccb_hdr *ccbh;
|
|
|
|
|
|
|
|
ccbh = TAILQ_FIRST(&softc->unknown_atio_queue);
|
|
|
|
if (ccbh != NULL) {
|
|
|
|
TAILQ_REMOVE(&softc->unknown_atio_queue,
|
|
|
|
ccbh, periph_links.tqe);
|
1999-05-22 22:00:24 +00:00
|
|
|
/* Requeue the ATIO back to the controller */
|
2000-07-14 19:45:43 +00:00
|
|
|
ccbh->ccb_flags = TARG_CCB_NONE;
|
1999-05-22 22:00:24 +00:00
|
|
|
xpt_action((union ccb *)ccbh);
|
1998-09-15 06:36:34 +00:00
|
|
|
ccbh = TAILQ_FIRST(&softc->unknown_atio_queue);
|
|
|
|
}
|
|
|
|
if (ccbh != NULL)
|
|
|
|
clear_mask &= ~TARG_EXCEPT_UNKNOWN_ATIO;
|
|
|
|
}
|
|
|
|
softc->exceptions &= ~clear_mask;
|
|
|
|
if (softc->exceptions == TARG_EXCEPT_NONE
|
|
|
|
&& softc->state == TARG_STATE_EXCEPTION) {
|
|
|
|
softc->state = TARG_STATE_NORMAL;
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TARGIOCFETCHATIO:
|
|
|
|
{
|
|
|
|
struct ccb_hdr *ccbh;
|
|
|
|
|
|
|
|
ccbh = TAILQ_FIRST(&softc->unknown_atio_queue);
|
|
|
|
if (ccbh != NULL) {
|
|
|
|
bcopy(ccbh, addr, sizeof(struct ccb_accept_tio));
|
|
|
|
} else {
|
|
|
|
error = ENOENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TARGIOCCOMMAND:
|
|
|
|
{
|
|
|
|
union ccb *inccb;
|
|
|
|
union ccb *ccb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX JGibbs
|
|
|
|
* This code is lifted directly from the pass-thru driver.
|
|
|
|
* Perhaps this should be moved to a library????
|
|
|
|
*/
|
|
|
|
inccb = (union ccb *)addr;
|
|
|
|
ccb = cam_periph_getccb(periph, inccb->ccb_h.pinfo.priority);
|
|
|
|
|
|
|
|
error = targsendccb(periph, ccb, inccb);
|
|
|
|
|
|
|
|
xpt_release_ccb(ccb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TARGIOCGETISTATE:
|
|
|
|
case TARGIOCSETISTATE:
|
|
|
|
{
|
|
|
|
struct ioc_initiator_state *ioc_istate;
|
|
|
|
|
|
|
|
ioc_istate = (struct ioc_initiator_state *)addr;
|
|
|
|
if (ioc_istate->initiator_id > MAX_INITIATORS) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("GET/SETISTATE for %d\n", ioc_istate->initiator_id));
|
1998-09-15 06:36:34 +00:00
|
|
|
if (cmd == TARGIOCGETISTATE) {
|
|
|
|
bcopy(&softc->istate[ioc_istate->initiator_id],
|
|
|
|
&ioc_istate->istate, sizeof(ioc_istate->istate));
|
|
|
|
} else {
|
|
|
|
bcopy(&ioc_istate->istate,
|
|
|
|
&softc->istate[ioc_istate->initiator_id],
|
|
|
|
sizeof(ioc_istate->istate));
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("pending_ca now %x\n",
|
|
|
|
softc->istate[ioc_istate->initiator_id].pending_ca));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-07-14 19:45:43 +00:00
|
|
|
#ifdef CAMDEBUG
|
|
|
|
case TARGIODEBUG:
|
|
|
|
{
|
|
|
|
union ccb ccb;
|
|
|
|
bzero (&ccb, sizeof ccb);
|
|
|
|
if (xpt_create_path(&ccb.ccb_h.path, periph,
|
|
|
|
xpt_path_path_id(periph->path),
|
|
|
|
xpt_path_target_id(periph->path),
|
|
|
|
xpt_path_lun_id(periph->path)) != CAM_REQ_CMP) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*((int *)addr)) {
|
|
|
|
ccb.cdbg.flags = CAM_DEBUG_PERIPH;
|
|
|
|
} else {
|
|
|
|
ccb.cdbg.flags = CAM_DEBUG_NONE;
|
|
|
|
}
|
|
|
|
xpt_setup_ccb(&ccb.ccb_h, ccb.ccb_h.path, 0);
|
|
|
|
ccb.ccb_h.func_code = XPT_DEBUG;
|
|
|
|
ccb.ccb_h.path_id = xpt_path_path_id(ccb.ccb_h.path);
|
|
|
|
ccb.ccb_h.target_id = xpt_path_target_id(ccb.ccb_h.path);
|
|
|
|
ccb.ccb_h.target_lun = xpt_path_lun_id(ccb.ccb_h.path);
|
|
|
|
ccb.ccb_h.cbfcnp = targdone;
|
|
|
|
xpt_action(&ccb);
|
|
|
|
if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
|
|
|
|
error = EIO;
|
|
|
|
} else {
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
xpt_free_path(ccb.ccb_h.path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
1998-09-15 06:36:34 +00:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX JGibbs lifted from pass-thru driver.
|
|
|
|
* Generally, "ccb" should be the CCB supplied by the kernel. "inccb"
|
|
|
|
* should be the CCB that is copied in from the user.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
targsendccb(struct cam_periph *periph, union ccb *ccb, union ccb *inccb)
|
|
|
|
{
|
|
|
|
struct targ_softc *softc;
|
|
|
|
struct cam_periph_map_info mapinfo;
|
|
|
|
int error, need_unmap;
|
1999-08-16 22:39:25 +00:00
|
|
|
int s;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
need_unmap = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are some fields in the CCB header that need to be
|
|
|
|
* preserved, the rest we get from the user.
|
|
|
|
*/
|
|
|
|
xpt_merge_ccb(ccb, inccb);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's no way for the user to have a completion
|
|
|
|
* function, so we put our own completion function in here.
|
|
|
|
*/
|
|
|
|
ccb->ccb_h.cbfcnp = targdone;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only attempt to map the user memory into kernel space
|
|
|
|
* if they haven't passed in a physical memory pointer,
|
|
|
|
* and if there is actually an I/O operation to perform.
|
|
|
|
* Right now cam_periph_mapmem() only supports SCSI and device
|
|
|
|
* match CCBs. For the SCSI CCBs, we only pass the CCB in if
|
|
|
|
* there's actually data to map. cam_periph_mapmem() will do the
|
|
|
|
* right thing, even if there isn't data to map, but since CCBs
|
|
|
|
* without data are a reasonably common occurance (e.g. test unit
|
|
|
|
* ready), it will save a few cycles if we check for it here.
|
|
|
|
*/
|
|
|
|
if (((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0)
|
|
|
|
&& (((ccb->ccb_h.func_code == XPT_CONT_TARGET_IO)
|
|
|
|
&& ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE))
|
|
|
|
|| (ccb->ccb_h.func_code == XPT_DEV_MATCH))) {
|
|
|
|
|
|
|
|
bzero(&mapinfo, sizeof(mapinfo));
|
|
|
|
|
|
|
|
error = cam_periph_mapmem(ccb, &mapinfo);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cam_periph_mapmem returned an error, we can't continue.
|
|
|
|
* Return the error to the user.
|
|
|
|
*/
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We successfully mapped the memory in, so we need to
|
|
|
|
* unmap it when the transaction is done.
|
|
|
|
*/
|
|
|
|
need_unmap = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-08-16 22:39:25 +00:00
|
|
|
* Once queued on the pending CCB list, this CCB will be protected
|
|
|
|
* by the error recovery handling used for 'buffer I/O' ccbs. Since
|
|
|
|
* we are in a process context here, however, the software interrupt
|
|
|
|
* for this driver may deliver an event invalidating this CCB just
|
|
|
|
* before we queue it. Close this race condition by blocking
|
|
|
|
* software interrupt delivery, checking for any pertinent queued
|
|
|
|
* events, and only then queuing this CCB.
|
1998-09-15 06:36:34 +00:00
|
|
|
*/
|
1999-08-16 22:39:25 +00:00
|
|
|
s = splsoftcam();
|
|
|
|
if (softc->exceptions == 0) {
|
|
|
|
if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO)
|
|
|
|
TAILQ_INSERT_TAIL(&softc->pending_queue, &ccb->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user wants us to perform any error recovery,
|
|
|
|
* then honor that request. Otherwise, it's up to the
|
|
|
|
* user to perform any error recovery.
|
|
|
|
*/
|
|
|
|
error = cam_periph_runccb(ccb,
|
|
|
|
/* error handler */NULL,
|
|
|
|
/* cam_flags */ 0,
|
|
|
|
/* sense_flags */SF_RETRY_UA,
|
|
|
|
&softc->device_stats);
|
|
|
|
|
|
|
|
if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO)
|
2000-03-18 22:13:27 +00:00
|
|
|
TAILQ_REMOVE(&softc->pending_queue, &ccb->ccb_h,
|
|
|
|
periph_links.tqe);
|
1999-08-16 22:39:25 +00:00
|
|
|
} else {
|
|
|
|
ccb->ccb_h.status = CAM_UNACKED_EVENT;
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
splx(s);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (need_unmap != 0)
|
|
|
|
cam_periph_unmapmem(ccb, &mapinfo);
|
|
|
|
|
|
|
|
ccb->ccb_h.cbfcnp = NULL;
|
|
|
|
ccb->ccb_h.periph_priv = inccb->ccb_h.periph_priv;
|
|
|
|
bcopy(ccb, inccb, sizeof(union ccb));
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
targpoll(dev_t dev, int poll_events, struct proc *p)
|
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
u_int unit;
|
|
|
|
int revents;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
1999-03-05 23:25:11 +00:00
|
|
|
|
|
|
|
/* ioctl is the only supported operation of the control device */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit))
|
|
|
|
return EINVAL;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
|
|
|
if (periph == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
revents = 0;
|
|
|
|
s = splcam();
|
|
|
|
if ((poll_events & (POLLOUT | POLLWRNORM)) != 0) {
|
|
|
|
if (TAILQ_FIRST(&softc->rcv_ccb_queue) != NULL
|
2000-04-15 05:54:02 +00:00
|
|
|
&& bioq_first(&softc->rcv_bio_queue) == NULL)
|
1998-09-15 06:36:34 +00:00
|
|
|
revents |= poll_events & (POLLOUT | POLLWRNORM);
|
|
|
|
}
|
|
|
|
if ((poll_events & (POLLIN | POLLRDNORM)) != 0) {
|
|
|
|
if (TAILQ_FIRST(&softc->snd_ccb_queue) != NULL
|
2000-04-15 05:54:02 +00:00
|
|
|
&& bioq_first(&softc->snd_bio_queue) == NULL)
|
1998-09-15 06:36:34 +00:00
|
|
|
revents |= poll_events & (POLLIN | POLLRDNORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (softc->state != TARG_STATE_NORMAL)
|
|
|
|
revents |= POLLERR;
|
|
|
|
|
|
|
|
if (revents == 0) {
|
|
|
|
if (poll_events & (POLLOUT | POLLWRNORM))
|
|
|
|
selrecord(p, &softc->rcv_select);
|
|
|
|
if (poll_events & (POLLIN | POLLRDNORM))
|
|
|
|
selrecord(p, &softc->snd_select);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
targread(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1999-03-05 23:25:11 +00:00
|
|
|
u_int unit;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
/* ioctl is the only supported operation of the control device */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit))
|
|
|
|
return EINVAL;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
if (uio->uio_iovcnt == 0
|
|
|
|
|| uio->uio_iov->iov_len == 0) {
|
|
|
|
/* EOF */
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splcam();
|
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
|
|
|
if (periph == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
softc->flags |= TARG_FLAG_SEND_EOF;
|
|
|
|
splx(s);
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-05-07 07:03:47 +00:00
|
|
|
return(physread(dev, uio, ioflag));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
targwrite(dev_t dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
1999-03-05 23:25:11 +00:00
|
|
|
u_int unit;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
/* ioctl is the only supported operation of the control device */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit))
|
|
|
|
return EINVAL;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
if (uio->uio_iovcnt == 0
|
|
|
|
|| uio->uio_iov->iov_len == 0) {
|
|
|
|
/* EOF */
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splcam();
|
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
|
|
|
if (periph == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
softc->flags |= TARG_FLAG_RECEIVE_EOF;
|
|
|
|
splx(s);
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-05-07 07:03:47 +00:00
|
|
|
return(physwrite(dev, uio, ioflag));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actually translate the requested transfer into one the physical driver
|
|
|
|
* can understand. The transfer is described by a buf and will include
|
|
|
|
* only one physical transfer.
|
|
|
|
*/
|
|
|
|
static void
|
2000-04-15 05:54:02 +00:00
|
|
|
targstrategy(struct bio *bp)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
u_int unit;
|
|
|
|
int s;
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
unit = minor(bp->bio_dev);
|
1999-03-05 23:25:11 +00:00
|
|
|
|
|
|
|
/* ioctl is the only supported operation of the control device */
|
|
|
|
if (TARG_IS_CONTROL_DEV(unit)) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EINVAL;
|
1999-03-05 23:25:11 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
periph = cam_extend_get(targperiphs, unit);
|
|
|
|
if (periph == NULL) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = ENXIO;
|
1999-03-05 23:25:11 +00:00
|
|
|
goto bad;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask interrupts so that the device cannot be invalidated until
|
|
|
|
* after we are in the queue. Otherwise, we might not properly
|
|
|
|
* clean up one of the buffers.
|
|
|
|
*/
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is an exception pending, error out
|
|
|
|
*/
|
|
|
|
if (softc->state != TARG_STATE_NORMAL) {
|
|
|
|
splx(s);
|
|
|
|
if (softc->state == TARG_STATE_EXCEPTION
|
|
|
|
&& (softc->exceptions & TARG_EXCEPT_DEVICE_INVALID) == 0)
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EBUSY;
|
1998-09-15 06:36:34 +00:00
|
|
|
else
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = ENXIO;
|
1998-09-15 06:36:34 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place it in the queue of buffers available for either
|
|
|
|
* SEND or RECEIVE commands.
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = bp->bio_bcount;
|
|
|
|
if (bp->bio_cmd == BIO_READ) {
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Queued a SEND buffer\n"));
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_insert_tail(&softc->snd_bio_queue, bp);
|
1998-09-15 06:36:34 +00:00
|
|
|
} else {
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Queued a RECEIVE buffer\n"));
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_insert_tail(&softc->rcv_bio_queue, bp);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to use the new buffer to service any pending
|
|
|
|
* target commands.
|
|
|
|
*/
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
|
|
|
|
return;
|
|
|
|
bad:
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Correctly set the buf to indicate a completed xfer
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = bp->bio_bcount;
|
1998-09-15 06:36:34 +00:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
targrunqueue(struct cam_periph *periph, struct targ_softc *softc)
|
|
|
|
{
|
|
|
|
struct ccb_queue *pending_queue;
|
|
|
|
struct ccb_accept_tio *atio;
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio_queue_head *bioq;
|
|
|
|
struct bio *bp;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct targ_cmd_desc *desc;
|
|
|
|
struct ccb_hdr *ccbh;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
pending_queue = NULL;
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq = NULL;
|
1998-09-15 06:36:34 +00:00
|
|
|
ccbh = NULL;
|
|
|
|
/* Only run one request at a time to maintain data ordering. */
|
|
|
|
if (softc->state != TARG_STATE_NORMAL
|
|
|
|
|| TAILQ_FIRST(&softc->work_queue) != NULL
|
|
|
|
|| TAILQ_FIRST(&softc->pending_queue) != NULL) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
if (((bp = bioq_first(&softc->snd_bio_queue)) != NULL
|
1998-09-15 06:36:34 +00:00
|
|
|
|| (softc->flags & TARG_FLAG_SEND_EOF) != 0)
|
|
|
|
&& (ccbh = TAILQ_FIRST(&softc->snd_ccb_queue)) != NULL) {
|
|
|
|
|
|
|
|
if (bp == NULL)
|
|
|
|
softc->flags &= ~TARG_FLAG_SEND_EOF;
|
|
|
|
else {
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("De-Queued a SEND buffer %ld\n",
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_bcount));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq = &softc->snd_bio_queue;
|
1998-09-15 06:36:34 +00:00
|
|
|
pending_queue = &softc->snd_ccb_queue;
|
2000-04-15 05:54:02 +00:00
|
|
|
} else if (((bp = bioq_first(&softc->rcv_bio_queue)) != NULL
|
1998-09-15 06:36:34 +00:00
|
|
|
|| (softc->flags & TARG_FLAG_RECEIVE_EOF) != 0)
|
|
|
|
&& (ccbh = TAILQ_FIRST(&softc->rcv_ccb_queue)) != NULL) {
|
|
|
|
|
|
|
|
if (bp == NULL)
|
|
|
|
softc->flags &= ~TARG_FLAG_RECEIVE_EOF;
|
|
|
|
else {
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("De-Queued a RECEIVE buffer %ld\n",
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_bcount));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq = &softc->rcv_bio_queue;
|
1998-09-15 06:36:34 +00:00
|
|
|
pending_queue = &softc->rcv_ccb_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pending_queue != NULL) {
|
|
|
|
/* Process a request */
|
|
|
|
atio = (struct ccb_accept_tio *)ccbh;
|
|
|
|
TAILQ_REMOVE(pending_queue, ccbh, periph_links.tqe);
|
|
|
|
desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
|
|
|
|
desc->bp = bp;
|
|
|
|
if (bp == NULL) {
|
|
|
|
/* EOF */
|
|
|
|
desc->data = NULL;
|
|
|
|
desc->data_increment = 0;
|
|
|
|
desc->data_resid = 0;
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_NONE;
|
|
|
|
} else {
|
2000-04-15 05:54:02 +00:00
|
|
|
bioq_remove(bioq, bp);
|
|
|
|
desc->data = &bp->bio_data[bp->bio_bcount - bp->bio_resid];
|
1998-09-15 06:36:34 +00:00
|
|
|
desc->data_increment =
|
2000-04-15 05:54:02 +00:00
|
|
|
MIN(desc->data_resid, bp->bio_resid);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
2000-07-08 23:24:08 +00:00
|
|
|
("Buffer command: data %p: datacnt %d\n",
|
2000-07-14 19:45:43 +00:00
|
|
|
desc->data, desc->data_increment));
|
1998-09-15 06:36:34 +00:00
|
|
|
TAILQ_INSERT_TAIL(&softc->work_queue, &atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
}
|
2000-07-14 19:45:43 +00:00
|
|
|
atio = (struct ccb_accept_tio *)TAILQ_FIRST(&softc->work_queue);
|
|
|
|
if (atio != NULL) {
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
priority = (atio->ccb_h.flags & CAM_DIS_DISCONNECT) ? 0 : 1;
|
1998-09-15 06:36:34 +00:00
|
|
|
splx(s);
|
2000-07-14 19:45:43 +00:00
|
|
|
xpt_schedule(periph, priority);
|
1998-09-15 06:36:34 +00:00
|
|
|
} else
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
targstart(struct cam_periph *periph, union ccb *start_ccb)
|
|
|
|
{
|
|
|
|
struct targ_softc *softc;
|
|
|
|
struct ccb_hdr *ccbh;
|
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
struct targ_cmd_desc *desc;
|
|
|
|
struct ccb_scsiio *csio;
|
1999-08-16 22:39:25 +00:00
|
|
|
targ_ccb_flags flags;
|
1998-09-15 06:36:34 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
ccbh = TAILQ_FIRST(&softc->work_queue);
|
|
|
|
if (periph->immediate_priority <= periph->pinfo.priority) {
|
1999-08-16 22:39:25 +00:00
|
|
|
start_ccb->ccb_h.ccb_flags = TARG_CCB_WAITING;
|
1998-09-15 06:36:34 +00:00
|
|
|
SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
|
|
|
|
periph_links.sle);
|
|
|
|
periph->immediate_priority = CAM_PRIORITY_NONE;
|
|
|
|
splx(s);
|
|
|
|
wakeup(&periph->ccb_list);
|
|
|
|
} else if (ccbh == NULL) {
|
|
|
|
splx(s);
|
|
|
|
xpt_release_ccb(start_ccb);
|
|
|
|
} else {
|
|
|
|
TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe);
|
|
|
|
splx(s);
|
|
|
|
atio = (struct ccb_accept_tio*)ccbh;
|
|
|
|
desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
|
|
|
|
|
|
|
|
/* Is this a tagged request? */
|
2000-07-17 01:45:51 +00:00
|
|
|
flags = atio->ccb_h.flags &
|
|
|
|
(CAM_DIS_DISCONNECT|CAM_TAG_ACTION_VALID|CAM_DIR_MASK);
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are done with the transaction, tell the
|
|
|
|
* controller to send status and perform a CMD_CMPLT.
|
|
|
|
*/
|
|
|
|
if (desc->data_resid == desc->data_increment)
|
|
|
|
flags |= CAM_SEND_STATUS;
|
|
|
|
|
|
|
|
csio = &start_ccb->csio;
|
|
|
|
cam_fill_ctio(csio,
|
|
|
|
/*retries*/2,
|
|
|
|
targdone,
|
|
|
|
flags,
|
2000-07-14 21:09:25 +00:00
|
|
|
(flags & CAM_TAG_ACTION_VALID)?
|
|
|
|
MSG_SIMPLE_Q_TAG : 0,
|
1998-09-15 06:36:34 +00:00
|
|
|
atio->tag_id,
|
|
|
|
atio->init_id,
|
|
|
|
desc->status,
|
|
|
|
/*data_ptr*/desc->data_increment == 0
|
|
|
|
? NULL : desc->data,
|
|
|
|
/*dxfer_len*/desc->data_increment,
|
|
|
|
/*timeout*/desc->timeout);
|
|
|
|
|
2000-01-25 17:42:27 +00:00
|
|
|
if ((flags & CAM_SEND_STATUS) != 0
|
|
|
|
&& (desc->status == SCSI_STATUS_CHECK_COND
|
|
|
|
|| desc->status == SCSI_STATUS_CMD_TERMINATED)) {
|
|
|
|
struct initiator_state *istate;
|
|
|
|
|
|
|
|
istate = &softc->istate[atio->init_id];
|
|
|
|
csio->sense_len = istate->sense_data.extra_len
|
|
|
|
+ offsetof(struct scsi_sense_data,
|
|
|
|
extra_len);
|
|
|
|
bcopy(&istate->sense_data, &csio->sense_data,
|
|
|
|
csio->sense_len);
|
|
|
|
csio->ccb_h.flags |= CAM_SEND_SENSE;
|
|
|
|
} else {
|
|
|
|
csio->sense_len = 0;
|
|
|
|
}
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
start_ccb->ccb_h.ccb_flags = TARG_CCB_NONE;
|
1998-09-15 06:36:34 +00:00
|
|
|
start_ccb->ccb_h.ccb_atio = atio;
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
2000-07-14 19:45:43 +00:00
|
|
|
("Sending a CTIO (flags 0x%x)\n", csio->ccb_h.flags));
|
1999-08-16 22:39:25 +00:00
|
|
|
TAILQ_INSERT_TAIL(&softc->pending_queue, &csio->ccb_h,
|
|
|
|
periph_links.tqe);
|
1998-09-15 06:36:34 +00:00
|
|
|
xpt_action(start_ccb);
|
2000-07-14 19:45:43 +00:00
|
|
|
/*
|
|
|
|
* If the queue was frozen waiting for the response
|
|
|
|
* to this ATIO (for instance disconnection was disallowed),
|
|
|
|
* then release it now that our response has been queued.
|
|
|
|
*/
|
|
|
|
if ((atio->ccb_h.flags & CAM_DEV_QFRZN) != 0) {
|
|
|
|
cam_release_devq(periph->path,
|
|
|
|
/*relsim_flags*/0,
|
|
|
|
/*reduction*/0,
|
|
|
|
/*timeout*/0,
|
|
|
|
/*getcount_only*/0);
|
|
|
|
atio->ccb_h.flags &= ~CAM_DEV_QFRZN;
|
|
|
|
}
|
1998-09-15 06:36:34 +00:00
|
|
|
s = splbio();
|
|
|
|
ccbh = TAILQ_FIRST(&softc->work_queue);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
if (ccbh != NULL)
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
targdone(struct cam_periph *periph, union ccb *done_ccb)
|
|
|
|
{
|
|
|
|
struct targ_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
if (done_ccb->ccb_h.ccb_flags == TARG_CCB_WAITING) {
|
1998-09-15 06:36:34 +00:00
|
|
|
/* Caller will release the CCB */
|
|
|
|
wakeup(&done_ccb->ccb_h.cbfcnp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-14 19:45:43 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
|
|
|
("targdone %x\n", done_ccb->ccb_h.func_code));
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
switch (done_ccb->ccb_h.func_code) {
|
|
|
|
case XPT_ACCEPT_TARGET_IO:
|
|
|
|
{
|
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
struct targ_cmd_desc *descr;
|
|
|
|
struct initiator_state *istate;
|
|
|
|
u_int8_t *cdb;
|
2000-07-14 19:45:43 +00:00
|
|
|
int priority;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
atio = &done_ccb->atio;
|
|
|
|
descr = (struct targ_cmd_desc*)atio->ccb_h.ccb_descr;
|
|
|
|
istate = &softc->istate[atio->init_id];
|
|
|
|
cdb = atio->cdb_io.cdb_bytes;
|
1998-12-15 08:15:15 +00:00
|
|
|
if (softc->state == TARG_STATE_TEARDOWN
|
|
|
|
|| atio->ccb_h.status == CAM_REQ_ABORTED) {
|
1998-09-15 06:36:34 +00:00
|
|
|
freedescr(descr);
|
|
|
|
free(done_ccb, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-17 01:45:51 +00:00
|
|
|
#ifdef CAMDEBUG
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char dcb[128];
|
|
|
|
for (dcb[0] = 0, i = 0; i < atio->cdb_len; i++) {
|
|
|
|
snprintf(dcb, sizeof dcb,
|
|
|
|
"%s %02x", dcb, cdb[i] & 0xff);
|
|
|
|
}
|
|
|
|
CAM_DEBUG(periph->path,
|
|
|
|
CAM_DEBUG_PERIPH, ("cdb:%s\n", dcb));
|
|
|
|
}
|
|
|
|
#endif
|
2000-01-25 17:42:27 +00:00
|
|
|
if (atio->sense_len != 0) {
|
2000-07-14 19:45:43 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
|
|
|
("ATIO with sense_len\n"));
|
2000-01-25 17:42:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We had an error in the reception of
|
|
|
|
* this command. Immediately issue a CA.
|
|
|
|
*/
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_NONE;
|
|
|
|
descr->data_resid = 0;
|
|
|
|
descr->data_increment = 0;
|
2000-03-18 22:13:27 +00:00
|
|
|
descr->timeout = 5 * 1000;
|
2000-01-25 17:42:27 +00:00
|
|
|
descr->status = SCSI_STATUS_CHECK_COND;
|
|
|
|
copy_sense(softc, istate, (u_int8_t *)&atio->sense_data,
|
|
|
|
atio->sense_len);
|
|
|
|
set_ca_condition(periph, atio->init_id, CA_CMD_SENSE);
|
|
|
|
} else if (istate->pending_ca == 0
|
|
|
|
&& istate->pending_ua != 0
|
|
|
|
&& cdb[0] != INQUIRY) {
|
|
|
|
|
2000-07-14 19:45:43 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
2000-07-17 01:45:51 +00:00
|
|
|
("pending_ca %d pending_ua %d\n",
|
|
|
|
istate->pending_ca, istate->pending_ua));
|
2000-07-14 19:45:43 +00:00
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/* Pending UA, tell initiator */
|
|
|
|
/* Direction is always relative to the initator */
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_NONE;
|
|
|
|
descr->data_resid = 0;
|
|
|
|
descr->data_increment = 0;
|
|
|
|
descr->timeout = 5 * 1000;
|
|
|
|
descr->status = SCSI_STATUS_CHECK_COND;
|
2000-01-25 17:42:27 +00:00
|
|
|
fill_sense(softc, atio->init_id,
|
|
|
|
SSD_CURRENT_ERROR, SSD_KEY_UNIT_ATTENTION,
|
|
|
|
0x29,
|
|
|
|
istate->pending_ua == UA_POWER_ON ? 1 : 2);
|
|
|
|
set_ca_condition(periph, atio->init_id, CA_UNIT_ATTN);
|
|
|
|
} else {
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Save the current CA and UA status so
|
|
|
|
* they can be used by this command.
|
|
|
|
*/
|
|
|
|
ua_types pending_ua;
|
|
|
|
ca_types pending_ca;
|
|
|
|
|
|
|
|
pending_ua = istate->pending_ua;
|
|
|
|
pending_ca = istate->pending_ca;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As per the SCSI2 spec, any command that occurs
|
2000-01-25 17:42:27 +00:00
|
|
|
* after a CA is reported, clears the CA. We must
|
|
|
|
* also clear the UA condition, if any, that caused
|
|
|
|
* the CA to occur assuming the UA is not for a
|
|
|
|
* persistant condition.
|
1998-09-15 06:36:34 +00:00
|
|
|
*/
|
|
|
|
istate->pending_ca = CA_NONE;
|
2000-01-25 17:42:27 +00:00
|
|
|
if (pending_ca == CA_UNIT_ATTN)
|
1998-09-15 06:36:34 +00:00
|
|
|
istate->pending_ua = UA_NONE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the type of incoming command and
|
|
|
|
* setup our buffer for a response.
|
|
|
|
*/
|
|
|
|
switch (cdb[0]) {
|
|
|
|
case INQUIRY:
|
|
|
|
{
|
|
|
|
struct scsi_inquiry *inq;
|
|
|
|
struct scsi_sense_data *sense;
|
|
|
|
|
|
|
|
inq = (struct scsi_inquiry *)cdb;
|
|
|
|
sense = &istate->sense_data;
|
2000-03-18 22:13:27 +00:00
|
|
|
descr->status = SCSI_STATUS_OK;
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Saw an inquiry!\n"));
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Validate the command. We don't
|
|
|
|
* support any VPD pages, so complain
|
|
|
|
* if EVPD is set.
|
|
|
|
*/
|
|
|
|
if ((inq->byte2 & SI_EVPD) != 0
|
|
|
|
|| inq->page_code != 0) {
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_NONE;
|
|
|
|
descr->data_resid = 0;
|
|
|
|
descr->data_increment = 0;
|
2000-03-18 22:13:27 +00:00
|
|
|
descr->timeout = 5 * 1000;
|
1998-09-15 06:36:34 +00:00
|
|
|
descr->status = SCSI_STATUS_CHECK_COND;
|
1999-08-16 22:39:25 +00:00
|
|
|
fill_sense(softc, atio->init_id,
|
1998-09-15 06:36:34 +00:00
|
|
|
SSD_CURRENT_ERROR,
|
|
|
|
SSD_KEY_ILLEGAL_REQUEST,
|
|
|
|
/*asc*/0x24, /*ascq*/0x00);
|
|
|
|
sense->extra_len =
|
|
|
|
offsetof(struct scsi_sense_data,
|
|
|
|
extra_bytes)
|
|
|
|
- offsetof(struct scsi_sense_data,
|
|
|
|
extra_len);
|
2000-01-25 17:42:27 +00:00
|
|
|
set_ca_condition(periph, atio->init_id,
|
|
|
|
CA_CMD_SENSE);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((inq->byte2 & SI_EVPD) != 0) {
|
|
|
|
sense->sense_key_spec[0] =
|
|
|
|
SSD_SCS_VALID|SSD_FIELDPTR_CMD
|
|
|
|
|SSD_BITPTR_VALID| /*bit value*/1;
|
|
|
|
sense->sense_key_spec[1] = 0;
|
|
|
|
sense->sense_key_spec[2] =
|
|
|
|
offsetof(struct scsi_inquiry,
|
|
|
|
byte2);
|
|
|
|
} else if (inq->page_code != 0) {
|
|
|
|
sense->sense_key_spec[0] =
|
|
|
|
SSD_SCS_VALID|SSD_FIELDPTR_CMD;
|
|
|
|
sense->sense_key_spec[1] = 0;
|
|
|
|
sense->sense_key_spec[2] =
|
|
|
|
offsetof(struct scsi_inquiry,
|
|
|
|
page_code);
|
|
|
|
}
|
2000-01-25 17:42:27 +00:00
|
|
|
if (descr->status == SCSI_STATUS_CHECK_COND)
|
|
|
|
break;
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Direction is always relative
|
|
|
|
* to the initator.
|
|
|
|
*/
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_IN;
|
|
|
|
descr->data = softc->inq_data;
|
2000-07-14 19:45:43 +00:00
|
|
|
descr->data_resid =
|
|
|
|
MIN(softc->inq_data_len,
|
|
|
|
SCSI_CDB6_LEN(inq->length));
|
1998-09-15 06:36:34 +00:00
|
|
|
descr->data_increment = descr->data_resid;
|
|
|
|
descr->timeout = 5 * 1000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TEST_UNIT_READY:
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_NONE;
|
|
|
|
descr->data_resid = 0;
|
|
|
|
descr->data_increment = 0;
|
1999-03-05 23:25:11 +00:00
|
|
|
descr->timeout = 5 * 1000;
|
1998-09-15 06:36:34 +00:00
|
|
|
descr->status = SCSI_STATUS_OK;
|
|
|
|
break;
|
|
|
|
case REQUEST_SENSE:
|
|
|
|
{
|
|
|
|
struct scsi_request_sense *rsense;
|
|
|
|
struct scsi_sense_data *sense;
|
|
|
|
|
|
|
|
rsense = (struct scsi_request_sense *)cdb;
|
|
|
|
sense = &istate->sense_data;
|
|
|
|
if (pending_ca == 0) {
|
1999-08-16 22:39:25 +00:00
|
|
|
fill_sense(softc, atio->init_id,
|
|
|
|
SSD_CURRENT_ERROR,
|
1998-09-15 06:36:34 +00:00
|
|
|
SSD_KEY_NO_SENSE, 0x00,
|
|
|
|
0x00);
|
1998-12-10 04:07:42 +00:00
|
|
|
CAM_DEBUG(periph->path,
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("No pending CA!\n"));
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Direction is always relative
|
|
|
|
* to the initator.
|
|
|
|
*/
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_IN;
|
|
|
|
descr->data = sense;
|
|
|
|
descr->data_resid =
|
|
|
|
offsetof(struct scsi_sense_data,
|
|
|
|
extra_len)
|
|
|
|
+ sense->extra_len;
|
2000-07-14 19:45:43 +00:00
|
|
|
descr->data_resid =
|
|
|
|
MIN(descr->data_resid,
|
|
|
|
SCSI_CDB6_LEN(rsense->length));
|
1998-09-15 06:36:34 +00:00
|
|
|
descr->data_increment = descr->data_resid;
|
|
|
|
descr->timeout = 5 * 1000;
|
|
|
|
descr->status = SCSI_STATUS_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RECEIVE:
|
|
|
|
case SEND:
|
|
|
|
{
|
|
|
|
struct scsi_send_receive *sr;
|
|
|
|
|
|
|
|
sr = (struct scsi_send_receive *)cdb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Direction is always relative
|
|
|
|
* to the initator.
|
|
|
|
*/
|
|
|
|
atio->ccb_h.flags &= ~CAM_DIR_MASK;
|
1999-02-11 07:08:58 +00:00
|
|
|
descr->data_resid = scsi_3btoul(sr->xfer_len);
|
|
|
|
descr->timeout = 5 * 1000;
|
|
|
|
descr->status = SCSI_STATUS_OK;
|
1998-09-15 06:36:34 +00:00
|
|
|
if (cdb[0] == SEND) {
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_OUT;
|
1998-12-10 04:07:42 +00:00
|
|
|
CAM_DEBUG(periph->path,
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Saw a SEND!\n"));
|
1998-09-15 06:36:34 +00:00
|
|
|
atio->ccb_h.flags |= CAM_DIR_OUT;
|
|
|
|
TAILQ_INSERT_TAIL(&softc->snd_ccb_queue,
|
|
|
|
&atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
selwakeup(&softc->snd_select);
|
|
|
|
} else {
|
|
|
|
atio->ccb_h.flags |= CAM_DIR_IN;
|
1998-12-10 04:07:42 +00:00
|
|
|
CAM_DEBUG(periph->path,
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Saw a RECEIVE!\n"));
|
1998-09-15 06:36:34 +00:00
|
|
|
TAILQ_INSERT_TAIL(&softc->rcv_ccb_queue,
|
|
|
|
&atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
selwakeup(&softc->rcv_select);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Attempt to satisfy this request with
|
|
|
|
* a user buffer.
|
|
|
|
*/
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Queue for consumption by our userland
|
|
|
|
* counterpart and transition to the exception
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(&softc->unknown_atio_queue,
|
|
|
|
&atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
softc->exceptions |= TARG_EXCEPT_UNKNOWN_ATIO;
|
|
|
|
targfireexception(periph, softc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Queue us up to receive a Continue Target I/O ccb. */
|
2000-07-14 19:45:43 +00:00
|
|
|
if ((atio->ccb_h.flags & CAM_DIS_DISCONNECT) != 0) {
|
|
|
|
TAILQ_INSERT_HEAD(&softc->work_queue, &atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
priority = 0;
|
|
|
|
} else {
|
|
|
|
TAILQ_INSERT_TAIL(&softc->work_queue, &atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
xpt_schedule(periph, priority);
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_CONT_TARGET_IO:
|
|
|
|
{
|
1999-08-16 22:39:25 +00:00
|
|
|
struct ccb_scsiio *csio;
|
1998-09-15 06:36:34 +00:00
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
struct targ_cmd_desc *desc;
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio *bp;
|
1999-08-16 22:39:25 +00:00
|
|
|
int error;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Received completed CTIO\n"));
|
1999-08-16 22:39:25 +00:00
|
|
|
csio = &done_ccb->csio;
|
1998-09-15 06:36:34 +00:00
|
|
|
atio = (struct ccb_accept_tio*)done_ccb->ccb_h.ccb_atio;
|
|
|
|
desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
TAILQ_REMOVE(&softc->pending_queue, &done_ccb->ccb_h,
|
1998-09-15 06:36:34 +00:00
|
|
|
periph_links.tqe);
|
|
|
|
|
1999-03-05 23:25:11 +00:00
|
|
|
if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
|
1999-08-16 22:39:25 +00:00
|
|
|
printf("CCB with error %x\n", done_ccb->ccb_h.status);
|
|
|
|
error = targerror(done_ccb, 0, 0);
|
|
|
|
if (error == ERESTART)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Right now we don't need to do anything
|
|
|
|
* prior to unfreezing the queue...
|
|
|
|
*/
|
|
|
|
if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
|
|
|
|
printf("Releasing Queue\n");
|
|
|
|
cam_release_devq(done_ccb->ccb_h.path,
|
|
|
|
/*relsim_flags*/0,
|
|
|
|
/*reduction*/0,
|
|
|
|
/*timeout*/0,
|
|
|
|
/*getcount_only*/0);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error = 0;
|
2000-01-25 17:42:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we shipped back sense data when completing
|
|
|
|
* this command, clear the pending CA for it.
|
|
|
|
*/
|
|
|
|
if (done_ccb->ccb_h.status & CAM_SENT_SENSE) {
|
|
|
|
struct initiator_state *istate;
|
|
|
|
|
|
|
|
istate = &softc->istate[csio->init_id];
|
|
|
|
if (istate->pending_ca == CA_UNIT_ATTN)
|
|
|
|
istate->pending_ua = UA_NONE;
|
|
|
|
istate->pending_ca = CA_NONE;
|
|
|
|
softc->istate[csio->init_id].pending_ca = CA_NONE;
|
|
|
|
done_ccb->ccb_h.status &= ~CAM_SENT_SENSE;
|
2000-07-14 19:45:43 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
|
|
|
("Sent Sense\n"));
|
2000-01-25 17:42:27 +00:00
|
|
|
}
|
|
|
|
done_ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
desc->data_increment -= csio->resid;
|
1998-09-15 06:36:34 +00:00
|
|
|
desc->data_resid -= desc->data_increment;
|
|
|
|
if ((bp = desc->bp) != NULL) {
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid -= desc->data_increment;
|
|
|
|
bp->bio_error = error;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Buffer I/O Completed - Resid %ld:%d\n",
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid, desc->data_resid));
|
1998-09-15 06:36:34 +00:00
|
|
|
/*
|
|
|
|
* Send the buffer back to the client if
|
|
|
|
* either the command has completed or all
|
|
|
|
* buffer space has been consumed.
|
|
|
|
*/
|
|
|
|
if (desc->data_resid == 0
|
2000-04-15 05:54:02 +00:00
|
|
|
|| bp->bio_resid == 0
|
1999-08-16 22:39:25 +00:00
|
|
|
|| error != 0) {
|
2000-04-15 05:54:02 +00:00
|
|
|
if (bp->bio_resid != 0)
|
1998-09-15 06:36:34 +00:00
|
|
|
/* Short transfer */
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
1998-12-10 04:07:42 +00:00
|
|
|
("Completing a buffer\n"));
|
1998-09-15 06:36:34 +00:00
|
|
|
biodone(bp);
|
|
|
|
desc->bp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xpt_release_ccb(done_ccb);
|
|
|
|
if (softc->state != TARG_STATE_TEARDOWN) {
|
|
|
|
|
|
|
|
if (desc->data_resid == 0) {
|
|
|
|
/*
|
|
|
|
* Send the original accept TIO back to the
|
|
|
|
* controller to handle more work.
|
|
|
|
*/
|
1999-08-16 22:39:25 +00:00
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
2000-07-14 21:09:25 +00:00
|
|
|
("Returning ATIO to target SIM\n"));
|
2000-07-14 19:45:43 +00:00
|
|
|
atio->ccb_h.ccb_flags = TARG_CCB_NONE;
|
1998-09-15 06:36:34 +00:00
|
|
|
xpt_action((union ccb *)atio);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Queue us up for another buffer */
|
|
|
|
if (atio->cdb_io.cdb_bytes[0] == SEND) {
|
1999-01-14 05:57:32 +00:00
|
|
|
if (desc->bp != NULL)
|
|
|
|
TAILQ_INSERT_HEAD(
|
2000-04-15 05:54:02 +00:00
|
|
|
&softc->snd_bio_queue.queue,
|
2000-04-16 06:51:27 +00:00
|
|
|
bp, bio_queue);
|
1998-09-15 06:36:34 +00:00
|
|
|
TAILQ_INSERT_HEAD(&softc->snd_ccb_queue,
|
|
|
|
&atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
} else {
|
1999-01-14 05:57:32 +00:00
|
|
|
if (desc->bp != NULL)
|
|
|
|
TAILQ_INSERT_HEAD(
|
2000-04-15 05:54:02 +00:00
|
|
|
&softc->rcv_bio_queue.queue,
|
2000-04-16 06:51:27 +00:00
|
|
|
bp, bio_queue);
|
1998-09-15 06:36:34 +00:00
|
|
|
TAILQ_INSERT_HEAD(&softc->rcv_ccb_queue,
|
|
|
|
&atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
}
|
|
|
|
desc->bp = NULL;
|
|
|
|
targrunqueue(periph, softc);
|
|
|
|
} else {
|
|
|
|
if (desc->bp != NULL) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_error = ENXIO;
|
1998-09-15 06:36:34 +00:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
freedescr(desc);
|
|
|
|
free(atio, M_DEVBUF);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_IMMED_NOTIFY:
|
|
|
|
{
|
1999-08-16 22:39:25 +00:00
|
|
|
int frozen;
|
|
|
|
|
|
|
|
frozen = (done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
|
|
|
|
if (softc->state == TARG_STATE_TEARDOWN) {
|
|
|
|
SLIST_REMOVE(&softc->immed_notify_slist,
|
2000-05-26 02:09:24 +00:00
|
|
|
&done_ccb->ccb_h, ccb_hdr,
|
1999-08-16 22:39:25 +00:00
|
|
|
periph_links.sle);
|
|
|
|
free(done_ccb, M_DEVBUF);
|
|
|
|
} else if (done_ccb->ccb_h.status == CAM_REQ_ABORTED) {
|
1998-09-15 06:36:34 +00:00
|
|
|
free(done_ccb, M_DEVBUF);
|
1999-08-16 22:39:25 +00:00
|
|
|
} else {
|
|
|
|
printf("Saw event %x:%x\n", done_ccb->ccb_h.status,
|
|
|
|
done_ccb->cin.message_args[0]);
|
|
|
|
/* Process error condition. */
|
|
|
|
targinoterror(periph, softc, &done_ccb->cin);
|
|
|
|
|
|
|
|
/* Requeue for another immediate event */
|
|
|
|
xpt_action(done_ccb);
|
|
|
|
}
|
|
|
|
if (frozen != 0)
|
|
|
|
cam_release_devq(periph->path,
|
|
|
|
/*relsim_flags*/0,
|
|
|
|
/*opening reduction*/0,
|
|
|
|
/*timeout*/0,
|
|
|
|
/*getcount_only*/0);
|
1998-09-15 06:36:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-14 19:45:43 +00:00
|
|
|
case XPT_DEBUG:
|
|
|
|
wakeup(&done_ccb->ccb_h.cbfcnp);
|
|
|
|
break;
|
1999-03-05 23:25:11 +00:00
|
|
|
default:
|
|
|
|
panic("targdone: Impossible xpt opcode %x encountered.",
|
|
|
|
done_ccb->ccb_h.func_code);
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transition to the exception state and notify our symbiotic
|
|
|
|
* userland process of the change.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
targfireexception(struct cam_periph *periph, struct targ_softc *softc)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* return all pending buffers with short read/write status so our
|
|
|
|
* process unblocks, and do a selwakeup on any process queued
|
|
|
|
* waiting for reads or writes. When the selwakeup is performed,
|
|
|
|
* the waking process will wakeup, call our poll routine again,
|
|
|
|
* and pick up the exception.
|
|
|
|
*/
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio *bp;
|
1998-09-15 06:36:34 +00:00
|
|
|
|
|
|
|
if (softc->state != TARG_STATE_NORMAL)
|
|
|
|
/* Already either tearing down or in exception state */
|
|
|
|
return;
|
|
|
|
|
|
|
|
softc->state = TARG_STATE_EXCEPTION;
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
while ((bp = bioq_first(&softc->snd_bio_queue)) != NULL) {
|
|
|
|
bioq_remove(&softc->snd_bio_queue, bp);
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1998-09-15 06:36:34 +00:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
while ((bp = bioq_first(&softc->rcv_bio_queue)) != NULL) {
|
|
|
|
bioq_remove(&softc->snd_bio_queue, bp);
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1998-09-15 06:36:34 +00:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
selwakeup(&softc->snd_select);
|
|
|
|
selwakeup(&softc->rcv_select);
|
|
|
|
}
|
|
|
|
|
1999-08-16 22:39:25 +00:00
|
|
|
static void
|
|
|
|
targinoterror(struct cam_periph *periph, struct targ_softc *softc,
|
|
|
|
struct ccb_immed_notify *inot)
|
|
|
|
{
|
|
|
|
cam_status status;
|
|
|
|
int sense;
|
|
|
|
|
|
|
|
status = inot->ccb_h.status;
|
|
|
|
sense = (status & CAM_AUTOSNS_VALID) != 0;
|
|
|
|
status &= CAM_STATUS_MASK;
|
|
|
|
switch (status) {
|
|
|
|
case CAM_SCSI_BUS_RESET:
|
|
|
|
set_unit_attention_cond(periph, /*init_id*/CAM_TARGET_WILDCARD,
|
|
|
|
UA_BUS_RESET);
|
|
|
|
abort_pending_transactions(periph,
|
|
|
|
/*init_id*/CAM_TARGET_WILDCARD,
|
|
|
|
TARG_TAG_WILDCARD, EINTR,
|
|
|
|
/*to_held_queue*/FALSE);
|
|
|
|
softc->exceptions |= TARG_EXCEPT_BUS_RESET_SEEN;
|
|
|
|
targfireexception(periph, softc);
|
|
|
|
break;
|
|
|
|
case CAM_BDR_SENT:
|
|
|
|
set_unit_attention_cond(periph, /*init_id*/CAM_TARGET_WILDCARD,
|
|
|
|
UA_BDR);
|
|
|
|
abort_pending_transactions(periph, CAM_TARGET_WILDCARD,
|
|
|
|
TARG_TAG_WILDCARD, EINTR,
|
|
|
|
/*to_held_queue*/FALSE);
|
|
|
|
softc->exceptions |= TARG_EXCEPT_BDR_RECEIVED;
|
|
|
|
targfireexception(periph, softc);
|
|
|
|
break;
|
|
|
|
case CAM_MESSAGE_RECV:
|
|
|
|
switch (inot->message_args[0]) {
|
|
|
|
case MSG_INITIATOR_DET_ERR:
|
|
|
|
break;
|
|
|
|
case MSG_ABORT:
|
|
|
|
break;
|
|
|
|
case MSG_BUS_DEV_RESET:
|
|
|
|
break;
|
|
|
|
case MSG_ABORT_TAG:
|
|
|
|
break;
|
|
|
|
case MSG_CLEAR_QUEUE:
|
|
|
|
break;
|
|
|
|
case MSG_TERM_IO_PROC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-15 06:36:34 +00:00
|
|
|
static int
|
|
|
|
targerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
|
|
|
|
{
|
1999-08-16 22:39:25 +00:00
|
|
|
struct cam_periph *periph;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
struct ccb_scsiio *csio;
|
2000-01-25 17:42:27 +00:00
|
|
|
struct initiator_state *istate;
|
1999-08-16 22:39:25 +00:00
|
|
|
cam_status status;
|
|
|
|
int frozen;
|
|
|
|
int sense;
|
|
|
|
int error;
|
|
|
|
int on_held_queue;
|
|
|
|
|
|
|
|
periph = xpt_path_periph(ccb->ccb_h.path);
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
status = ccb->ccb_h.status;
|
|
|
|
sense = (status & CAM_AUTOSNS_VALID) != 0;
|
|
|
|
frozen = (status & CAM_DEV_QFRZN) != 0;
|
|
|
|
status &= CAM_STATUS_MASK;
|
|
|
|
on_held_queue = FALSE;
|
|
|
|
csio = &ccb->csio;
|
2000-01-25 17:42:27 +00:00
|
|
|
istate = &softc->istate[csio->init_id];
|
1999-08-16 22:39:25 +00:00
|
|
|
switch (status) {
|
|
|
|
case CAM_REQ_ABORTED:
|
|
|
|
if ((ccb->ccb_h.ccb_flags & TARG_CCB_ABORT_TO_HELDQ) != 0) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place this CCB into the initiators
|
|
|
|
* 'held' queue until the pending CA is cleared.
|
|
|
|
* If there is no CA pending, reissue immediately.
|
|
|
|
*/
|
|
|
|
if (istate->pending_ca == 0) {
|
|
|
|
ccb->ccb_h.ccb_flags = TARG_CCB_NONE;
|
|
|
|
xpt_action(ccb);
|
|
|
|
} else {
|
|
|
|
ccb->ccb_h.ccb_flags = TARG_CCB_HELDQ;
|
|
|
|
TAILQ_INSERT_TAIL(&softc->pending_queue,
|
|
|
|
&ccb->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
}
|
|
|
|
/* The command will be retried at a later time. */
|
|
|
|
on_held_queue = TRUE;
|
|
|
|
error = ERESTART;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case CAM_SCSI_BUS_RESET:
|
|
|
|
case CAM_BDR_SENT:
|
|
|
|
case CAM_REQ_TERMIO:
|
|
|
|
case CAM_CMD_TIMEOUT:
|
|
|
|
/* Assume we did not send any data */
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
case CAM_SEL_TIMEOUT:
|
|
|
|
if (ccb->ccb_h.retry_count > 0) {
|
|
|
|
ccb->ccb_h.retry_count--;
|
|
|
|
error = ERESTART;
|
|
|
|
} else {
|
|
|
|
/* "Select or reselect failure" */
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
fill_sense(softc, csio->init_id, SSD_CURRENT_ERROR,
|
|
|
|
SSD_KEY_HARDWARE_ERROR, 0x45, 0x00);
|
2000-01-25 17:42:27 +00:00
|
|
|
set_ca_condition(periph, csio->init_id, CA_CMD_SENSE);
|
1999-08-16 22:39:25 +00:00
|
|
|
error = EIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CAM_UNCOR_PARITY:
|
|
|
|
/* "SCSI parity error" */
|
|
|
|
fill_sense(softc, csio->init_id, SSD_CURRENT_ERROR,
|
|
|
|
SSD_KEY_HARDWARE_ERROR, 0x47, 0x00);
|
2000-01-25 17:42:27 +00:00
|
|
|
set_ca_condition(periph, csio->init_id,
|
1999-08-16 22:39:25 +00:00
|
|
|
CA_CMD_SENSE);
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
case CAM_NO_HBA:
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
case CAM_SEQUENCE_FAIL:
|
|
|
|
if (sense != 0) {
|
2000-01-25 17:42:27 +00:00
|
|
|
copy_sense(softc, istate, (u_int8_t *)&csio->sense_data,
|
|
|
|
csio->sense_len);
|
|
|
|
set_ca_condition(periph,
|
1999-08-16 22:39:25 +00:00
|
|
|
csio->init_id,
|
|
|
|
CA_CMD_SENSE);
|
|
|
|
}
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
case CAM_IDE:
|
|
|
|
/* "Initiator detected error message received" */
|
|
|
|
fill_sense(softc, csio->init_id, SSD_CURRENT_ERROR,
|
|
|
|
SSD_KEY_HARDWARE_ERROR, 0x48, 0x00);
|
2000-01-25 17:42:27 +00:00
|
|
|
set_ca_condition(periph, csio->init_id,
|
1999-08-16 22:39:25 +00:00
|
|
|
CA_CMD_SENSE);
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = EIO;
|
|
|
|
break;
|
|
|
|
case CAM_REQUEUE_REQ:
|
|
|
|
printf("Requeue Request!\n");
|
|
|
|
error = ERESTART;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
csio->resid = csio->dxfer_len;
|
|
|
|
error = EIO;
|
|
|
|
panic("targerror: Unexpected status %x encounterd", status);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error == ERESTART || error == 0) {
|
|
|
|
/* Clear the QFRZN flag as we will release the queue */
|
|
|
|
if (frozen != 0)
|
|
|
|
ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
|
|
|
|
|
|
|
|
if (error == ERESTART && !on_held_queue)
|
|
|
|
xpt_action(ccb);
|
|
|
|
|
|
|
|
if (frozen != 0)
|
|
|
|
cam_release_devq(ccb->ccb_h.path,
|
|
|
|
/*relsim_flags*/0,
|
|
|
|
/*opening reduction*/0,
|
|
|
|
/*timeout*/0,
|
|
|
|
/*getcount_only*/0);
|
|
|
|
}
|
|
|
|
return (error);
|
1998-09-15 06:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct targ_cmd_desc*
|
|
|
|
allocdescr()
|
|
|
|
{
|
|
|
|
struct targ_cmd_desc* descr;
|
|
|
|
|
|
|
|
/* Allocate the targ_descr structure */
|
|
|
|
descr = (struct targ_cmd_desc *)malloc(sizeof(*descr),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (descr == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
bzero(descr, sizeof(*descr));
|
|
|
|
|
|
|
|
/* Allocate buffer backing store */
|
|
|
|
descr->backing_store = malloc(MAX_BUF_SIZE, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (descr->backing_store == NULL) {
|
|
|
|
free(descr, M_DEVBUF);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
descr->max_size = MAX_BUF_SIZE;
|
|
|
|
return (descr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freedescr(struct targ_cmd_desc *descr)
|
|
|
|
{
|
1998-12-15 08:15:15 +00:00
|
|
|
free(descr->backing_store, M_DEVBUF);
|
1998-09-15 06:36:34 +00:00
|
|
|
free(descr, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-16 22:39:25 +00:00
|
|
|
fill_sense(struct targ_softc *softc, u_int initiator_id, u_int error_code,
|
|
|
|
u_int sense_key, u_int asc, u_int ascq)
|
1998-09-15 06:36:34 +00:00
|
|
|
{
|
1999-08-16 22:39:25 +00:00
|
|
|
struct initiator_state *istate;
|
|
|
|
struct scsi_sense_data *sense;
|
|
|
|
|
|
|
|
istate = &softc->istate[initiator_id];
|
|
|
|
sense = &istate->sense_data;
|
1998-09-15 06:36:34 +00:00
|
|
|
bzero(sense, sizeof(*sense));
|
|
|
|
sense->error_code = error_code;
|
|
|
|
sense->flags = sense_key;
|
|
|
|
sense->add_sense_code = asc;
|
|
|
|
sense->add_sense_code_qual = ascq;
|
|
|
|
|
|
|
|
sense->extra_len = offsetof(struct scsi_sense_data, fru)
|
|
|
|
- offsetof(struct scsi_sense_data, extra_len);
|
|
|
|
}
|
1999-08-16 22:39:25 +00:00
|
|
|
|
|
|
|
static void
|
2000-01-25 17:42:27 +00:00
|
|
|
copy_sense(struct targ_softc *softc, struct initiator_state *istate,
|
|
|
|
u_int8_t *sense_buffer, size_t sense_len)
|
1999-08-16 22:39:25 +00:00
|
|
|
{
|
|
|
|
struct scsi_sense_data *sense;
|
|
|
|
size_t copylen;
|
|
|
|
|
|
|
|
sense = &istate->sense_data;
|
|
|
|
copylen = sizeof(*sense);
|
2000-01-25 17:42:27 +00:00
|
|
|
if (copylen > sense_len)
|
|
|
|
copylen = sense_len;
|
|
|
|
bcopy(sense_buffer, sense, copylen);
|
1999-08-16 22:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_unit_attention_cond(struct cam_periph *periph,
|
|
|
|
u_int initiator_id, ua_types ua)
|
|
|
|
{
|
|
|
|
int start;
|
|
|
|
int end;
|
|
|
|
struct targ_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
if (initiator_id == CAM_TARGET_WILDCARD) {
|
|
|
|
start = 0;
|
|
|
|
end = MAX_INITIATORS - 1;
|
|
|
|
} else
|
|
|
|
start = end = initiator_id;
|
|
|
|
|
|
|
|
while (start <= end) {
|
|
|
|
softc->istate[start].pending_ua = ua;
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-25 17:42:27 +00:00
|
|
|
set_ca_condition(struct cam_periph *periph, u_int initiator_id, ca_types ca)
|
1999-08-16 22:39:25 +00:00
|
|
|
{
|
|
|
|
struct targ_softc *softc;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
softc->istate[initiator_id].pending_ca = ca;
|
|
|
|
abort_pending_transactions(periph, initiator_id, TARG_TAG_WILDCARD,
|
2000-03-18 22:13:27 +00:00
|
|
|
/*errno*/0, /*to_held_queue*/TRUE);
|
1999-08-16 22:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
abort_pending_transactions(struct cam_periph *periph, u_int initiator_id,
|
|
|
|
u_int tag_id, int errno, int to_held_queue)
|
|
|
|
{
|
|
|
|
struct ccb_abort cab;
|
|
|
|
struct ccb_queue *atio_queues[3];
|
|
|
|
struct targ_softc *softc;
|
|
|
|
struct ccb_hdr *ccbh;
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
softc = (struct targ_softc *)periph->softc;
|
|
|
|
|
|
|
|
atio_queues[0] = &softc->work_queue;
|
|
|
|
atio_queues[1] = &softc->snd_ccb_queue;
|
|
|
|
atio_queues[2] = &softc->rcv_ccb_queue;
|
|
|
|
|
|
|
|
/* First address the ATIOs awaiting resources */
|
|
|
|
for (i = 0; i < (sizeof(atio_queues) / sizeof(*atio_queues)); i++) {
|
|
|
|
struct ccb_queue *atio_queue;
|
|
|
|
|
|
|
|
if (to_held_queue) {
|
|
|
|
/*
|
|
|
|
* The device queue is frozen anyway, so there
|
|
|
|
* is nothing for us to do.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
atio_queue = atio_queues[i];
|
|
|
|
ccbh = TAILQ_FIRST(atio_queue);
|
|
|
|
while (ccbh != NULL) {
|
|
|
|
struct ccb_accept_tio *atio;
|
|
|
|
struct targ_cmd_desc *desc;
|
|
|
|
|
|
|
|
atio = (struct ccb_accept_tio *)ccbh;
|
|
|
|
desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
|
|
|
|
ccbh = TAILQ_NEXT(ccbh, periph_links.tqe);
|
|
|
|
|
|
|
|
/* Only abort the CCBs that match */
|
|
|
|
if ((atio->init_id != initiator_id
|
|
|
|
&& initiator_id != CAM_TARGET_WILDCARD)
|
|
|
|
|| (tag_id != TARG_TAG_WILDCARD
|
|
|
|
&& ((atio->ccb_h.flags & CAM_TAG_ACTION_VALID) == 0
|
|
|
|
|| atio->tag_id != tag_id)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TAILQ_REMOVE(atio_queue, &atio->ccb_h,
|
|
|
|
periph_links.tqe);
|
|
|
|
|
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
|
|
|
("Aborting ATIO\n"));
|
|
|
|
if (desc->bp != NULL) {
|
2000-04-15 05:54:02 +00:00
|
|
|
desc->bp->bio_flags |= BIO_ERROR;
|
1999-08-16 22:39:25 +00:00
|
|
|
if (softc->state != TARG_STATE_TEARDOWN)
|
2000-04-15 05:54:02 +00:00
|
|
|
desc->bp->bio_error = errno;
|
1999-08-16 22:39:25 +00:00
|
|
|
else
|
2000-04-15 05:54:02 +00:00
|
|
|
desc->bp->bio_error = ENXIO;
|
1999-08-16 22:39:25 +00:00
|
|
|
biodone(desc->bp);
|
|
|
|
desc->bp = NULL;
|
|
|
|
}
|
|
|
|
if (softc->state == TARG_STATE_TEARDOWN) {
|
|
|
|
freedescr(desc);
|
|
|
|
free(atio, M_DEVBUF);
|
|
|
|
} else {
|
|
|
|
/* Return the ATIO back to the controller */
|
2000-07-14 19:45:43 +00:00
|
|
|
atio->ccb_h.ccb_flags = TARG_CCB_NONE;
|
1999-08-16 22:39:25 +00:00
|
|
|
xpt_action((union ccb *)atio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ccbh = TAILQ_FIRST(&softc->pending_queue);
|
|
|
|
while (ccbh != NULL) {
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
|
|
|
|
csio = (struct ccb_scsiio *)ccbh;
|
|
|
|
ccbh = TAILQ_NEXT(ccbh, periph_links.tqe);
|
|
|
|
|
|
|
|
/* Only abort the CCBs that match */
|
|
|
|
if ((csio->init_id != initiator_id
|
|
|
|
&& initiator_id != CAM_TARGET_WILDCARD)
|
|
|
|
|| (tag_id != TARG_TAG_WILDCARD
|
|
|
|
&& ((csio->ccb_h.flags & CAM_TAG_ACTION_VALID) == 0
|
|
|
|
|| csio->tag_id != tag_id)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
|
|
|
|
("Aborting CTIO\n"));
|
|
|
|
|
2000-03-18 22:13:27 +00:00
|
|
|
TAILQ_REMOVE(&softc->pending_queue, &csio->ccb_h,
|
1999-08-16 22:39:25 +00:00
|
|
|
periph_links.tqe);
|
|
|
|
|
|
|
|
if (to_held_queue != 0)
|
|
|
|
csio->ccb_h.ccb_flags |= TARG_CCB_ABORT_TO_HELDQ;
|
|
|
|
xpt_setup_ccb(&cab.ccb_h, csio->ccb_h.path, /*priority*/1);
|
|
|
|
cab.abort_ccb = (union ccb *)csio;
|
|
|
|
xpt_action((union ccb *)&cab);
|
|
|
|
if (cab.ccb_h.status != CAM_REQ_CMP) {
|
|
|
|
xpt_print_path(cab.ccb_h.path);
|
|
|
|
printf("Unable to abort CCB. Status %x\n",
|
|
|
|
cab.ccb_h.status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|