From e7c3c38077a7227ad49392f694de953e019f78ad Mon Sep 17 00:00:00 2001 From: mav Date: Fri, 13 Nov 2015 19:48:41 +0000 Subject: [PATCH] MFC r289877: Remove ISP_INTERNAL_TARGET code. We have CTL now, which is real and much more functional then this joke. git-svn-id: svn://svn.freebsd.org/base/stable/10@290790 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/isp/isp_freebsd.c | 886 -------------------------------------- sys/dev/isp/isp_freebsd.h | 12 - 2 files changed, 898 deletions(-) diff --git a/sys/dev/isp/isp_freebsd.c b/sys/dev/isp/isp_freebsd.c index 2b60419f3..c22534272 100644 --- a/sys/dev/isp/isp_freebsd.c +++ b/sys/dev/isp/isp_freebsd.c @@ -68,10 +68,6 @@ static timeout_t isp_ldt; static task_fn_t isp_ldt_task; static void isp_kthread(void *); static void isp_action(struct cam_sim *, union ccb *); -#ifdef ISP_INTERNAL_TARGET -static void isp_target_thread_pi(void *); -static void isp_target_thread_fc(void *); -#endif static int isp_timer_count; static void isp_timer(void *); @@ -159,14 +155,6 @@ isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan) struct isp_spi *spi = ISP_SPI_PC(isp, chan); spi->sim = sim; spi->path = path; -#ifdef ISP_INTERNAL_TARGET - ISP_SET_PC(isp, chan, proc_active, 1); - if (THREAD_CREATE(isp_target_thread_pi, spi, &spi->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) { - ISP_SET_PC(isp, chan, proc_active, 0); - isp_prt(isp, ISP_LOGERR, "cannot create test target thread"); - } - ISP_SPI_PC(isp, chan)->num_threads += 1; -#endif } else { fcparam *fcp = FCPARAM(isp, chan); struct isp_fc *fc = ISP_FC_PC(isp, chan); @@ -205,14 +193,6 @@ isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan) return (ENOMEM); } fc->num_threads += 1; -#ifdef ISP_INTERNAL_TARGET - ISP_SET_PC(isp, chan, proc_active, 1); - if (THREAD_CREATE(isp_target_thread_fc, fc, &fc->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) { - ISP_SET_PC(isp, chan, proc_active, 0); - isp_prt(isp, ISP_LOGERR, "cannot create test target thread"); - } - fc->num_threads += 1; -#endif if (chan > 0) { snprintf(name, sizeof(name), "chan%d", chan); tree = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree), @@ -257,18 +237,6 @@ isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan) return (0); } -static void -isp_detach_internal_target(ispsoftc_t *isp, int chan) -{ -#ifdef ISP_INTERNAL_TARGET - void *wchan; - - ISP_GET_PC(isp, chan, target_proc, wchan); - ISP_SET_PC(isp, chan, proc_active, 0); - wakeup(wchan); -#endif -} - static void isp_detach_chan(ispsoftc_t *isp, int chan) { @@ -293,7 +261,6 @@ isp_detach_chan(ispsoftc_t *isp, int chan) /* Wait for the channel's spawned threads to exit. */ wakeup(isp->isp_osinfo.pc.ptr); - isp_detach_internal_target(isp, chan); while (*num_threads != 0) mtx_sleep(isp, &isp->isp_osinfo.lock, PRIBIO, "isp_reap", 100); } @@ -3598,859 +3565,6 @@ isp_target_mark_aborted_early(ispsoftc_t *isp, tstate_t *tptr, uint32_t tag_id) } } } - - -#ifdef ISP_INTERNAL_TARGET -//#define ISP_SEPARATE_STATUS 1 -#define ISP_MULTI_CCBS 1 -#if defined(ISP_MULTI_CCBS) && !defined(ISP_SEPARATE_STATUS) -#define ISP_SEPARATE_STATUS 1 -#endif - -typedef struct periph_private_data_t { - union ccb *ccb; /* original ATIO or Immediate Notify */ - unsigned long offset; /* current offset */ - int sequence; /* current CTIO sequence */ - int ctio_cnt; /* current # of ctio's outstanding */ - int - status_sent : 1, - on_queue : 1; /* on restart queue */ -} ppd_t; -/* - * Each ATIO we allocate will have periph private data associated with it - * that maintains per-command state. This private to each ATIO. - */ -#define ATIO_PPD(ccb) ((ppd_t *)(((struct ccb_hdr *)ccb)->ppriv_ptr0)) -/* - * Each CTIO we send downstream will get a pointer to the ATIO itself - * so that on completion we can retrieve that pointer. - */ -#define ccb_atio ppriv_ptr1 -#define ccb_inot ppriv_ptr1 - -/* - * Each CTIO we send downstream will contain a sequence number - */ -#define CTIO_SEQ(ccb) ccb->ccb_h.ppriv_field0 - -#define MAX_ISP_TARG_TRANSFER (2 << 20) -#define NISP_TARG_CMDS 64 -#define NISP_TARG_NOTIFIES 64 -#define DISK_SHIFT 9 -#define JUNK_SIZE 256 -#define MULTI_CCB_DATA_LIM 8192 -//#define MULTI_CCB_DATA_CNT 64 -#define MULTI_CCB_DATA_CNT 8 - -extern u_int vm_kmem_size; -static int ca; -static uint32_t disk_size; -static uint8_t *disk_data = NULL; -static uint8_t *junk_data; -static MALLOC_DEFINE(M_ISPTARG, "ISPTARG", "ISP TARGET data"); -struct isptarg_softc { - /* CCBs (CTIOs, ATIOs, INOTs) pending on the controller */ - struct isp_ccbq work_queue; - struct isp_ccbq rework_queue; - struct isp_ccbq running_queue; - struct isp_ccbq inot_queue; - struct cam_periph *periph; - struct cam_path *path; - ispsoftc_t *isp; -}; -static periph_ctor_t isptargctor; -static periph_dtor_t isptargdtor; -static periph_start_t isptargstart; -static periph_init_t isptarginit; -static void isptarg_done(struct cam_periph *, union ccb *); -static void isptargasync(void *, u_int32_t, struct cam_path *, void *); - - -static int isptarg_rwparm(uint8_t *, uint8_t *, uint64_t, uint32_t, uint8_t **, uint32_t *, int *); - -static struct periph_driver isptargdriver = -{ - isptarginit, "isptarg", TAILQ_HEAD_INITIALIZER(isptargdriver.units), 0 -}; - -static void -isptarginit(void) -{ -} - -static void -isptargnotify(ispsoftc_t *isp, union ccb *iccb, struct ccb_immediate_notify *inot) -{ - struct ccb_notify_acknowledge *ack = &iccb->cna2; - - ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, inot->ccb_h.path, "%s: [0x%x] immediate notify for 0x%x from 0x%x status 0x%x arg 0x%x\n", __func__, - inot->tag_id, inot->initiator_id, inot->seq_id, inot->ccb_h.status, inot->arg); - ack->ccb_h.func_code = XPT_NOTIFY_ACKNOWLEDGE; - ack->ccb_h.flags = 0; - ack->ccb_h.retry_count = 0; - ack->ccb_h.cbfcnp = isptarg_done; - ack->ccb_h.timeout = 0; - ack->ccb_h.ccb_inot = inot; - ack->tag_id = inot->tag_id; - ack->seq_id = inot->seq_id; - ack->initiator_id = inot->initiator_id; - xpt_action(iccb); -} - -static void -isptargstart(struct cam_periph *periph, union ccb *iccb) -{ - const uint8_t niliqd[SHORT_INQUIRY_LENGTH] = { - 0x7f, 0x0, 0x5, 0x2, 32, 0, 0, 0x32, - 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ', - 'S', 'C', 'S', 'I', ' ', 'N', 'U', 'L', - 'L', ' ', 'D', 'E', 'V', 'I', 'C', 'E', - '0', '0', '0', '1' - }; - const uint8_t iqd[SHORT_INQUIRY_LENGTH] = { - 0, 0x0, 0x5, 0x2, 32, 0, 0, 0x32, - 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ', - 'S', 'C', 'S', 'I', ' ', 'M', 'E', 'M', - 'O', 'R', 'Y', ' ', 'D', 'I', 'S', 'K', - '0', '0', '0', '1' - }; - int r, i, more = 0, last, is_data_cmd = 0, is_write; - char *queue; - struct isptarg_softc *softc = periph->softc; - struct ccb_scsiio *csio; - lun_id_t return_lun; - struct ccb_accept_tio *atio; - uint8_t *cdb, *ptr, status; - uint8_t *data_ptr; - uint32_t data_len, flags; - struct ccb_hdr *ccbh; - - mtx_assert(periph->sim->mtx, MA_OWNED); - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, iccb->ccb_h.path, "%s: function code 0x%x INOTQ=%c WORKQ=%c REWORKQ=%c\n", __func__, iccb->ccb_h.func_code, - TAILQ_FIRST(&softc->inot_queue)? 'y' : 'n', TAILQ_FIRST(&softc->work_queue)? 'y' : 'n', TAILQ_FIRST(&softc->rework_queue)? 'y' : 'n'); - /* - * Check for immediate notifies first - */ - ccbh = TAILQ_FIRST(&softc->inot_queue); - if (ccbh) { - TAILQ_REMOVE(&softc->inot_queue, ccbh, periph_links.tqe); - if (TAILQ_FIRST(&softc->inot_queue) || TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue)) { - xpt_schedule(periph, 1); - } - isptargnotify(softc->isp, iccb, (struct ccb_immediate_notify *)ccbh); - return; - } - - /* - * Check the rework (continuation) work queue first. - */ - ccbh = TAILQ_FIRST(&softc->rework_queue); - if (ccbh) { - atio = (struct ccb_accept_tio *)ccbh; - TAILQ_REMOVE(&softc->rework_queue, ccbh, periph_links.tqe); - more = TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue); - queue = "rework"; - } else { - ccbh = TAILQ_FIRST(&softc->work_queue); - if (ccbh == NULL) { - xpt_release_ccb(iccb); - return; - } - atio = (struct ccb_accept_tio *)ccbh; - TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe); - more = TAILQ_FIRST(&softc->work_queue) != NULL; - queue = "work"; - } - ATIO_PPD(atio)->on_queue = 0; - - if (atio->tag_id == 0xffffffff || atio->ccb_h.func_code != XPT_ACCEPT_TARGET_IO) { - panic("BAD ATIO"); - } - - data_len = is_write = 0; - data_ptr = NULL; - csio = &iccb->csio; - status = SCSI_STATUS_OK; - flags = CAM_SEND_STATUS; - memset(&atio->sense_data, 0, sizeof (atio->sense_data)); - cdb = atio->cdb_io.cdb_bytes; - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, ccbh->path, "%s: [0x%x] processing ATIO from %s queue initiator 0x%x CDB=0x%x data_offset=%u\n", __func__, atio->tag_id, - queue, atio->init_id, cdb[0], ATIO_PPD(atio)->offset); - - return_lun = XS_LUN(atio); - if (return_lun != 0) { - xpt_print(atio->ccb_h.path, "[0x%x] Non-Zero Lun %d: cdb0=0x%x\n", atio->tag_id, return_lun, cdb[0]); - if (cdb[0] != INQUIRY && cdb[0] != REPORT_LUNS && cdb[0] != REQUEST_SENSE) { - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST; - SDFIXED(atio->sense_data)->add_sense_code = 0x25; /* LOGICAL UNIT NOT SUPPORTED */ - atio->sense_len = SSD_MIN_SIZE; - } - return_lun = CAM_LUN_WILDCARD; - } - - switch (cdb[0]) { - case REQUEST_SENSE: - flags |= CAM_DIR_IN; - data_len = sizeof (atio->sense_data); - junk_data[0] = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_NO_SENSE; - memset(junk_data+1, 0, data_len-1); - if (data_len > cdb[4]) { - data_len = cdb[4]; - } - if (data_len) { - data_ptr = junk_data; - } - break; - case WRITE_6: - case WRITE_10: - case WRITE_12: - case WRITE_16: - is_write = 1; - /* FALLTHROUGH */ - case READ_6: - case READ_10: - case READ_12: - case READ_16: - is_data_cmd = 1; - r = isptarg_rwparm(cdb, disk_data, disk_size, ATIO_PPD(atio)->offset, &data_ptr, &data_len, &last); - if (r != 0) { - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST; - if (r == -1) { - SDFIXED(atio->sense_data)->add_sense_code = 0x21; /* LOGICAL BLOCK ADDRESS OUT OF RANGE */ - } else { - SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */ - } - atio->sense_len = SSD_MIN_SIZE; - } else { -#ifdef ISP_SEPARATE_STATUS - if (last && data_len) { - last = 0; - } -#endif - if (last == 0) { - flags &= ~CAM_SEND_STATUS; - } - if (data_len) { - ATIO_PPD(atio)->offset += data_len; - if (is_write) - flags |= CAM_DIR_OUT; - else - flags |= CAM_DIR_IN; - } else { - flags |= CAM_DIR_NONE; - } - } - break; - case INQUIRY: - flags |= CAM_DIR_IN; - if (cdb[1] || cdb[2] || cdb[3]) { - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION; - SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */ - atio->sense_len = SSD_MIN_SIZE; - break; - } - data_len = sizeof (iqd); - if (data_len > cdb[4]) { - data_len = cdb[4]; - } - if (data_len) { - if (XS_LUN(iccb) != 0) { - memcpy(junk_data, niliqd, sizeof (iqd)); - } else { - memcpy(junk_data, iqd, sizeof (iqd)); - } - data_ptr = junk_data; - } - break; - case TEST_UNIT_READY: - flags |= CAM_DIR_NONE; - if (ca) { - ca = 0; - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION; - SDFIXED(atio->sense_data)->add_sense_code = 0x29; /* POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */ - atio->sense_len = SSD_MIN_SIZE; - } - break; - case SYNCHRONIZE_CACHE: - case START_STOP: - case RESERVE: - case RELEASE: - case VERIFY_10: - flags |= CAM_DIR_NONE; - break; - - case READ_CAPACITY: - flags |= CAM_DIR_IN; - if (cdb[2] || cdb[3] || cdb[4] || cdb[5]) { - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST; - SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */ - atio->sense_len = SSD_MIN_SIZE; - break; - } - if (cdb[8] & 0x1) { /* PMI */ - junk_data[0] = 0xff; - junk_data[1] = 0xff; - junk_data[2] = 0xff; - junk_data[3] = 0xff; - } else { - uint64_t last_blk = (disk_size >> DISK_SHIFT) - 1; - if (last_blk < 0xffffffffULL) { - junk_data[0] = (last_blk >> 24) & 0xff; - junk_data[1] = (last_blk >> 16) & 0xff; - junk_data[2] = (last_blk >> 8) & 0xff; - junk_data[3] = (last_blk) & 0xff; - } else { - junk_data[0] = 0xff; - junk_data[1] = 0xff; - junk_data[2] = 0xff; - junk_data[3] = 0xff; - } - } - junk_data[4] = ((1 << DISK_SHIFT) >> 24) & 0xff; - junk_data[5] = ((1 << DISK_SHIFT) >> 16) & 0xff; - junk_data[6] = ((1 << DISK_SHIFT) >> 8) & 0xff; - junk_data[7] = ((1 << DISK_SHIFT)) & 0xff; - data_ptr = junk_data; - data_len = 8; - break; - case REPORT_LUNS: - flags |= CAM_DIR_IN; - memset(junk_data, 0, JUNK_SIZE); - junk_data[0] = (1 << 3) >> 24; - junk_data[1] = (1 << 3) >> 16; - junk_data[2] = (1 << 3) >> 8; - junk_data[3] = (1 << 3); - ptr = NULL; - for (i = 0; i < 1; i++) { - ptr = &junk_data[8 + (i << 3)]; - if (i >= 256) { - ptr[0] = 0x40 | ((i >> 8) & 0x3f); - } - ptr[1] = i; - } - data_ptr = junk_data; - data_len = (ptr + 8) - junk_data; - break; - - default: - flags |= CAM_DIR_NONE; - status = SCSI_STATUS_CHECK_COND; - SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR; - SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST; - SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */ - atio->sense_len = SSD_MIN_SIZE; - break; - } - - /* - * If we are done with the transaction, tell the - * controller to send status and perform a CMD_CMPLT. - * If we have associated sense data, see if we can - * send that too. - */ - if (status == SCSI_STATUS_CHECK_COND) { - flags |= CAM_SEND_SENSE; - csio->sense_len = atio->sense_len; - csio->sense_data = atio->sense_data; - flags &= ~CAM_DIR_MASK; - data_len = 0; - data_ptr = NULL; - } - cam_fill_ctio(csio, 0, isptarg_done, flags, MSG_SIMPLE_Q_TAG, atio->tag_id, atio->init_id, status, data_ptr, data_len, 30 * hz); - iccb->ccb_h.target_id = atio->ccb_h.target_id; - iccb->ccb_h.target_lun = return_lun; - iccb->ccb_h.ccb_atio = atio; - CTIO_SEQ(iccb) = ATIO_PPD(atio)->sequence++; - ATIO_PPD(atio)->ctio_cnt++; - if (flags & CAM_SEND_STATUS) { - KASSERT((ATIO_PPD(atio)->status_sent == 0), ("we have already sent status for 0x%x in %s", atio->tag_id, __func__)); - ATIO_PPD(atio)->status_sent = 1; - } - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, atio->ccb_h.path, "%s: sending downstream for 0x%x sequence %u len %u flags %x\n", __func__, atio->tag_id, CTIO_SEQ(iccb), data_len, flags); - xpt_action(iccb); - - if ((atio->ccb_h.status & CAM_DEV_QFRZN) != 0) { - cam_release_devq(periph->path, 0, 0, 0, 0); - atio->ccb_h.status &= ~CAM_DEV_QFRZN; - } -#ifdef ISP_MULTI_CCBS - if (is_data_cmd && ATIO_PPD(atio)->status_sent == 0 && ATIO_PPD(atio)->ctio_cnt < MULTI_CCB_DATA_CNT && ATIO_PPD(atio)->on_queue == 0) { - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, atio->ccb_h.path, "%s: more still to do for 0x%x\n", __func__, atio->tag_id); - TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe); - ATIO_PPD(atio)->on_queue = 1; - more = 1; - } -#endif - if (more) { - xpt_schedule(periph, 1); - } -} - -static cam_status -isptargctor(struct cam_periph *periph, void *arg) -{ - struct isptarg_softc *softc; - - softc = (struct isptarg_softc *)arg; - periph->softc = softc; - softc->periph = periph; - softc->path = periph->path; - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__); - return (CAM_REQ_CMP); -} - -static void -isptargdtor(struct cam_periph *periph) -{ - struct isptarg_softc *softc; - softc = (struct isptarg_softc *)periph->softc; - ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__); - softc->periph = NULL; - softc->path = NULL; - periph->softc = NULL; -} - -static void -isptarg_done(struct cam_periph *periph, union ccb *ccb) -{ - struct isptarg_softc *softc; - ispsoftc_t *isp; - uint32_t newoff; - struct ccb_accept_tio *atio; - struct ccb_immediate_notify *inot; - cam_status status; - - softc = (struct isptarg_softc *)periph->softc; - isp = softc->isp; - status = ccb->ccb_h.status & CAM_STATUS_MASK; - - switch (ccb->ccb_h.func_code) { - case XPT_ACCEPT_TARGET_IO: - atio = (struct ccb_accept_tio *) ccb; - ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] ATIO seen in %s\n", atio->tag_id, __func__); - memset(ATIO_PPD(atio), 0, sizeof (ppd_t)); - TAILQ_INSERT_TAIL(&softc->work_queue, &ccb->ccb_h, periph_links.tqe); - ATIO_PPD(atio)->on_queue = 1; - xpt_schedule(periph, 1); - break; - case XPT_IMMEDIATE_NOTIFY: - inot = (struct ccb_immediate_notify *) ccb; - ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] INOT for 0x%x seen in %s\n", inot->tag_id, inot->seq_id, __func__); - TAILQ_INSERT_TAIL(&softc->inot_queue, &ccb->ccb_h, periph_links.tqe); - xpt_schedule(periph, 1); - break; - case XPT_CONT_TARGET_IO: - atio = ccb->ccb_h.ccb_atio; - KASSERT((ATIO_PPD(atio)->ctio_cnt != 0), ("ctio zero when finishing a CTIO")); - ATIO_PPD(atio)->ctio_cnt--; - if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { - switch (ccb->ccb_h.status & CAM_STATUS_MASK) { - case CAM_MESSAGE_RECV: - newoff = (ccb->csio.msg_ptr[3] << 24) | (ccb->csio.msg_ptr[4] << 16) | (ccb->csio.msg_ptr[5] << 8) | (ccb->csio.msg_ptr[6]); - ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "[0x%x] got message to return to reset offset to 0x%x at sequence %u\n", atio->tag_id, newoff, CTIO_SEQ(ccb)); - ATIO_PPD(atio)->offset = newoff; - ATIO_PPD(atio)->status_sent = 0; - if (ATIO_PPD(atio)->on_queue == 0) { - TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe); - ATIO_PPD(atio)->on_queue = 1; - } - xpt_schedule(periph, 1); - break; - default: - cam_error_print(ccb, CAM_ESF_ALL, CAM_EPF_ALL); - xpt_action((union ccb *)atio); - break; - } - } else if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) { - ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] MID CTIO sequence %u seen in %s\n", atio->tag_id, CTIO_SEQ(ccb), __func__); - if (ATIO_PPD(atio)->status_sent == 0 && ATIO_PPD(atio)->on_queue == 0) { - TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe); - ATIO_PPD(atio)->on_queue = 1; - } - xpt_schedule(periph, 1); - } else { - KASSERT((ATIO_PPD(atio)->ctio_cnt == 0), ("ctio count still %d when we think we've sent the STATUS ctio", ATIO_PPD(atio)->ctio_cnt)); - ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] FINAL CTIO sequence %u seen in %s\n", atio->tag_id, CTIO_SEQ(ccb), __func__); - xpt_action((union ccb *)atio); - } - if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { - cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0); - ccb->ccb_h.status &= ~CAM_DEV_QFRZN; - } - xpt_release_ccb(ccb); - break; - case XPT_NOTIFY_ACKNOWLEDGE: - if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { - cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0); - ccb->ccb_h.status &= ~CAM_DEV_QFRZN; - } - inot = ccb->ccb_h.ccb_inot; - ISP_PATH_PRT(isp, ISP_LOGTDEBUG1, inot->ccb_h.path, "[0x%x] recycle notify for tag 0x%x\n", inot->tag_id, inot->seq_id); - xpt_release_ccb(ccb); - xpt_action((union ccb *)inot); - break; - default: - xpt_print(ccb->ccb_h.path, "unexpected code 0x%x\n", ccb->ccb_h.func_code); - break; - } -} - -static void -isptargasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) -{ - struct ac_contract *acp = arg; - struct ac_device_changed *fc = (struct ac_device_changed *) acp->contract_data; - - if (code != AC_CONTRACT) { - return; - } - xpt_print(path, "0x%016llx Port ID 0x%06x %s\n", (unsigned long long) fc->wwpn, fc->port, fc->arrived? "arrived" : "departed"); -} - -static void -isp_target_thread(ispsoftc_t *isp, int chan) -{ - union ccb *ccb = NULL; - int i; - void *wchan; - cam_status status; - struct isptarg_softc *softc = NULL; - struct cam_periph *periph = NULL, *wperiph = NULL; - struct cam_path *path, *wpath; - struct cam_sim *sim; - - if (disk_data == NULL) { - disk_size = roundup2(vm_kmem_size >> 1, (1ULL << 20)); - if (disk_size < (50 << 20)) { - disk_size = 50 << 20; - } - disk_data = malloc(disk_size, M_ISPTARG, M_WAITOK | M_ZERO); - if (disk_data == NULL) { - isp_prt(isp, ISP_LOGERR, "%s: could not allocate disk data", __func__); - goto out; - } - isp_prt(isp, ISP_LOGINFO, "allocated a %ju MiB disk", (uintmax_t) (disk_size >> 20)); - } - junk_data = malloc(JUNK_SIZE, M_ISPTARG, M_WAITOK | M_ZERO); - if (junk_data == NULL) { - isp_prt(isp, ISP_LOGERR, "%s: could not allocate junk", __func__); - goto out; - } - - - softc = malloc(sizeof (*softc), M_ISPTARG, M_WAITOK | M_ZERO); - if (softc == NULL) { - isp_prt(isp, ISP_LOGERR, "%s: could not allocate softc", __func__); - goto out; - } - TAILQ_INIT(&softc->work_queue); - TAILQ_INIT(&softc->rework_queue); - TAILQ_INIT(&softc->running_queue); - TAILQ_INIT(&softc->inot_queue); - softc->isp = isp; - - periphdriver_register(&isptargdriver); - ISP_GET_PC(isp, chan, sim, sim); - ISP_GET_PC(isp, chan, path, path); - status = xpt_create_path(&wpath, NULL, cam_sim_path(sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - if (status != CAM_REQ_CMP) { - isp_prt(isp, ISP_LOGERR, "%s: could not allocate wildcard path", __func__); - return; - } - status = xpt_create_path(&path, NULL, cam_sim_path(sim), 0, 0); - if (status != CAM_REQ_CMP) { - xpt_free_path(wpath); - isp_prt(isp, ISP_LOGERR, "%s: could not allocate path", __func__); - return; - } - - ISP_LOCK(isp); - status = cam_periph_alloc(isptargctor, NULL, isptargdtor, isptargstart, "isptarg", CAM_PERIPH_BIO, wpath, NULL, 0, softc); - if (status != CAM_REQ_CMP) { - ISP_UNLOCK(isp); - isp_prt(isp, ISP_LOGERR, "%s: cam_periph_alloc for wildcard failed", __func__); - goto out; - } - wperiph = cam_periph_find(wpath, "isptarg"); - if (wperiph == NULL) { - ISP_UNLOCK(isp); - isp_prt(isp, ISP_LOGERR, "%s: wildcard periph already allocated but doesn't exist", __func__); - goto out; - } - - status = cam_periph_alloc(isptargctor, NULL, isptargdtor, isptargstart, "isptarg", CAM_PERIPH_BIO, path, NULL, 0, softc); - if (status != CAM_REQ_CMP) { - ISP_UNLOCK(isp); - isp_prt(isp, ISP_LOGERR, "%s: cam_periph_alloc failed", __func__); - goto out; - } - - periph = cam_periph_find(path, "isptarg"); - if (periph == NULL) { - ISP_UNLOCK(isp); - isp_prt(isp, ISP_LOGERR, "%s: periph already allocated but doesn't exist", __func__); - goto out; - } - - status = xpt_register_async(AC_CONTRACT, isptargasync, isp, wpath); - if (status != CAM_REQ_CMP) { - ISP_UNLOCK(isp); - isp_prt(isp, ISP_LOGERR, "%s: xpt_register_async failed", __func__); - goto out; - } - - ISP_UNLOCK(isp); - - ccb = xpt_alloc_ccb(); - - /* - * Make sure role is none. - */ - xpt_setup_ccb(&ccb->ccb_h, periph->path, 10); - ccb->ccb_h.func_code = XPT_SET_SIM_KNOB; - ccb->knob.xport_specific.fc.role = KNOB_ROLE_NONE; - ccb->knob.xport_specific.fc.valid = KNOB_VALID_ROLE; - - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - - /* - * Now enable luns - */ - xpt_setup_ccb(&ccb->ccb_h, periph->path, 10); - ccb->ccb_h.func_code = XPT_EN_LUN; - ccb->cel.enable = 1; - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - if (ccb->ccb_h.status != CAM_REQ_CMP) { - xpt_free_ccb(ccb); - xpt_print(periph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status); - goto out; - } - - xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 10); - ccb->ccb_h.func_code = XPT_EN_LUN; - ccb->cel.enable = 1; - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - if (ccb->ccb_h.status != CAM_REQ_CMP) { - xpt_free_ccb(ccb); - xpt_print(wperiph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status); - goto out; - } - xpt_free_ccb(ccb); - - /* - * Add resources - */ - ISP_GET_PC(isp, chan, target_proc, wchan); - for (i = 0; i < 4; i++) { - ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO); - xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1); - ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO; - ccb->ccb_h.cbfcnp = isptarg_done; - ccb->ccb_h.ppriv_ptr0 = malloc(sizeof (ppd_t), M_ISPTARG, M_WAITOK | M_ZERO); - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - } - for (i = 0; i < NISP_TARG_CMDS; i++) { - ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO); - xpt_setup_ccb(&ccb->ccb_h, periph->path, 1); - ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO; - ccb->ccb_h.cbfcnp = isptarg_done; - ccb->ccb_h.ppriv_ptr0 = malloc(sizeof (ppd_t), M_ISPTARG, M_WAITOK | M_ZERO); - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - } - for (i = 0; i < 4; i++) { - ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO); - xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1); - ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY; - ccb->ccb_h.cbfcnp = isptarg_done; - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - } - for (i = 0; i < NISP_TARG_NOTIFIES; i++) { - ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO); - xpt_setup_ccb(&ccb->ccb_h, periph->path, 1); - ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY; - ccb->ccb_h.cbfcnp = isptarg_done; - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - } - - /* - * Now turn it all back on - */ - xpt_setup_ccb(&ccb->ccb_h, periph->path, 10); - ccb->ccb_h.func_code = XPT_SET_SIM_KNOB; - ccb->knob.xport_specific.fc.valid = KNOB_VALID_ROLE; - ccb->knob.xport_specific.fc.role = KNOB_ROLE_TARGET; - ISP_LOCK(isp); - xpt_action(ccb); - ISP_UNLOCK(isp); - - /* - * Okay, while things are still active, sleep... - */ - ISP_LOCK(isp); - for (;;) { - ISP_GET_PC(isp, chan, proc_active, i); - if (i == 0) { - break; - } - msleep(wchan, &isp->isp_lock, PUSER, "tsnooze", 0); - } - ISP_UNLOCK(isp); - -out: - if (wperiph) { - cam_periph_invalidate(wperiph); - } - if (periph) { - cam_periph_invalidate(periph); - } - if (junk_data) { - free(junk_data, M_ISPTARG); - } - if (disk_data) { - free(disk_data, M_ISPTARG); - } - if (softc) { - free(softc, M_ISPTARG); - } - xpt_free_path(path); - xpt_free_path(wpath); -} - -static void -isp_target_thread_pi(void *arg) -{ - struct isp_spi *pi = arg; - ispsoftc_t *isp = cam_sim_softc(pi->sim); - int chan = cam_sim_bus(pi->sim); - - isp_target_thread(isp, chan); - ISP_SPI_PC(isp, chan)->num_threads -= 1; - kthread_exit(); -} - -static void -isp_target_thread_fc(void *arg) -{ - struct isp_fc *fc = arg; - ispsoftc_t *isp = cam_sim_softc(pi->sim); - int chan = cam_sim_bus(pi->sim); - - isp_target_thread(isp, chan); - ISP_FC_PC(isp, chan)->num_threads -= 1; - kthread_exit(); -} - -static int -isptarg_rwparm(uint8_t *cdb, uint8_t *dp, uint64_t dl, uint32_t offset, uint8_t **kp, uint32_t *tl, int *lp) -{ - uint32_t cnt, curcnt; - uint64_t lba; - - switch (cdb[0]) { - case WRITE_16: - case READ_16: - cnt = (((uint32_t)cdb[10]) << 24) | - (((uint32_t)cdb[11]) << 16) | - (((uint32_t)cdb[12]) << 8) | - ((uint32_t)cdb[13]); - - lba = (((uint64_t)cdb[2]) << 56) | - (((uint64_t)cdb[3]) << 48) | - (((uint64_t)cdb[4]) << 40) | - (((uint64_t)cdb[5]) << 32) | - (((uint64_t)cdb[6]) << 24) | - (((uint64_t)cdb[7]) << 16) | - (((uint64_t)cdb[8]) << 8) | - ((uint64_t)cdb[9]); - break; - case WRITE_12: - case READ_12: - cnt = (((uint32_t)cdb[6]) << 16) | - (((uint32_t)cdb[7]) << 8) | - ((u_int32_t)cdb[8]); - - lba = (((uint32_t)cdb[2]) << 24) | - (((uint32_t)cdb[3]) << 16) | - (((uint32_t)cdb[4]) << 8) | - ((uint32_t)cdb[5]); - break; - case WRITE_10: - case READ_10: - cnt = (((uint32_t)cdb[7]) << 8) | - ((u_int32_t)cdb[8]); - - lba = (((uint32_t)cdb[2]) << 24) | - (((uint32_t)cdb[3]) << 16) | - (((uint32_t)cdb[4]) << 8) | - ((uint32_t)cdb[5]); - break; - case WRITE_6: - case READ_6: - cnt = cdb[4]; - if (cnt == 0) { - cnt = 256; - } - lba = (((uint32_t)cdb[1] & 0x1f) << 16) | - (((uint32_t)cdb[2]) << 8) | - ((uint32_t)cdb[3]); - break; - default: - return (-1); - } - - cnt <<= DISK_SHIFT; - lba <<= DISK_SHIFT; - - if (offset == cnt) { - *lp = 1; - return (0); - } - - if (lba + cnt > dl) { - return (-2); - } - - curcnt = MAX_ISP_TARG_TRANSFER; - if (offset + curcnt >= cnt) { - curcnt = cnt - offset; - *lp = 1; - } else { - *lp = 0; - } -#ifdef ISP_MULTI_CCBS - if (curcnt > MULTI_CCB_DATA_LIM) - curcnt = MULTI_CCB_DATA_LIM; -#endif - *tl = curcnt; - *kp = &dp[lba + offset]; - return (0); -} - -#endif #endif static void diff --git a/sys/dev/isp/isp_freebsd.h b/sys/dev/isp/isp_freebsd.h index 39f4d523a..3e166cf4f 100644 --- a/sys/dev/isp/isp_freebsd.h +++ b/sys/dev/isp/isp_freebsd.h @@ -242,9 +242,6 @@ struct isp_fc { struct isp_nexus *nexus_free_list; uint32_t #ifdef ISP_TARGET_MODE -#ifdef ISP_INTERNAL_TARGET - proc_active : 1, -#endif tm_luns_enabled : 1, tm_enable_defer : 1, tm_enabled : 1, @@ -263,9 +260,6 @@ struct isp_fc { struct task gtask; #ifdef ISP_TARGET_MODE struct tslist lun_hash[LUN_HASH_SIZE]; -#ifdef ISP_INTERNAL_TARGET - struct proc * target_proc; -#endif #if defined(DEBUG) unsigned int inject_lost_data_frame; #endif @@ -278,9 +272,6 @@ struct isp_spi { struct cam_path *path; uint32_t #ifdef ISP_TARGET_MODE -#ifdef ISP_INTERNAL_TARGET - proc_active : 1, -#endif tm_luns_enabled : 1, tm_enable_defer : 1, tm_enabled : 1, @@ -290,9 +281,6 @@ struct isp_spi { iid : 4; #ifdef ISP_TARGET_MODE struct tslist lun_hash[LUN_HASH_SIZE]; -#ifdef ISP_INTERNAL_TARGET - struct proc * target_proc; -#endif #endif int num_threads; }; -- 2.45.0