Lines Matching +full:adc +full:- +full:chan
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2009-2020 Alexander Motin <mav@FreeBSD.org>
5 * Copyright (c) 1997-2009 by Matthew Jacob
51 static const char prom3[] = "Chan %d [%u] PortID 0x%06x Departed because of %s";
54 static void isp_loop_changed(ispsoftc_t *isp, int chan);
77 int chan = arg2;
80 value = FCPARAM(isp, chan)->role;
83 if ((error != 0) || (req->newptr == NULL))
90 old = FCPARAM(isp, chan)->role;
95 /* If nothing has changed -- we are done. */
102 error = isp_control(isp, ISPCTL_CHANGE_ROLE, chan, value);
108 isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan)
110 fcparam *fcp = FCPARAM(isp, chan);
111 struct isp_fc *fc = ISP_FC_PC(isp, chan);
112 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(isp->isp_osinfo.dev);
113 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
122 device_get_unit(isp->isp_dev), &isp->isp_lock,
123 isp->isp_maxcmds, isp->isp_maxcmds, devq);
127 if (xpt_bus_register(sim, isp->isp_dev, chan) != CAM_SUCCESS) {
138 fc->sim = sim;
139 fc->path = path;
140 fc->isp = isp;
141 fc->ready = 1;
142 fcp->isp_use_gft_id = 1;
143 fcp->isp_use_gff_id = 1;
145 callout_init_mtx(&fc->gdt, &isp->isp_lock, 0);
146 TASK_INIT(&fc->gtask, 1, isp_gdt_task, fc);
148 TAILQ_INIT(&fc->waitq);
149 STAILQ_INIT(&fc->ntfree);
151 STAILQ_INSERT_TAIL(&fc->ntfree, &fc->ntpool[i], next);
152 LIST_INIT(&fc->atfree);
153 for (i = ATPDPSIZE-1; i >= 0; i--)
154 LIST_INSERT_HEAD(&fc->atfree, &fc->atpool[i], next);
156 LIST_INIT(&fc->atused[i]);
158 isp_loop_changed(isp, chan);
160 if (kproc_create(isp_kthread, fc, &fc->kproc, 0, 0,
161 "%s_%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
162 xpt_free_path(fc->path);
163 xpt_bus_deregister(cam_sim_path(fc->sim));
164 cam_sim_free(fc->sim, FALSE);
167 fc->num_threads += 1;
168 if (chan > 0) {
169 snprintf(name, sizeof(name), "chan%d", chan);
175 "wwnn", CTLFLAG_RD, &fcp->isp_wwnn,
178 "wwpn", CTLFLAG_RD, &fcp->isp_wwpn,
181 "loop_down_limit", CTLFLAG_RW, &fc->loop_down_limit, 0,
184 "gone_device_time", CTLFLAG_RW, &fc->gone_device_time, 0,
188 "inject_lost_data_frame", CTLFLAG_RW, &fc->inject_lost_data_frame, 0,
193 isp, chan, isp_role_sysctl, "I", "Current role");
195 "speed", CTLFLAG_RD, &fcp->isp_gbspeed, 0,
198 "linkstate", CTLFLAG_RD, &fcp->isp_linkstate, 0,
201 "fwstate", CTLFLAG_RD, &fcp->isp_fwstate, 0,
204 "loopstate", CTLFLAG_RD, &fcp->isp_loopstate, 0,
207 "topo", CTLFLAG_RD, &fcp->isp_topo, 0,
210 "use_gft_id", CTLFLAG_RWTUN, &fcp->isp_use_gft_id, 0,
213 "use_gff_id", CTLFLAG_RWTUN, &fcp->isp_use_gff_id, 0,
216 "fw_version_flash", CTLFLAG_RD, fcp->fw_version_flash, 0,
219 "fw_version_ispfw", CTLFLAG_RD, fcp->fw_version_ispfw, 0,
222 "fw_version_run", CTLFLAG_RD, fcp->fw_version_run, 0,
228 isp_detach_chan(ispsoftc_t *isp, int chan)
230 struct isp_fc *fc = ISP_FC_PC(isp, chan);
232 xpt_free_path(fc->path);
233 xpt_bus_deregister(cam_sim_path(fc->sim));
234 cam_sim_free(fc->sim, FALSE);
238 while (fc->num_threads != 0)
239 mtx_sleep(&fc->num_threads, &isp->isp_lock, PRIBIO, "isp_reap", 0);
245 const char *nu = device_get_nameunit(isp->isp_osinfo.dev);
246 int du = device_get_unit(isp->isp_dev);
247 int chan;
252 isp->isp_osinfo.devq = cam_simq_alloc(isp->isp_maxcmds);
253 if (isp->isp_osinfo.devq == NULL) {
257 for (chan = 0; chan < isp->isp_nchan; chan++) {
258 if (isp_attach_chan(isp, isp->isp_osinfo.devq, chan)) {
263 callout_init_mtx(&isp->isp_osinfo.tmo, &isp->isp_lock, 0);
265 callout_reset(&isp->isp_osinfo.tmo, isp_timer_count, isp_timer, isp);
267 isp->isp_osinfo.cdev = make_dev(&isp_cdevsw, du, UID_ROOT, GID_OPERATOR, 0600, "%s", nu);
268 if (isp->isp_osinfo.cdev) {
269 isp->isp_osinfo.cdev->si_drv1 = isp;
275 isp->isp_osinfo.is_exiting = 1;
276 while (--chan >= 0)
277 isp_detach_chan(isp, chan);
279 cam_simq_free(isp->isp_osinfo.devq);
280 isp->isp_osinfo.devq = NULL;
281 return (-1);
287 int chan;
289 if (isp->isp_osinfo.cdev) {
290 destroy_dev(isp->isp_osinfo.cdev);
291 isp->isp_osinfo.cdev = NULL;
295 isp->isp_osinfo.is_exiting = 1;
296 for (chan = isp->isp_nchan - 1; chan >= 0; chan -= 1)
297 isp_detach_chan(isp, chan);
299 callout_drain(&isp->isp_osinfo.tmo);
300 cam_simq_free(isp->isp_osinfo.devq);
305 isp_freeze_loopdown(ispsoftc_t *isp, int chan)
307 struct isp_fc *fc = ISP_FC_PC(isp, chan);
309 if (fc->sim == NULL)
311 if (fc->simqfrozen == 0) {
313 "Chan %d Freeze simq (loopdown)", chan);
314 fc->simqfrozen = SIMQFRZ_LOOPDOWN;
316 xpt_freeze_simq(fc->sim, 1);
319 "Chan %d Mark simq frozen (loopdown)", chan);
320 fc->simqfrozen |= SIMQFRZ_LOOPDOWN;
325 isp_unfreeze_loopdown(ispsoftc_t *isp, int chan)
327 struct isp_fc *fc = ISP_FC_PC(isp, chan);
329 if (fc->sim == NULL)
331 int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
332 fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
333 if (wasfrozen && fc->simqfrozen == 0) {
335 "Chan %d Release simq", chan);
336 xpt_release_simq(fc->sim, 1);
350 if (isp->isp_rqovf || fc->sim == NULL)
353 xpt_freeze_simq(fc->sim, 1);
354 isp->isp_rqovf = 1;
363 if (!isp->isp_rqovf || fc->sim == NULL)
366 xpt_release_simq(fc->sim, 0);
367 isp->isp_rqovf = 0;
375 int nr, chan, retval = ENOTTY;
377 isp = dev->si_drv1;
382 int olddblev = isp->isp_dblev;
383 isp->isp_dblev = *(int *)addr;
389 chan = *(int *)addr;
390 if (chan < 0 || chan >= isp->isp_nchan) {
391 retval = -ENXIO;
394 *(int *)addr = FCPARAM(isp, chan)->role;
399 chan = nr >> 8;
400 if (chan < 0 || chan >= isp->isp_nchan) {
401 retval = -ENXIO;
410 *(int *)addr = FCPARAM(isp, chan)->role;
411 retval = isp_control(isp, ISPCTL_CHANGE_ROLE, chan, nr);
423 chan = *(intptr_t *)addr;
424 if (chan < 0 || chan >= isp->isp_nchan) {
425 retval = -ENXIO;
429 if (isp_fc_runstate(isp, chan, 5 * 1000000) != LOOP_READY) {
438 chan = *(intptr_t *)addr;
439 if (chan < 0 || chan >= isp->isp_nchan) {
440 retval = -ENXIO;
444 if (isp_control(isp, ISPCTL_SEND_LIP, chan)) {
456 if (ifc->loopid >= MAX_FC_TARG) {
460 lp = &FCPARAM(isp, ifc->chan)->portdb[ifc->loopid];
461 if (lp->state != FC_PORTDB_STATE_NIL) {
462 ifc->role = (lp->prli_word3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
463 ifc->loopid = lp->handle;
464 ifc->portid = lp->portid;
465 ifc->node_wwn = lp->node_wwn;
466 ifc->port_wwn = lp->port_wwn;
476 int chan = hba->fc_channel;
478 if (chan < 0 || chan >= isp->isp_nchan) {
482 hba->fc_fw_major = ISP_FW_MAJORX(isp->isp_fwrev);
483 hba->fc_fw_minor = ISP_FW_MINORX(isp->isp_fwrev);
484 hba->fc_fw_micro = ISP_FW_MICROX(isp->isp_fwrev);
485 hba->fc_nchannels = isp->isp_nchan;
486 hba->fc_nports = MAX_FC_TARG;
487 hba->fc_speed = FCPARAM(isp, hba->fc_channel)->isp_gbspeed;
488 hba->fc_topology = FCPARAM(isp, chan)->isp_topo + 1;
489 hba->fc_loopid = FCPARAM(isp, chan)->isp_loopid;
490 hba->nvram_node_wwn = FCPARAM(isp, chan)->isp_wwnn_nvram;
491 hba->nvram_port_wwn = FCPARAM(isp, chan)->isp_wwpn_nvram;
492 hba->active_node_wwn = FCPARAM(isp, chan)->isp_wwnn;
493 hba->active_port_wwn = FCPARAM(isp, chan)->isp_wwpn;
508 chan = fct->chan;
509 if (chan < 0 || chan >= isp->isp_nchan) {
510 retval = -ENXIO;
515 nphdl = fct->loopid;
517 fcp = FCPARAM(isp, chan);
520 lp = &fcp->portdb[i];
521 if (lp->handle == nphdl) {
533 tmf.tmf_nphdl = lp->handle;
536 tmf.tmf_tidlo = lp->portid;
537 tmf.tmf_tidhi = lp->portid >> 16;
538 tmf.tmf_vpidx = ISP_GET_VPIDX(isp, chan);
539 tmf.tmf_lun[1] = fct->lun & 0xff;
540 if (fct->lun >= 256) {
541 tmf.tmf_lun[0] = 0x40 | (fct->lun >> 8);
543 switch (fct->action) {
574 isp_prt(isp, ISP_LOGERR, "%s: TMF of chan %d error %d",
575 __func__, chan, retval);
583 fcp->sendmarker = 1;
603 ISP_PCMD(ccb) = isp->isp_osinfo.pcmd_free;
605 return (-1);
607 isp->isp_osinfo.pcmd_free = ((struct isp_pcmd *)ISP_PCMD(ccb))->next;
616 PISP_PCMD(ccb)->datalen = 0;
618 PISP_PCMD(ccb)->next = isp->isp_osinfo.pcmd_free;
619 isp->isp_osinfo.pcmd_free = ISP_PCMD(ccb);
648 static void isp_target_mark_aborted_early(ispsoftc_t *, int chan, tstate_t *, uint32_t);
656 SLIST_FOREACH(tptr, &fc->lun_hash[LUN_HASH_FUNC(lun)], next) {
657 if (tptr->ts_lun == lun)
669 if (STAILQ_EMPTY(&tptr->restart_queue))
672 STAILQ_CONCAT(&rq, &tptr->restart_queue);
677 ((at7_entry_t *)ntp->data)->at_rxid);
678 isp_handle_platform_atio7(isp, (at7_entry_t *) ntp->data);
680 if (!STAILQ_EMPTY(&tptr->restart_queue))
684 STAILQ_CONCAT(&rq, &tptr->restart_queue);
685 STAILQ_CONCAT(&tptr->restart_queue, &rq);
687 return (!STAILQ_EMPTY(&tptr->restart_queue));
698 for (bus = 0; bus < isp->isp_nchan; bus++) {
701 SLIST_FOREACH(tptr, &fc->lun_hash[i], next)
708 ccb = (union ccb *)TAILQ_FIRST(&fc->waitq);
710 TAILQ_REMOVE(&fc->waitq, &ccb->ccb_h, sim_links.tqe);
719 isp_get_atpd(ispsoftc_t *isp, int chan, uint32_t tag, void *ccb)
721 struct isp_fc *fc = ISP_FC_PC(isp, chan);
724 atp = LIST_FIRST(&fc->atfree);
727 atp->ccb = ccb;
728 atp->tag = tag;
729 LIST_INSERT_HEAD(&fc->atused[ATPDPHASH(tag)], atp, next);
735 isp_find_atpd(ispsoftc_t *isp, int chan, uint32_t tag)
737 struct isp_fc *fc = ISP_FC_PC(isp, chan);
740 LIST_FOREACH(atp, &fc->atused[ATPDPHASH(tag)], next) {
741 if (atp->tag == tag)
752 isp_find_atpd_ccb(ispsoftc_t *isp, int chan, uint32_t tag, void *ccb)
754 struct isp_fc *fc = ISP_FC_PC(isp, chan);
757 LIST_FOREACH(atp, &fc->atused[ATPDPHASH(tag)], next) {
758 if (atp->tag == tag && atp->ccb == ccb)
765 isp_put_atpd(ispsoftc_t *isp, int chan, atio_private_data_t *atp)
767 struct isp_fc *fc = ISP_FC_PC(isp, chan);
769 if (atp->ests)
770 isp_put_ecmd(isp, atp->ests);
773 LIST_INSERT_HEAD(&fc->atfree, atp, next);
777 isp_dump_atpd(ispsoftc_t *isp, int chan)
779 struct isp_fc *fc = ISP_FC_PC(isp, chan);
783 for (atp = fc->atpool; atp < &fc->atpool[ATPDPSIZE]; atp++) {
784 if (atp->state == ATPD_STATE_FREE)
786 isp_prt(isp, ISP_LOGALL, "Chan %d ATP [0x%x] origdlen %u bytes_xfrd %u lun %jx nphdl 0x%04x s_id 0x%06x d_id 0x%06x oxid 0x%04x state %s",
787 chan, atp->tag, atp->orig_datalen, atp->bytes_xfered, (uintmax_t)atp->lun, atp->nphdl, atp->sid, atp->did, atp->oxid, states[atp->state & 0x7]);
792 isp_get_ntpd(ispsoftc_t *isp, int chan)
794 struct isp_fc *fc = ISP_FC_PC(isp, chan);
797 ntp = STAILQ_FIRST(&fc->ntfree);
799 STAILQ_REMOVE_HEAD(&fc->ntfree, next);
804 isp_find_ntpd(ispsoftc_t *isp, int chan, uint32_t tag_id, uint32_t seq_id)
806 struct isp_fc *fc = ISP_FC_PC(isp, chan);
809 for (ntp = fc->ntpool; ntp < &fc->ntpool[ATPDPSIZE]; ntp++) {
810 if (ntp->tag_id == tag_id && ntp->seq_id == seq_id)
817 isp_put_ntpd(ispsoftc_t *isp, int chan, inot_private_data_t *ntp)
819 struct isp_fc *fc = ISP_FC_PC(isp, chan);
821 ntp->tag_id = ntp->seq_id = 0;
822 STAILQ_INSERT_HEAD(&fc->ntfree, ntp, next);
836 tptr->ts_lun = lun;
837 SLIST_INIT(&tptr->atios);
838 SLIST_INIT(&tptr->inots);
839 STAILQ_INIT(&tptr->restart_queue);
840 SLIST_INSERT_HEAD(&fc->lun_hash[LUN_HASH_FUNC(lun)], tptr, next);
852 while ((ccb = (union ccb *)SLIST_FIRST(&tptr->atios)) != NULL) {
853 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
854 ccb->ccb_h.status = CAM_REQ_ABORTED;
857 while ((ccb = (union ccb *)SLIST_FIRST(&tptr->inots)) != NULL) {
858 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
859 ccb->ccb_h.status = CAM_REQ_ABORTED;
862 while ((ntp = STAILQ_FIRST(&tptr->restart_queue)) != NULL) {
863 isp_endcmd(isp, ntp->data, NIL_HANDLE, bus, SCSI_STATUS_BUSY, 0);
864 STAILQ_REMOVE_HEAD(&tptr->restart_queue, next);
867 SLIST_REMOVE(&fc->lun_hash[LUN_HASH_FUNC(tptr->ts_lun)], tptr, tstate, next);
876 target_id_t target = ccb->ccb_h.target_id;
877 lun_id_t lun = ccb->ccb_h.target_lun;
881 * or target and lun both non-wildcard.
883 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0|ISP_LOGCONFIG, ccb->ccb_h.path,
886 ccb->ccb_h.status = CAM_LUN_INVALID;
894 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
898 tptr = create_lun_state(isp, bus, ccb->ccb_h.path);
900 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
905 ccb->ccb_h.status = CAM_REQ_CMP;
914 target_id_t target = ccb->ccb_h.target_id;
915 lun_id_t lun = ccb->ccb_h.target_lun;
917 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0|ISP_LOGCONFIG, ccb->ccb_h.path,
920 ccb->ccb_h.status = CAM_LUN_INVALID;
927 ccb->ccb_h.status = CAM_PATH_INVALID;
933 ccb->ccb_h.status = CAM_REQ_CMP;
948 isp_prt(isp, ISP_LOGTDEBUG0, "%s: ENTRY[0x%x] how %u xfrlen %u sendstatus %d sense_len %u", __func__, ccb->csio.tag_id, how, ccb->csio.dxfer_len,
949 (ccb->ccb_h.flags & CAM_SEND_STATUS) != 0, ((ccb->ccb_h.flags & CAM_SEND_SENSE)? ccb->csio.sense_len : 0));
951 waitq = &ISP_FC_PC(isp, XS_CHANNEL(ccb))->waitq;
957 TAILQ_INSERT_TAIL(waitq, &ccb->ccb_h, sim_links.tqe);
962 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
967 TAILQ_REMOVE(waitq, &ccb->ccb_h, sim_links.tqe);
969 cso = &ccb->csio;
970 xfrlen = cso->dxfer_len;
972 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
973 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "a data transfer length of zero but no status to send is wrong\n");
974 ccb->ccb_h.status = CAM_REQ_INVALID;
980 atp = isp_find_atpd(isp, XS_CHANNEL(ccb), cso->tag_id);
982 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] cannot find private data adjunct in %s", __func__, cso->tag_id, __func__);
984 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
992 if (atp->dead) {
993 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] not sending a CTIO for a dead command", __func__, cso->tag_id);
994 ccb->ccb_h.status = CAM_REQ_ABORTED;
1003 if ((fcp->role & ISP_ROLE_TARGET) == 0) {
1004 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] stopping sending a CTIO because we're no longer in target mode", __func__, cso->tag_id);
1005 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1014 if (atp->ctcnt >= ATPD_CCB_OUTSTANDING) {
1015 isp_prt(isp, ISP_LOGTINFO, "[0x%x] handling only %d CCBs at a time (flags for this ccb: 0x%x)", cso->tag_id, ATPD_CCB_OUTSTANDING, ccb->ccb_h.flags);
1016 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
1021 * Does the initiator expect FC-Tape style responses?
1023 if ((atp->word3 & PRLI_WD3_RETRY) && fcp->fctape_enabled) {
1033 if (atp->sendst) {
1035 cso->tag_id, atp->orig_datalen, atp->bytes_xfered, atp->bytes_in_transit);
1037 atp->sendst = 0;
1039 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1045 if (ccb->ccb_h.flags & CAM_SEND_SENSE) {
1052 sense_length = cso->sense_len;
1057 if (sense_length > (XCMD_SIZE - MIN_FCP_RESPONSE_SIZE)) {
1058 sense_length = XCMD_SIZE - MIN_FCP_RESPONSE_SIZE;
1067 tmp = atp->bytes_xfered + atp->bytes_in_transit;
1068 if (xfrlen > 0 && tmp > atp->orig_datalen) {
1071 cso->tag_id, tmp + xfrlen - atp->orig_datalen);
1072 ccb->ccb_h.status = CAM_DATA_RUN_ERR;
1076 if (xfrlen > atp->orig_datalen - tmp) {
1077 xfrlen = atp->orig_datalen - tmp;
1079 cso->resid = cso->dxfer_len;
1080 ccb->ccb_h.status = CAM_REQ_CMP;
1087 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
1088 cto->ct_header.rqs_entry_count = 1;
1089 cto->ct_header.rqs_seqno |= ATPD_SEQ_NOTIFY_CAM;
1091 cto->ct_nphdl = atp->nphdl;
1092 cto->ct_rxid = atp->tag;
1093 cto->ct_iid_lo = atp->sid;
1094 cto->ct_iid_hi = atp->sid >> 16;
1095 cto->ct_oxid = atp->oxid;
1096 cto->ct_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(ccb));
1097 cto->ct_timeout = XS_TIME(ccb);
1098 cto->ct_flags = atp->tattr << CT7_TASK_ATTR_SHIFT;
1109 cto->ct_flags |= CT7_SENDSTATUS | CT7_NO_DATA;
1110 resid = atp->orig_datalen - atp->bytes_xfered - atp->bytes_in_transit;
1112 cto->ct_flags |= CT7_FLAG_MODE1;
1113 cto->ct_scsi_status = cso->scsi_status;
1115 cto->ct_resid = -resid;
1116 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
1118 cto->ct_resid = resid;
1119 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
1122 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1125 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
1126 cto->rsp.m1.ct_resplen = cto->ct_senselen = sense_length;
1127 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, sense_length);
1133 if (atp->ests == NULL) {
1134 atp->ests = isp_get_ecmd(isp);
1135 if (atp->ests == NULL) {
1136 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
1142 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1145 cto->ct_flags |= CT7_FLAG_MODE2;
1146 rp.fcp_rsp_scsi_status = cso->scsi_status;
1148 rp.fcp_rsp_resid = -resid;
1156 cto->ct_senselen = sense_length;
1158 isp_put_fcp_rsp_iu(isp, &rp, atp->ests);
1159 memcpy(((fcp_rsp_iu_t *)atp->ests)->fcp_rsp_extra, &cso->sense_data, sense_length);
1161 isp_put_fcp_rsp_iu(isp, &rp, atp->ests);
1163 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
1164 isp_print_bytes(isp, "FCP Response Frame After Swizzling", MIN_FCP_RESPONSE_SIZE + sense_length, atp->ests);
1166 bus_dmamap_sync(isp->isp_osinfo.ecmd_dmat, isp->isp_osinfo.ecmd_map, BUS_DMASYNC_PREWRITE);
1167 addr = isp->isp_osinfo.ecmd_dma;
1168 addr += ((((isp_ecmd_t *)atp->ests) - isp->isp_osinfo.ecmd_base) * XCMD_SIZE);
1169 isp_prt(isp, ISP_LOGTDEBUG0, "%s: ests base %p vaddr %p ecmd_dma %jx addr %jx len %u", __func__, isp->isp_osinfo.ecmd_base, atp->ests,
1170 (uintmax_t) isp->isp_osinfo.ecmd_dma, (uintmax_t)addr, MIN_FCP_RESPONSE_SIZE + sense_length);
1171 cto->rsp.m2.ct_datalen = MIN_FCP_RESPONSE_SIZE + sense_length;
1172 cto->rsp.m2.ct_fcp_rsp_iudata.ds_base = DMA_LO32(addr);
1173 cto->rsp.m2.ct_fcp_rsp_iudata.ds_basehi = DMA_HI32(addr);
1174 cto->rsp.m2.ct_fcp_rsp_iudata.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
1178 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid, sense_length,
1179 cso->sense_data.error_code, cso->sense_data.sense_buf[1], cso->sense_data.sense_buf[11], cso->sense_data.sense_buf[12]);
1182 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid);
1184 atp->state = ATPD_STATE_LAST_CTIO;
1191 cto->ct_flags |= CT7_FLAG_MODE0;
1192 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1193 cto->ct_flags |= CT7_DATA_IN;
1195 cto->ct_flags |= CT7_DATA_OUT;
1198 cto->rsp.m0.reloff = atp->bytes_xfered + atp->bytes_in_transit;
1199 cto->rsp.m0.ct_xfrlen = xfrlen;
1202 if (ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame && xfrlen > ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame) {
1203 isp_prt(isp, ISP_LOGWARN, "%s: truncating data frame with xfrlen %d to %d", __func__, xfrlen, xfrlen - (xfrlen >> 2));
1204 ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame = 0;
1205 cto->rsp.m0.ct_xfrlen -= xfrlen >> 2;
1209 resid = atp->orig_datalen - atp->bytes_xfered - xfrlen;
1210 if (cso->scsi_status == SCSI_STATUS_OK && resid == 0 /* && fctape == 0 */) {
1211 cto->ct_flags |= CT7_SENDSTATUS;
1212 atp->state = ATPD_STATE_LAST_CTIO;
1214 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1217 atp->sendst = 1; /* send status later */
1218 cto->ct_header.rqs_seqno &= ~ATPD_SEQ_NOTIFY_CAM;
1219 atp->state = ATPD_STATE_CTIO;
1222 atp->state = ATPD_STATE_CTIO;
1225 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cto->ct_scsi_status, cto->ct_flags, xfrlen, atp->bytes_xfered);
1229 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "out of PCMDs\n");
1230 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
1235 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "No XFLIST pointers for %s\n", __func__);
1236 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
1240 atp->bytes_in_transit += xfrlen;
1241 PISP_PCMD(ccb)->datalen = xfrlen;
1251 cto->ct_syshandle = handle;
1257 TAILQ_INSERT_HEAD(waitq, &ccb->ccb_h, sim_links.tqe);
1260 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1264 ccb->ccb_h.status = CAM_REQ_INPROG | CAM_SIM_QUEUED;
1266 ccb->ccb_h.spriv_field0 = atp->bytes_xfered;
1268 ccb->ccb_h.spriv_field0 = ~0;
1270 atp->ctcnt++;
1271 atp->seqno++;
1279 ispsoftc_t *isp = tp->isp;
1282 if (isp_notify_ack(isp, tp->not)) {
1283 callout_schedule(&tp->timer, 5);
1295 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1304 uint16_t chan, nphdl = NIL_HANDLE;
1313 did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2];
1314 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
1315 lun = CAM_EXTLUN_BYTE_SWIZZLE(be64dec(aep->at_cmnd.fcp_cmnd_lun));
1317 if (ISP_CAP_MULTI_ID(isp) && isp->isp_nchan > 1) {
1319 isp_find_chan_by_did(isp, did, &chan);
1320 if (chan == ISP_NOCHAN) {
1323 __func__, aep->at_rxid, did);
1329 chan = 0;
1335 if (isp_find_pdb_by_portid(isp, chan, sid, &lp) == 0) {
1339 isp_prt(isp, ISP_LOGTINFO, "%s: [RX_ID 0x%x] D_ID 0x%06x found on Chan %d for S_ID 0x%06x wasn't in PDB already",
1340 __func__, aep->at_rxid, did, chan, sid);
1341 isp_dump_portdb(isp, chan);
1342 isp_endcmd(isp, aep, NIL_HANDLE, chan, ECMD_TERMINATE, 0);
1345 nphdl = lp->handle;
1350 tptr = get_lun_statep(isp, chan, lun);
1352 tptr = get_lun_statep(isp, chan, CAM_LUN_WILDCARD);
1356 __func__, aep->at_rxid, (uintmax_t)lun);
1358 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
1360 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
1369 if (isp_atio_restart(isp, chan, tptr))
1375 if (aep->at_rxid == AT7_NORESRC_RXID) {
1376 isp_endcmd(isp, aep, nphdl, chan, SCSI_BUSY, 0);
1383 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1385 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atios", aep->at_rxid);
1389 oatp = isp_find_atpd(isp, chan, aep->at_rxid);
1391 isp_prt(isp, oatp->state == ATPD_STATE_LAST_CTIO ? ISP_LOGTDEBUG0 :
1392 ISP_LOGWARN, "[0x%x] tag wraparound (N-Port Handle "
1394 aep->at_rxid, nphdl, sid, aep->at_hdr.ox_id, oatp->state);
1396 * It's not a "no resource" condition- but we can treat it like one
1400 atp = isp_get_atpd(isp, chan, aep->at_rxid, atiop);
1402 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atps", aep->at_rxid);
1403 isp_endcmd(isp, aep, nphdl, chan, SCSI_BUSY, 0);
1406 atp->word3 = lp->prli_word3;
1407 atp->state = ATPD_STATE_ATIO;
1408 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1409 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, atiop->ccb_h.path, "Take FREE ATIO\n");
1410 atiop->init_id = FC_PORTDB_TGT(isp, chan, lp);
1411 atiop->ccb_h.target_id = ISP_MAX_TARGETS(isp);
1412 atiop->ccb_h.target_lun = lun;
1413 atiop->sense_len = 0;
1414 cdbxlen = aep->at_cmnd.fcp_cmnd_alen_datadir >> FCP_CMND_ADDTL_CDBLEN_SHIFT;
1418 cdbxlen = sizeof (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_cdb);
1419 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cmnd.cdb_dl.sf.fcp_cmnd_cdb, cdbxlen);
1420 atiop->cdb_len = cdbxlen;
1421 atiop->ccb_h.status = CAM_CDB_RECVD;
1422 atiop->tag_id = atp->tag;
1423 switch (aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK) {
1425 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
1426 atiop->tag_action = MSG_SIMPLE_TASK;
1429 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
1430 atiop->tag_action = MSG_HEAD_OF_QUEUE_TASK;
1433 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
1434 atiop->tag_action = MSG_ORDERED_TASK;
1437 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
1438 atiop->tag_action = MSG_ACA_TASK;
1442 atiop->tag_action = 0;
1445 atiop->priority = (aep->at_cmnd.fcp_cmnd_task_attribute &
1447 atp->orig_datalen = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
1448 atp->bytes_xfered = 0;
1449 atp->lun = lun;
1450 atp->nphdl = nphdl;
1451 atp->sid = sid;
1452 atp->did = did;
1453 atp->oxid = aep->at_hdr.ox_id;
1454 atp->rxid = aep->at_hdr.rx_id;
1455 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
1456 atp->tattr = aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK;
1457 atp->state = ATPD_STATE_CAM;
1459 aep->at_rxid, atp->cdb0, (uintmax_t)lun, atp->orig_datalen);
1464 ntp = isp_get_ntpd(isp, chan);
1466 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
1469 memcpy(ntp->data, aep, QENTRY_LEN);
1470 STAILQ_INSERT_TAIL(&tptr->restart_queue, ntp, next);
1487 inot = (in_fcentry_24xx_t *)atp->srr;
1488 srr_off = inot->in_srr_reloff_lo | (inot->in_srr_reloff_hi << 16);
1489 ccb = atp->srr_ccb;
1490 atp->srr_ccb = NULL;
1491 atp->nsrr++;
1493 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] null ccb", atp->tag);
1497 ccb_off = ccb->ccb_h.spriv_field0;
1498 ccb_len = ccb->csio.dxfer_len;
1501 switch (inot->in_srr_iu) {
1506 atp->sendst = 0;
1507 atp->bytes_xfered = srr_off;
1509 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] SRR offset 0x%x but current CCB doesn't transfer data", atp->tag, srr_off);
1513 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] SRR offset 0x%x not covered by current CCB data range [0x%x..0x%x]", atp->tag, srr_off, ccb_off, ccb_end);
1516 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] SRR offset 0x%x covered by current CCB data range [0x%x..0x%x]", atp->tag, srr_off, ccb_off, ccb_end);
1519 isp_prt(isp, ISP_LOGTINFO, "SRR[0x%x] Got an FCP RSP SRR- resending status", atp->tag);
1520 atp->sendst = 1;
1529 isp_prt(isp, ISP_LOGWARN, "Got an FCP DATA IN SRR- dropping");
1533 isp_prt(isp, ISP_LOGWARN, "Got an unknown information (%x) SRR- dropping", inot->in_srr_iu);
1543 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
1549 inot->in_reserved = 1;
1551 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1552 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
1557 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
1560 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1561 ccb->ccb_h.status |= CAM_MESSAGE_RECV;
1565 ccb->csio.msg_ptr = &ccb->csio.sense_data.sense_buf[SSD_FULL_SIZE - 16];
1566 ccb->csio.msg_len = 7;
1567 ccb->csio.msg_ptr[0] = MSG_EXTENDED;
1568 ccb->csio.msg_ptr[1] = 5;
1569 ccb->csio.msg_ptr[2] = 0; /* modify data pointer */
1570 ccb->csio.msg_ptr[3] = srr_off >> 24;
1571 ccb->csio.msg_ptr[4] = srr_off >> 16;
1572 ccb->csio.msg_ptr[5] = srr_off >> 8;
1573 ccb->csio.msg_ptr[6] = srr_off;
1581 in_fcentry_24xx_t *inot = notify->nt_lreserved;
1583 uint32_t tag = notify->nt_tagval & 0xffffffff;
1585 atp = isp_find_atpd(isp, notify->nt_channel, tag);
1592 atp->srr_notify_rcvd = 1;
1593 memcpy(atp->srr, inot, sizeof (atp->srr));
1595 inot->in_rxid, inot->in_flags, inot->in_srr_iu,
1596 ((uint32_t)inot->in_srr_reloff_hi << 16) | inot->in_srr_reloff_lo);
1597 if (atp->srr_ccb)
1610 handle = ct->ct_syshandle;
1617 resid = data_requested = PISP_PCMD(ccb)->datalen;
1621 atp = isp_find_atpd(isp, bus, ct->ct_rxid);
1628 atp = isp_find_atpd(isp, bus, ccb->csio.tag_id);
1631 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x after I/O", __func__, ccb->csio.tag_id);
1634 KASSERT((atp->ctcnt > 0), ("ctio count not greater than zero"));
1635 atp->bytes_in_transit -= data_requested;
1636 atp->ctcnt -= 1;
1637 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1639 if (ct->ct_nphdl == CT7_SRR) {
1640 atp->srr_ccb = ccb;
1641 if (atp->srr_notify_rcvd)
1645 if (ct->ct_nphdl == CT_HBA_RESET) {
1646 sentstatus = (ccb->ccb_h.flags & CAM_SEND_STATUS) &&
1647 (atp->sendst == 0);
1650 sentstatus = ct->ct_flags & CT7_SENDSTATUS;
1651 ok = (ct->ct_nphdl == CT7_OK);
1652 notify_cam = (ct->ct_header.rqs_seqno & ATPD_SEQ_NOTIFY_CAM) != 0;
1653 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA)
1654 resid = ct->ct_resid;
1656 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO7[%x] seq %u nc %d sts 0x%x flg 0x%x sns %d resid %d %s", __func__, ct->ct_rxid, ATPD_GET_SEQNO(ct),
1657 notify_cam, ct->ct_nphdl, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
1660 atp->bytes_xfered += data_requested - resid;
1661 ccb->csio.resid = ccb->csio.dxfer_len -
1662 (data_requested - resid);
1664 if (sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE))
1665 ccb->ccb_h.status |= CAM_SENT_SENSE;
1666 ccb->ccb_h.status |= CAM_REQ_CMP;
1670 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
1672 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
1674 atp->state = ATPD_STATE_PDON;
1681 (sentstatus)? " FINAL " : "MIDTERM ", atp->tag, ok, notify_cam, atp->sendst, (ccb->ccb_h.flags & CAM_SEND_STATUS) != 0);
1683 if (atp->sendst) {
1709 if (isp->isp_state != ISP_RUNSTATE) {
1710 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) acked- h/w not ready (dropping)", mp->nt_ncode, mp->nt_lreserved != NULL);
1717 if (mp->nt_lreserved && ((isphdr_t *)mp->nt_lreserved)->rqs_entry_type == RQSTYPE_ATIO) {
1718 at7_entry_t *aep = (at7_entry_t *)mp->nt_lreserved;
1723 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
1724 if (isp_find_pdb_by_portid(isp, mp->nt_channel, sid, &lp)) {
1725 nphdl = lp->handle;
1730 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
1731 cto->ct_header.rqs_entry_count = 1;
1732 cto->ct_nphdl = nphdl;
1733 cto->ct_rxid = aep->at_rxid;
1734 cto->ct_vpidx = mp->nt_channel;
1735 cto->ct_iid_lo = sid;
1736 cto->ct_iid_hi = sid >> 16;
1737 cto->ct_oxid = aep->at_hdr.ox_id;
1738 cto->ct_flags = CT7_SENDSTATUS|CT7_NOACK|CT7_NO_DATA|CT7_FLAG_MODE1;
1739 cto->ct_flags |= (aep->at_ta_len >> 12) << CT7_TASK_ATTR_SHIFT;
1741 cto->ct_scsi_status |= (FCP_RSPLEN_VALID << 8);
1742 cto->rsp.m1.ct_resplen = 4;
1743 ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp));
1744 cto->rsp.m1.ct_resp[0] = rsp & 0xff;
1745 cto->rsp.m1.ct_resp[1] = (rsp >> 8) & 0xff;
1746 cto->rsp.m1.ct_resp[2] = (rsp >> 16) & 0xff;
1747 cto->rsp.m1.ct_resp[3] = (rsp >> 24) & 0xff;
1755 if (mp->nt_lreserved && ((isphdr_t *)mp->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD)
1756 return (isp_acknak_abts(isp, mp->nt_lreserved, (rsp == 0) ? 0 : EINVAL));
1761 if (mp->nt_need_ack) {
1762 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) being acked", mp->nt_ncode, mp->nt_lreserved != NULL);
1766 return (isp_notify_ack(isp, mp->nt_lreserved));
1788 isp_prt(isp, ISP_LOGTDEBUG0, "%s: code 0x%x sid 0x%x tagval 0x%016llx chan %d lun %jx", __func__, notify->nt_ncode,
1789 notify->nt_sid, (unsigned long long) notify->nt_tagval, notify->nt_channel, notify->nt_lun);
1790 if (notify->nt_lun == LUN_ANY) {
1791 if (notify->nt_tagval == TAG_ANY) {
1794 atp = isp_find_atpd(isp, notify->nt_channel,
1795 notify->nt_tagval & 0xffffffff);
1796 lun = atp ? atp->lun : CAM_LUN_WILDCARD;
1799 lun = notify->nt_lun;
1801 tptr = get_lun_statep(isp, notify->nt_channel, lun);
1803 tptr = get_lun_statep(isp, notify->nt_channel, CAM_LUN_WILDCARD);
1805 isp_prt(isp, ISP_LOGWARN, "%s: no state pointer found for chan %d lun %#jx", __func__, notify->nt_channel, (uintmax_t)lun);
1809 inot = (struct ccb_immediate_notify *) SLIST_FIRST(&tptr->inots);
1811 isp_prt(isp, ISP_LOGWARN, "%s: out of immediate notify structures for chan %d lun %#jx", __func__, notify->nt_channel, (uintmax_t)lun);
1815 inot->ccb_h.target_id = ISP_MAX_TARGETS(isp);
1816 inot->ccb_h.target_lun = lun;
1817 if (isp_find_pdb_by_portid(isp, notify->nt_channel, notify->nt_sid, &lp) == 0 &&
1818 isp_find_pdb_by_handle(isp, notify->nt_channel, notify->nt_nphdl, &lp) == 0) {
1819 inot->initiator_id = CAM_TARGET_WILDCARD;
1821 inot->initiator_id = FC_PORTDB_TGT(isp, notify->nt_channel, lp);
1823 inot->seq_id = notify->nt_tagval;
1824 inot->tag_id = notify->nt_tagval >> 32;
1826 switch (notify->nt_ncode) {
1828 isp_target_mark_aborted_early(isp, notify->nt_channel, tptr, inot->tag_id);
1829 inot->arg = MSG_ABORT_TASK;
1832 isp_target_mark_aborted_early(isp, notify->nt_channel, tptr, TAG_ANY);
1833 inot->arg = MSG_ABORT_TASK_SET;
1836 inot->arg = MSG_CLEAR_ACA;
1839 inot->arg = MSG_CLEAR_TASK_SET;
1842 inot->arg = MSG_LOGICAL_UNIT_RESET;
1845 inot->arg = MSG_TARGET_RESET;
1848 inot->arg = MSG_QUERY_TASK_SET;
1851 inot->arg = MSG_QUERY_ASYNC_EVENT;
1854 isp_prt(isp, ISP_LOGWARN, "%s: unknown TMF code 0x%x for chan %d lun %#jx", __func__, notify->nt_ncode, notify->nt_channel, (uintmax_t)lun);
1858 ntp = isp_get_ntpd(isp, notify->nt_channel);
1863 ISP_MEMCPY(&ntp->nt, notify, sizeof (isp_notify_t));
1864 if (notify->nt_lreserved) {
1865 ISP_MEMCPY(&ntp->data, notify->nt_lreserved, QENTRY_LEN);
1866 ntp->nt.nt_lreserved = &ntp->data;
1868 ntp->seq_id = notify->nt_tagval;
1869 ntp->tag_id = notify->nt_tagval >> 32;
1871 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
1872 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, inot->ccb_h.path, "Take FREE INOT\n");
1873 inot->ccb_h.status = CAM_MESSAGE_RECV;
1877 if (notify->nt_need_ack) {
1878 if (((isphdr_t *)notify->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD) {
1879 if (isp_acknak_abts(isp, notify->nt_lreserved, ENOMEM)) {
1880 isp_prt(isp, ISP_LOGWARN, "you lose- unable to send an ACKNAK");
1883 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, notify->nt_lreserved);
1892 isp_target_mark_aborted_early(ispsoftc_t *isp, int chan, tstate_t *tptr, uint32_t tag_id)
1897 STAILQ_FOREACH_SAFE(ntp, &tptr->restart_queue, next, tmp) {
1898 this_tag_id = ((at7_entry_t *)ntp->data)->at_rxid;
1900 STAILQ_REMOVE(&tptr->restart_queue, ntp,
1902 isp_endcmd(isp, ntp->data, NIL_HANDLE, chan,
1904 isp_put_ntpd(isp, chan, ntp);
1983 isp_make_here(ispsoftc_t *isp, fcportdb_t *fcp, int chan, int tgt)
1986 struct isp_fc *fc = ISP_FC_PC(isp, chan);
1993 isp_prt(isp, ISP_LOGWARN, "Chan %d unable to alloc CCB for rescan", chan);
1996 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(fc->sim),
2006 isp_make_gone(ispsoftc_t *isp, fcportdb_t *fcp, int chan, int tgt)
2009 struct isp_fc *fc = ISP_FC_PC(isp, chan);
2011 if (xpt_create_path(&tp, NULL, cam_sim_path(fc->sim), tgt, CAM_LUN_WILDCARD) == CAM_REQ_CMP) {
2018 * Gone Device Timer Function- when we have decided that a device has gone
2031 taskqueue_enqueue(taskqueue_thread, &fc->gtask);
2038 ispsoftc_t *isp = fc->isp;
2039 int chan = fc - ISP_FC_PC(isp, 0);
2042 struct ac_device_changed *adc;
2046 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d GDT timer expired", chan);
2048 lp = &FCPARAM(isp, chan)->portdb[dbidx];
2050 if (lp->state != FC_PORTDB_STATE_ZOMBIE) {
2053 if (lp->gone_timer != 0) {
2054 lp->gone_timer -= 1;
2058 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, dbidx, lp->portid, "Gone Device Timeout");
2059 if (lp->is_target) {
2060 lp->is_target = 0;
2061 isp_make_gone(isp, lp, chan, dbidx);
2063 if (lp->is_initiator) {
2064 lp->is_initiator = 0;
2066 adc = (struct ac_device_changed *) ac.contract_data;
2067 adc->wwpn = lp->port_wwn;
2068 adc->port = lp->portid;
2069 adc->target = dbidx;
2070 adc->arrived = 0;
2071 xpt_async(AC_CONTRACT, fc->path, &ac);
2073 lp->state = FC_PORTDB_STATE_NIL;
2075 if (fc->ready) {
2077 callout_reset(&fc->gdt, hz, isp_gdt, fc);
2079 callout_deactivate(&fc->gdt);
2080 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Stopping Gone Device Timer @ %lu", chan, (unsigned long) time_uptime);
2096 isp_loop_changed(ispsoftc_t *isp, int chan)
2098 fcparam *fcp = FCPARAM(isp, chan);
2099 struct isp_fc *fc = ISP_FC_PC(isp, chan);
2101 if (fc->loop_down_time)
2103 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Loop changed", chan);
2104 if (fcp->role & ISP_ROLE_INITIATOR)
2105 isp_freeze_loopdown(isp, chan);
2106 fc->loop_down_time = time_uptime;
2111 isp_loop_up(ispsoftc_t *isp, int chan)
2113 struct isp_fc *fc = ISP_FC_PC(isp, chan);
2115 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Loop is up", chan);
2116 fc->loop_seen_once = 1;
2117 fc->loop_down_time = 0;
2118 isp_unfreeze_loopdown(isp, chan);
2122 isp_loop_dead(ispsoftc_t *isp, int chan)
2124 fcparam *fcp = FCPARAM(isp, chan);
2125 struct isp_fc *fc = ISP_FC_PC(isp, chan);
2128 struct ac_device_changed *adc;
2131 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Loop is dead", chan);
2137 lp = &fcp->portdb[dbidx];
2139 if (lp->state == FC_PORTDB_STATE_NIL)
2145 if (ISP_H2HT(isp->isp_xflist[i].handle) != ISP_HANDLE_INITIATOR) {
2148 if ((xs = isp->isp_xflist[i].cmd) == NULL) {
2155 isp->isp_xflist[i].handle, chan, XS_TGT(xs),
2168 isp_destroy_handle(isp, isp->isp_xflist[i].handle);
2170 isp->isp_xflist[i].handle, chan, XS_TGT(xs),
2176 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, dbidx, lp->portid, "Loop Down Timeout");
2177 if (lp->is_target) {
2178 lp->is_target = 0;
2179 isp_make_gone(isp, lp, chan, dbidx);
2181 if (lp->is_initiator) {
2182 lp->is_initiator = 0;
2184 adc = (struct ac_device_changed *) ac.contract_data;
2185 adc->wwpn = lp->port_wwn;
2186 adc->port = lp->portid;
2187 adc->target = dbidx;
2188 adc->arrived = 0;
2189 xpt_async(AC_CONTRACT, fc->path, &ac);
2193 isp_unfreeze_loopdown(isp, chan);
2194 fc->loop_down_time = 0;
2201 ispsoftc_t *isp = fc->isp;
2202 int chan = fc - ISP_FC_PC(isp, 0);
2207 while (isp->isp_osinfo.is_exiting == 0) {
2209 "Chan %d Checking FC state", chan);
2210 lb = isp_fc_runstate(isp, chan, 250000);
2212 "Chan %d FC got to %s state", chan,
2232 if (fc->loop_seen_once == 0)
2235 lim = fc->loop_down_limit;
2236 d = time_uptime - fc->loop_down_time;
2253 isp_loop_up(isp, chan);
2255 isp_loop_dead(isp, chan);
2259 "Chan %d sleep for %d seconds", chan, slp);
2260 msleep(fc, &isp->isp_lock, PRIBIO, "ispf", slp * hz);
2262 fc->num_threads -= 1;
2263 wakeup(&fc->num_threads);
2270 isp_abort_atpd(ispsoftc_t *isp, int chan, atio_private_data_t *atp)
2276 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
2277 cto->ct_header.rqs_entry_count = 1;
2278 cto->ct_nphdl = atp->nphdl;
2279 cto->ct_vpidx = chan;
2280 cto->ct_iid_lo = atp->sid;
2281 cto->ct_iid_hi = atp->sid >> 16;
2282 cto->ct_rxid = atp->tag;
2283 cto->ct_flags = CT7_NOACK|CT7_TERMINATE;
2284 cto->ct_oxid = atp->oxid;
2292 union ccb *accb = ccb->cab.abort_ccb;
2299 SLIST_FOREACH(sccb, &tptr->atios, sim_links.sle) {
2300 if (sccb != &accb->ccb_h)
2302 SLIST_REMOVE(&tptr->atios, sccb, ccb_hdr, sim_links.sle);
2303 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, sccb->path,
2305 accb->ccb_h.status = CAM_REQ_ABORTED;
2307 ccb->ccb_h.status = CAM_REQ_CMP;
2313 atp = isp_find_atpd_ccb(isp, XS_CHANNEL(accb), accb->atio.tag_id, accb);
2316 ccb->ccb_h.status = CAM_UA_ABORT;
2322 ccb->ccb_h.status = CAM_REQ_CMP;
2329 union ccb *accb = ccb->cab.abort_ccb;
2336 SLIST_FOREACH(sccb, &tptr->inots, sim_links.sle) {
2337 if (sccb != &accb->ccb_h)
2339 SLIST_REMOVE(&tptr->inots, sccb, ccb_hdr, sim_links.sle);
2340 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, sccb->path,
2342 accb->ccb_h.status = CAM_REQ_ABORTED;
2344 ccb->ccb_h.status = CAM_REQ_CMP;
2350 ntp = isp_find_ntpd(isp, XS_CHANNEL(accb), accb->cin1.tag_id, accb->cin1.seq_id);
2352 if (ntp->nt.nt_need_ack) {
2354 ntp->nt.nt_lreserved);
2357 ccb->ccb_h.status = CAM_REQ_CMP;
2359 ccb->ccb_h.status = CAM_UA_ABORT;
2374 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
2379 isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
2382 switch (ccb->ccb_h.func_code) {
2387 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
2388 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
2389 ccb->ccb_h.status = CAM_REQ_INVALID;
2395 if (ccb->ccb_h.target_id >= ISP_MAX_TARGETS(isp)) {
2396 xpt_print(ccb->ccb_h.path, "invalid target\n");
2397 ccb->ccb_h.status = CAM_PATH_INVALID;
2399 if (ccb->ccb_h.status == CAM_PATH_INVALID) {
2404 ccb->csio.scsi_status = SCSI_STATUS_OK;
2407 cam_freeze_devq(ccb->ccb_h.path);
2408 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
2409 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2417 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2418 if (ccb->ccb_h.timeout == CAM_TIME_INFINITY)
2421 ts = SBT_1MS * ccb->ccb_h.timeout + 10 * SBT_1S;
2422 callout_reset_sbt(&PISP_PCMD(ccb)->wdog, ts, 0,
2428 cam_freeze_devq(ccb->ccb_h.path);
2429 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
2430 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2436 cam_freeze_devq(ccb->ccb_h.path);
2437 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 10, 0);
2438 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2446 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2454 if (ccb->cel.enable) {
2463 tstate_t *tptr = get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun);
2467 if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY)
2471 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path,
2474 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
2479 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
2480 ccb->atio.tag_id = 0;
2481 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h, sim_links.sle);
2482 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path,
2484 } else if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY) {
2485 ccb->cin1.seq_id = ccb->cin1.tag_id = 0;
2486 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
2487 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path,
2490 ccb->ccb_h.status = CAM_REQ_INPROG;
2505 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: [0x%x] NOTIFY ACKNOWLEDGE for 0x%x seen\n", __func__, ccb->cna2.tag_id, ccb->cna2.seq_id);
2506 ntp = isp_find_ntpd(isp, XS_CHANNEL(ccb), ccb->cna2.tag_id, ccb->cna2.seq_id);
2508 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "%s: [0x%x] XPT_NOTIFY_ACKNOWLEDGE of 0x%x cannot find ntp private data\n", __func__,
2509 ccb->cna2.tag_id, ccb->cna2.seq_id);
2510 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
2516 * Target should abort all affected tasks before ACK-ing INOT,
2521 uint32_t rsp = (ccb->ccb_h.flags & CAM_SEND_STATUS) ? ccb->cna2.arg : 0;
2522 if (ntp->nt.nt_ncode == NT_ABORT_TASK && (rsp & 0xff) == 0 &&
2523 (atp = isp_find_atpd(isp, XS_CHANNEL(ccb), ccb->cna2.seq_id)) != NULL) {
2524 if (atp->ctcnt == 0 &&
2528 atp->dead = 1;
2531 if (isp_handle_platform_target_notify_ack(isp, &ntp->nt, rsp)) {
2532 cam_freeze_devq(ccb->ccb_h.path);
2533 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 10, 0);
2534 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2535 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
2539 ccb->ccb_h.status = CAM_REQ_CMP;
2540 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: [0x%x] calling xpt_done for tag 0x%x\n", __func__, ccb->cna2.tag_id, ccb->cna2.seq_id);
2550 tgt = ccb->ccb_h.target_id;
2555 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2560 * that we re-start the CRN at 1 after a reset.
2564 ccb->ccb_h.status = CAM_REQ_CMP;
2570 union ccb *accb = ccb->cab.abort_ccb;
2571 switch (accb->ccb_h.func_code) {
2583 ccb->ccb_h.status = CAM_UA_ABORT;
2585 ccb->ccb_h.status = CAM_REQ_CMP;
2589 ccb->ccb_h.status = CAM_REQ_INVALID;
2598 #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
2600 cts = &ccb->cts;
2602 ccb->ccb_h.status = CAM_REQ_INVALID;
2606 ccb->ccb_h.status = CAM_REQ_CMP;
2614 cts = &ccb->cts;
2615 scsi = &cts->proto_specific.scsi;
2616 fc = &cts->xport_specific.fc;
2617 tgt = cts->ccb_h.target_id;
2620 cts->protocol = PROTO_SCSI;
2621 cts->protocol_version = SCSI_REV_2;
2622 cts->transport = XPORT_FC;
2623 cts->transport_version = 0;
2625 scsi->valid = CTS_SCSI_VALID_TQ;
2626 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
2627 fc->valid = CTS_FC_VALID_SPEED;
2628 fc->bitrate = fcp->isp_gbspeed * 100000;
2630 fcportdb_t *lp = &fcp->portdb[tgt];
2631 fc->wwnn = lp->node_wwn;
2632 fc->wwpn = lp->port_wwn;
2633 fc->port = lp->portid;
2634 fc->valid |= CTS_FC_VALID_WWNN | CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT;
2636 ccb->ccb_h.status = CAM_REQ_CMP;
2641 cam_calc_geometry(&ccb->ccg, 1);
2648 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2653 xpt_print(ccb->ccb_h.path, "reset bus on channel %d\n", bus);
2655 xpt_async(AC_BUS_RESET, ISP_FC_PC(isp, bus)->path, 0);
2656 ccb->ccb_h.status = CAM_REQ_CMP;
2661 ccb->ccb_h.status = CAM_REQ_INVALID;
2667 struct ccb_sim_knob *kp = &ccb->knob;
2670 if (kp->xport_specific.fc.valid & KNOB_VALID_ADDRESS) {
2671 fcp->isp_wwnn = ISP_FC_PC(isp, bus)->def_wwnn = kp->xport_specific.fc.wwnn;
2672 fcp->isp_wwpn = ISP_FC_PC(isp, bus)->def_wwpn = kp->xport_specific.fc.wwpn;
2673 isp_prt(isp, ISP_LOGALL, "Setting Channel %d wwns to 0x%jx 0x%jx", bus, fcp->isp_wwnn, fcp->isp_wwpn);
2675 ccb->ccb_h.status = CAM_REQ_CMP;
2676 if (kp->xport_specific.fc.valid & KNOB_VALID_ROLE) {
2680 switch (kp->xport_specific.fc.role) {
2682 if (fcp->role != ISP_ROLE_NONE) {
2688 if (fcp->role != ISP_ROLE_TARGET) {
2694 if (fcp->role != ISP_ROLE_INITIATOR) {
2700 if (fcp->role != ISP_ROLE_BOTH) {
2707 ISP_PATH_PRT(isp, ISP_LOGCONFIG, ccb->ccb_h.path, "changing role on from %d to %d\n", fcp->role, newrole);
2710 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2719 case XPT_GET_SIM_KNOB_OLD: /* Get SIM knobs -- compat value */
2722 struct ccb_sim_knob *kp = &ccb->knob;
2725 kp->xport_specific.fc.wwnn = fcp->isp_wwnn;
2726 kp->xport_specific.fc.wwpn = fcp->isp_wwpn;
2727 switch (fcp->role) {
2729 kp->xport_specific.fc.role = KNOB_ROLE_NONE;
2732 kp->xport_specific.fc.role = KNOB_ROLE_TARGET;
2735 kp->xport_specific.fc.role = KNOB_ROLE_INITIATOR;
2738 kp->xport_specific.fc.role = KNOB_ROLE_BOTH;
2741 kp->xport_specific.fc.valid = KNOB_VALID_ADDRESS | KNOB_VALID_ROLE;
2742 ccb->ccb_h.status = CAM_REQ_CMP;
2748 struct ccb_pathinq *cpi = &ccb->cpi;
2750 cpi->version_num = 1;
2752 cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
2754 cpi->target_sprt = 0;
2756 cpi->hba_eng_cnt = 0;
2757 cpi->max_target = ISP_MAX_TARGETS(isp) - 1;
2758 cpi->max_lun = 255;
2759 cpi->bus_id = cam_sim_bus(sim);
2760 cpi->maxio = (ISP_NSEG64_MAX - 1) * PAGE_SIZE;
2764 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED;
2765 cpi->hba_misc |= PIM_EXTLUNS | PIM_NOSCAN;
2771 cpi->initiator_id = cpi->max_target + 1;
2777 cpi->base_transfer_speed = 8000000;
2779 cpi->base_transfer_speed = 4000000;
2780 cpi->hba_inquiry = PI_TAG_ABLE;
2781 cpi->transport = XPORT_FC;
2782 cpi->transport_version = 0;
2783 cpi->xport_specific.fc.wwnn = fcp->isp_wwnn;
2784 cpi->xport_specific.fc.wwpn = fcp->isp_wwpn;
2785 cpi->xport_specific.fc.port = fcp->isp_portid;
2786 cpi->xport_specific.fc.bitrate = fcp->isp_gbspeed * 1000;
2787 cpi->protocol = PROTO_SCSI;
2788 cpi->protocol_version = SCSI_REV_2;
2789 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
2790 strlcpy(cpi->hba_vid, "Qlogic", HBA_IDLEN);
2791 strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
2792 cpi->unit_number = cam_sim_unit(sim);
2793 cpi->ccb_h.status = CAM_REQ_CMP;
2798 ccb->ccb_h.status = CAM_REQ_INVALID;
2813 if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP && (sccb->scsi_status != SCSI_STATUS_OK)) {
2814 sccb->ccb_h.status &= ~CAM_STATUS_MASK;
2815 if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) && (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) {
2816 sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
2818 sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
2822 sccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2823 status = sccb->ccb_h.status & CAM_STATUS_MASK;
2825 (sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
2826 sccb->ccb_h.status |= CAM_DEV_QFRZN;
2827 xpt_freeze_devq(sccb->ccb_h.path, 1);
2831 if (callout_active(&PISP_PCMD(sccb)->wdog))
2832 callout_stop(&PISP_PCMD(sccb)->wdog);
2843 static const char prom[] = "Chan %d [%d] WWPN 0x%16jx PortID 0x%06x handle 0x%x %s %s";
2850 struct ac_device_changed *adc;
2865 isp_prt(isp, ISP_LOGINFO, "Chan %d LOOP Reset, LIP primitive %x", bus, lipp);
2867 * Per FCP-4, a Reset LIP should result in a CRN reset. Other
2897 isp_prt(isp, ISP_LOGINFO, "Chan %d %s", bus, msg);
2906 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
2907 isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "arrived");
2908 if ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) &&
2909 (lp->prli_word3 & PRLI_WD3_TARGET_FUNCTION)) {
2910 lp->is_target = 1;
2914 if ((FCPARAM(isp, bus)->role & ISP_ROLE_TARGET) &&
2915 (lp->prli_word3 & PRLI_WD3_INITIATOR_FUNCTION)) {
2916 lp->is_initiator = 1;
2918 adc = (struct ac_device_changed *) ac.contract_data;
2919 adc->wwpn = lp->port_wwn;
2920 adc->port = lp->portid;
2921 adc->target = tgt;
2922 adc->arrived = 1;
2923 xpt_async(AC_CONTRACT, fc->path, &ac);
2938 isp_gen_role_str(buf, sizeof (buf), lp->new_prli_word3);
2940 isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->new_portid, lp->handle, buf, "changed");
2942 isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "stayed");
2944 if (lp->is_target !=
2945 ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) &&
2946 (lp->new_prli_word3 & PRLI_WD3_TARGET_FUNCTION))) {
2947 lp->is_target = !lp->is_target;
2948 if (lp->is_target) {
2962 if (lp->is_initiator !=
2963 ((FCPARAM(isp, bus)->role & ISP_ROLE_TARGET) &&
2964 (lp->new_prli_word3 & PRLI_WD3_INITIATOR_FUNCTION))) {
2965 lp->is_initiator = !lp->is_initiator;
2967 adc = (struct ac_device_changed *) ac.contract_data;
2968 adc->wwpn = lp->port_wwn;
2969 adc->port = lp->portid;
2970 adc->target = tgt;
2971 adc->arrived = lp->is_initiator;
2972 xpt_async(AC_CONTRACT, fc->path, &ac);
2992 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
2993 if (lp->is_target || lp->is_initiator) {
2994 lp->state = FC_PORTDB_STATE_ZOMBIE;
2995 lp->gone_timer = fc->gone_device_time;
2996 isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "gone zombie");
2997 if (fc->ready && !callout_active(&fc->gdt)) {
2998 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Starting Gone Device Timer with %u seconds time now %lu", bus, lp->gone_timer, (unsigned long)time_uptime);
2999 callout_reset(&fc->gdt, hz, isp_gdt, fc);
3003 isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "gone");
3029 "Chan %d %s (nphdl 0x%x state 0x%x reason 0x%x)",
3036 * the fcp crn on these events according to FCP-4
3067 isp_prt(isp, ISP_LOGINFO, "Chan %d %s (PortID 0x%06x)",
3071 isp_prt(isp, ISP_LOGINFO, "Chan %d %s", bus, msg);
3083 switch (notify->nt_ncode) {
3109 isp_prt(isp, ISP_LOGALL, "target notify code 0x%x", notify->nt_ncode);
3124 tp->isp = isp;
3125 memcpy(tp->data, inot, sizeof (tp->data));
3126 tp->not = tp->data;
3127 callout_init_mtx(&tp->timer, &isp->isp_lock, 0);
3128 callout_reset(&tp->timer, 5,
3131 isp_prt(isp, ISP_LOGERR, "you lose- cannot allocate a notify refire");
3143 switch (hp->rqs_entry_type) {
3152 __func__, hp->rqs_entry_type);
3176 isp_default_wwn(ispsoftc_t * isp, int chan, int isactive, int iswwnn)
3179 struct isp_fc *fc = ISP_FC_PC(isp, chan);
3182 seed = iswwnn ? fc->def_wwnn : fc->def_wwpn;
3188 seed = iswwnn ? FCPARAM(isp, chan)->isp_wwnn_nvram :
3189 FCPARAM(isp, chan)->isp_wwpn_nvram;
3195 if (chan > 0) {
3196 seed = iswwnn ? ISP_FC_PC(isp, 0)->def_wwnn :
3197 ISP_FC_PC(isp, 0)->def_wwpn;
3199 seed = iswwnn ? FCPARAM(isp, 0)->isp_wwnn_nvram :
3200 FCPARAM(isp, 0)->isp_wwpn_nvram;
3204 /* If still nothing -- improvise. */
3206 seed = 0x400000007F000000ull + device_get_unit(isp->isp_dev);
3212 if (!iswwnn && chan > 0) {
3219 seed ^= ((uint64_t) (chan + 1) & 0xf) << 56;
3220 seed ^= ((uint64_t) ((chan + 1) >> 4) & 0xf) << 52;
3232 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
3235 snprintf(lbuf, sizeof (lbuf), "%s: ", device_get_nameunit(isp->isp_dev));
3238 vsnprintf(&lbuf[loc], sizeof (lbuf) - loc - 1, fmt, ap);
3247 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
3250 xpt_print_path(xs->ccb_h.path);
3271 isp_fc_scratch_acquire(ispsoftc_t *isp, int chan)
3273 struct isp_fc *fc = ISP_FC_PC(isp, chan);
3275 if (fc->fcbsy)
3276 return (-1);
3277 fc->fcbsy = 1;
3330 ispsoftc_t *isp= mp->isp;
3331 struct ccb_scsiio *csio = mp->csio;
3335 mp->error = error;
3338 if ((csio->ccb_h.func_code == XPT_CONT_TARGET_IO) ^
3339 ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN))
3343 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, op);
3345 mp->error = ISP_SEND_CMD(isp, mp->qe, dm_segs, nseg);
3346 if (mp->error)
3361 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap,
3379 csio->ccb_h.status = CAM_REQ_INVALID;
3383 csio->ccb_h.status = CAM_UNREC_HBA_ERROR;
3398 if ((csio->ccb_h.func_code == XPT_CONT_TARGET_IO) ^
3399 ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN))
3403 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, op);
3404 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
3413 isp_fcp_reset_crn(ispsoftc_t *isp, int chan, uint32_t tgt, int tgt_set)
3415 struct isp_fc *fc = ISP_FC_PC(isp, chan);
3421 "Chan %d resetting CRN on all targets", chan);
3424 "Chan %d resetting CRN on target %u", chan, tgt);
3427 for (nxp = fc->nexus_hash[i]; nxp != NULL; nxp = nxp->next) {
3428 if (tgt_set == 0 || tgt == nxp->tgt)
3429 nxp->crnseed = 0;
3438 uint32_t chan, tgt;
3443 chan = XS_CHANNEL(cmd);
3446 fc = ISP_FC_PC(isp, chan);
3448 nxp = fc->nexus_hash[idx];
3451 if (nxp->tgt == tgt && nxp->lun == lun)
3453 nxp = nxp->next;
3456 nxp = fc->nexus_free_list;
3460 return (-1);
3463 fc->nexus_free_list = nxp->next;
3465 nxp->tgt = tgt;
3466 nxp->lun = lun;
3467 nxp->next = fc->nexus_hash[idx];
3468 fc->nexus_hash[idx] = nxp;
3470 if (nxp->crnseed == 0)
3471 nxp->crnseed = 1;
3472 *crnp = nxp->crnseed++;
3486 callout_reset(&isp->isp_osinfo.tmo, isp_timer_count, isp_timer, isp);
3493 isp_ecmd_t *ecmd = isp->isp_osinfo.ecmd_free;
3495 isp->isp_osinfo.ecmd_free = ecmd->next;
3503 ecmd->next = isp->isp_osinfo.ecmd_free;
3504 isp->isp_osinfo.ecmd_free = ecmd;