2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <dev/isp/isp_freebsd.h>
34 #include <sys/unistd.h>
35 #include <sys/kthread.h>
37 #include <sys/module.h>
38 #include <sys/ioccom.h>
39 #include <dev/isp/isp_ioctl.h>
40 #include <sys/devicestat.h>
41 #include <cam/cam_periph.h>
42 #include <cam/cam_xpt_periph.h>
44 #if __FreeBSD_version < 800002
45 #define THREAD_CREATE kthread_create
47 #define THREAD_CREATE kproc_create
50 MODULE_VERSION(isp, 1);
51 MODULE_DEPEND(isp, cam, 1, 1, 1);
52 int isp_announced = 0;
53 int isp_fabric_hysteresis = 5;
54 int isp_loop_down_limit = 60; /* default loop down limit */
55 int isp_change_is_bad = 0; /* "changed" devices are bad */
56 int isp_quickboot_time = 7; /* don't wait more than N secs for loop up */
57 int isp_gone_device_time = 30; /* grace time before reporting device lost */
58 int isp_autoconfig = 1; /* automatically attach/detach devices */
59 static const char prom3[] = "Chan %d PortID 0x%06x Departed from Target %u because of %s";
61 static void isp_freeze_loopdown(ispsoftc_t *, int, char *);
62 static d_ioctl_t ispioctl;
63 static void isp_intr_enable(void *);
64 static void isp_cam_async(void *, uint32_t, struct cam_path *, void *);
65 static void isp_poll(struct cam_sim *);
66 static timeout_t isp_watchdog;
67 static timeout_t isp_gdt;
68 static task_fn_t isp_gdt_task;
69 static timeout_t isp_ldt;
70 static task_fn_t isp_ldt_task;
71 static void isp_kthread(void *);
72 static void isp_action(struct cam_sim *, union ccb *);
73 #ifdef ISP_INTERNAL_TARGET
74 static void isp_target_thread_pi(void *);
75 static void isp_target_thread_fc(void *);
77 static int isp_timer_count;
78 static void isp_timer(void *);
80 static struct cdevsw isp_cdevsw = {
81 .d_version = D_VERSION,
87 isp_role_sysctl(SYSCTL_HANDLER_ARGS)
89 ispsoftc_t *isp = (ispsoftc_t *)arg1;
91 int error, old, value;
93 value = FCPARAM(isp, chan)->role;
95 error = sysctl_handle_int(oidp, &value, 0, req);
96 if ((error != 0) || (req->newptr == NULL))
99 if (value < ISP_ROLE_NONE || value > ISP_ROLE_BOTH)
103 old = FCPARAM(isp, chan)->role;
105 /* If nothing has changed -- we are done. */
111 /* We don't allow target mode switch from here. */
112 if ((value ^ old) & ISP_ROLE_TARGET) {
117 /* Actually change the role. */
118 error = isp_control(isp, ISPCTL_CHANGE_ROLE, chan, value);
124 isp_attach_chan(ispsoftc_t *isp, struct cam_devq *devq, int chan)
126 struct ccb_setasync csa;
128 struct cam_path *path;
131 * Construct our SIM entry.
133 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp, device_get_unit(isp->isp_dev), &isp->isp_osinfo.lock, isp->isp_maxcmds, isp->isp_maxcmds, devq);
140 if (xpt_bus_register(sim, isp->isp_dev, chan) != CAM_SUCCESS) {
142 cam_sim_free(sim, FALSE);
146 if (xpt_create_path(&path, NULL, cam_sim_path(sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
148 xpt_bus_deregister(cam_sim_path(sim));
150 cam_sim_free(sim, FALSE);
153 xpt_setup_ccb(&csa.ccb_h, path, 5);
154 csa.ccb_h.func_code = XPT_SASYNC_CB;
155 csa.event_enable = AC_LOST_DEVICE;
156 csa.callback = isp_cam_async;
157 csa.callback_arg = sim;
160 xpt_action((union ccb *)&csa);
164 struct isp_spi *spi = ISP_SPI_PC(isp, chan);
167 #ifdef ISP_INTERNAL_TARGET
168 ISP_SET_PC(isp, chan, proc_active, 1);
169 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)) {
170 ISP_SET_PC(isp, chan, proc_active, 0);
171 isp_prt(isp, ISP_LOGERR, "cannot create test target thread");
173 ISP_SPI_PC(isp, chan)->num_threads += 1;
176 fcparam *fcp = FCPARAM(isp, chan);
177 struct isp_fc *fc = ISP_FC_PC(isp, chan);
178 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(isp->isp_osinfo.dev);
179 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
188 callout_init_mtx(&fc->ldt, &isp->isp_osinfo.lock, 0);
189 callout_init_mtx(&fc->gdt, &isp->isp_osinfo.lock, 0);
190 TASK_INIT(&fc->ltask, 1, isp_ldt_task, fc);
191 TASK_INIT(&fc->gtask, 1, isp_gdt_task, fc);
194 * We start by being "loop down" if we have an initiator role
196 if (fcp->role & ISP_ROLE_INITIATOR) {
197 isp_freeze_loopdown(isp, chan, "isp_attach");
198 callout_reset(&fc->ldt, isp_quickboot_time * hz, isp_ldt, fc);
199 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Starting Initial Loop Down Timer @ %lu", (unsigned long) time_uptime);
202 if (THREAD_CREATE(isp_kthread, fc, &fc->kproc, 0, 0, "%s: fc_thrd%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
203 xpt_free_path(fc->path);
205 if (callout_active(&fc->ldt))
206 callout_stop(&fc->ldt);
207 xpt_bus_deregister(cam_sim_path(fc->sim));
209 cam_sim_free(fc->sim, FALSE);
212 ISP_FC_PC(isp, chan)->num_threads += 1;
213 #ifdef ISP_INTERNAL_TARGET
214 ISP_SET_PC(isp, chan, proc_active, 1);
215 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)) {
216 ISP_SET_PC(isp, chan, proc_active, 0);
217 isp_prt(isp, ISP_LOGERR, "cannot create test target thread");
219 ISP_FC_PC(isp, chan)->num_threads += 1;
222 snprintf(name, sizeof(name), "chan%d", chan);
223 tree = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree),
224 OID_AUTO, name, CTLFLAG_RW, 0, "Virtual channel");
226 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwnn", CTLFLAG_RD, &FCPARAM(isp, chan)->isp_wwnn, "World Wide Node Name");
227 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwpn", CTLFLAG_RD, &FCPARAM(isp, chan)->isp_wwpn, "World Wide Port Name");
228 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "loop_down_limit", CTLFLAG_RW, &ISP_FC_PC(isp, chan)->loop_down_limit, 0, "Loop Down Limit");
229 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "gone_device_time", CTLFLAG_RW, &ISP_FC_PC(isp, chan)->gone_device_time, 0, "Gone Device Time");
230 #if defined(ISP_TARGET_MODE) && defined(DEBUG)
231 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "inject_lost_data_frame", CTLFLAG_RW, &ISP_FC_PC(isp, chan)->inject_lost_data_frame, 0, "Cause a Lost Frame on a Read");
233 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
234 "role", CTLTYPE_INT | CTLFLAG_RW, isp, chan,
235 isp_role_sysctl, "I", "Current role");
241 isp_detach_internal_target(ispsoftc_t *isp, int chan)
243 #ifdef ISP_INTERNAL_TARGET
246 ISP_GET_PC(isp, chan, target_proc, wchan);
247 ISP_SET_PC(isp, chan, proc_active, 0);
253 isp_detach_chan(ispsoftc_t *isp, int chan)
256 struct cam_path *path;
257 struct ccb_setasync csa;
260 ISP_GET_PC(isp, chan, sim, sim);
261 ISP_GET_PC(isp, chan, path, path);
262 ISP_GET_PC_ADDR(isp, chan, num_threads, num_threads);
264 xpt_setup_ccb(&csa.ccb_h, path, 5);
265 csa.ccb_h.func_code = XPT_SASYNC_CB;
266 csa.event_enable = 0;
267 csa.callback = isp_cam_async;
268 csa.callback_arg = sim;
269 xpt_action((union ccb *)&csa);
271 xpt_bus_deregister(cam_sim_path(sim));
272 cam_sim_free(sim, FALSE);
274 /* Wait for the channel's spawned threads to exit. */
275 wakeup(isp->isp_osinfo.pc.ptr);
276 isp_detach_internal_target(isp, chan);
277 while (*num_threads != 0)
278 mtx_sleep(isp, &isp->isp_osinfo.lock, PRIBIO, "isp_reap", 100);
282 isp_attach(ispsoftc_t *isp)
284 const char *nu = device_get_nameunit(isp->isp_osinfo.dev);
285 int du = device_get_unit(isp->isp_dev);
288 isp->isp_osinfo.ehook.ich_func = isp_intr_enable;
289 isp->isp_osinfo.ehook.ich_arg = isp;
291 * Haha. Set this first, because if we're loaded as a module isp_intr_enable
292 * will be called right awawy, which will clear isp_osinfo.ehook_active,
293 * which would be unwise to then set again later.
295 isp->isp_osinfo.ehook_active = 1;
296 if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) {
297 isp_prt(isp, ISP_LOGERR, "could not establish interrupt enable hook");
302 * Create the device queue for our SIM(s).
304 isp->isp_osinfo.devq = cam_simq_alloc(isp->isp_maxcmds);
305 if (isp->isp_osinfo.devq == NULL) {
306 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
310 for (chan = 0; chan < isp->isp_nchan; chan++) {
311 if (isp_attach_chan(isp, isp->isp_osinfo.devq, chan)) {
316 callout_init_mtx(&isp->isp_osinfo.tmo, &isp->isp_osinfo.lock, 0);
317 isp_timer_count = hz >> 2;
318 callout_reset(&isp->isp_osinfo.tmo, isp_timer_count, isp_timer, isp);
319 isp->isp_osinfo.timer_active = 1;
321 isp->isp_osinfo.cdev = make_dev(&isp_cdevsw, du, UID_ROOT, GID_OPERATOR, 0600, "%s", nu);
322 if (isp->isp_osinfo.cdev) {
323 isp->isp_osinfo.cdev->si_drv1 = isp;
328 while (--chan >= 0) {
330 struct cam_path *path;
332 ISP_GET_PC(isp, chan, sim, sim);
333 ISP_GET_PC(isp, chan, path, path);
336 xpt_bus_deregister(cam_sim_path(sim));
338 cam_sim_free(sim, FALSE);
340 if (isp->isp_osinfo.ehook_active) {
341 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
342 isp->isp_osinfo.ehook_active = 0;
344 if (isp->isp_osinfo.cdev) {
345 destroy_dev(isp->isp_osinfo.cdev);
346 isp->isp_osinfo.cdev = NULL;
348 cam_simq_free(isp->isp_osinfo.devq);
349 isp->isp_osinfo.devq = NULL;
354 isp_detach(ispsoftc_t *isp)
360 for (chan = isp->isp_nchan - 1; chan >= 0; chan -= 1) {
361 ISP_GET_PC(isp, chan, sim, sim);
362 if (sim->refcount > 2) {
367 /* Tell spawned threads that we're exiting. */
368 isp->isp_osinfo.is_exiting = 1;
369 if (isp->isp_osinfo.timer_active) {
370 callout_stop(&isp->isp_osinfo.tmo);
371 isp->isp_osinfo.timer_active = 0;
373 for (chan = isp->isp_nchan - 1; chan >= 0; chan -= 1)
374 isp_detach_chan(isp, chan);
377 if (isp->isp_osinfo.cdev) {
378 destroy_dev(isp->isp_osinfo.cdev);
379 isp->isp_osinfo.cdev = NULL;
381 if (isp->isp_osinfo.ehook_active) {
382 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
383 isp->isp_osinfo.ehook_active = 0;
385 if (isp->isp_osinfo.devq != NULL) {
386 cam_simq_free(isp->isp_osinfo.devq);
387 isp->isp_osinfo.devq = NULL;
393 isp_freeze_loopdown(ispsoftc_t *isp, int chan, char *msg)
396 struct isp_fc *fc = ISP_FC_PC(isp, chan);
397 if (fc->simqfrozen == 0) {
398 isp_prt(isp, ISP_LOGDEBUG0, "%s: freeze simq (loopdown) chan %d", msg, chan);
399 fc->simqfrozen = SIMQFRZ_LOOPDOWN;
400 xpt_freeze_simq(fc->sim, 1);
402 isp_prt(isp, ISP_LOGDEBUG0, "%s: mark frozen (loopdown) chan %d", msg, chan);
403 fc->simqfrozen |= SIMQFRZ_LOOPDOWN;
409 isp_unfreeze_loopdown(ispsoftc_t *isp, int chan)
412 struct isp_fc *fc = ISP_FC_PC(isp, chan);
413 int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
414 fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
415 if (wasfrozen && fc->simqfrozen == 0) {
416 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d releasing simq", __func__, chan);
417 xpt_release_simq(fc->sim, 1);
424 ispioctl(struct cdev *dev, u_long c, caddr_t addr, int flags, struct thread *td)
427 int nr, chan, retval = ENOTTY;
434 int olddblev = isp->isp_dblev;
435 isp->isp_dblev = *(int *)addr;
436 *(int *)addr = olddblev;
442 if (chan < 0 || chan >= isp->isp_nchan) {
447 *(int *)addr = FCPARAM(isp, chan)->role;
449 *(int *)addr = SDPARAM(isp, chan)->role;
456 if (chan < 0 || chan >= isp->isp_nchan) {
461 if (nr & ~(ISP_ROLE_INITIATOR|ISP_ROLE_TARGET)) {
467 * We don't really support dual role at present on FC cards.
469 * We should, but a bunch of things are currently broken,
472 if (nr == ISP_ROLE_BOTH) {
473 isp_prt(isp, ISP_LOGERR, "cannot support dual role at present");
478 *(int *)addr = FCPARAM(isp, chan)->role;
481 *(int *)addr = SDPARAM(isp, chan)->role;
483 retval = isp_control(isp, ISPCTL_CHANGE_ROLE, chan, nr);
490 #ifdef ISP_TARGET_MODE
491 isp_del_all_wwn_entries(isp, ISP_NOCHAN);
501 if (chan < 0 || chan >= isp->isp_nchan) {
506 if (isp_fc_runstate(isp, chan, 5 * 1000000)) {
518 if (chan < 0 || chan >= isp->isp_nchan) {
523 if (isp_control(isp, ISPCTL_SEND_LIP, chan)) {
531 case ISP_FC_GETDINFO:
533 struct isp_fc_device *ifc = (struct isp_fc_device *) addr;
539 if (ifc->loopid >= MAX_FC_TARG) {
543 lp = &FCPARAM(isp, ifc->chan)->portdb[ifc->loopid];
544 if (lp->state == FC_PORTDB_STATE_VALID || lp->target_mode) {
545 ifc->role = (lp->prli_word3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
546 ifc->loopid = lp->handle;
547 ifc->portid = lp->portid;
548 ifc->node_wwn = lp->node_wwn;
549 ifc->port_wwn = lp->port_wwn;
558 isp_stats_t *sp = (isp_stats_t *) addr;
560 ISP_MEMZERO(sp, sizeof (*sp));
561 sp->isp_stat_version = ISP_STATS_VERSION;
562 sp->isp_type = isp->isp_type;
563 sp->isp_revision = isp->isp_revision;
565 sp->isp_stats[ISP_INTCNT] = isp->isp_intcnt;
566 sp->isp_stats[ISP_INTBOGUS] = isp->isp_intbogus;
567 sp->isp_stats[ISP_INTMBOXC] = isp->isp_intmboxc;
568 sp->isp_stats[ISP_INGOASYNC] = isp->isp_intoasync;
569 sp->isp_stats[ISP_RSLTCCMPLT] = isp->isp_rsltccmplt;
570 sp->isp_stats[ISP_FPHCCMCPLT] = isp->isp_fphccmplt;
571 sp->isp_stats[ISP_RSCCHIWAT] = isp->isp_rscchiwater;
572 sp->isp_stats[ISP_FPCCHIWAT] = isp->isp_fpcchiwater;
580 isp->isp_intbogus = 0;
581 isp->isp_intmboxc = 0;
582 isp->isp_intoasync = 0;
583 isp->isp_rsltccmplt = 0;
584 isp->isp_fphccmplt = 0;
585 isp->isp_rscchiwater = 0;
586 isp->isp_fpcchiwater = 0;
590 case ISP_FC_GETHINFO:
592 struct isp_hba_device *hba = (struct isp_hba_device *) addr;
593 int chan = hba->fc_channel;
595 if (chan < 0 || chan >= isp->isp_nchan) {
599 hba->fc_fw_major = ISP_FW_MAJORX(isp->isp_fwrev);
600 hba->fc_fw_minor = ISP_FW_MINORX(isp->isp_fwrev);
601 hba->fc_fw_micro = ISP_FW_MICROX(isp->isp_fwrev);
602 hba->fc_nchannels = isp->isp_nchan;
604 hba->fc_nports = MAX_FC_TARG;
605 hba->fc_speed = FCPARAM(isp, hba->fc_channel)->isp_gbspeed;
606 hba->fc_topology = FCPARAM(isp, chan)->isp_topo + 1;
607 hba->fc_loopid = FCPARAM(isp, chan)->isp_loopid;
608 hba->nvram_node_wwn = FCPARAM(isp, chan)->isp_wwnn_nvram;
609 hba->nvram_port_wwn = FCPARAM(isp, chan)->isp_wwpn_nvram;
610 hba->active_node_wwn = FCPARAM(isp, chan)->isp_wwnn;
611 hba->active_port_wwn = FCPARAM(isp, chan)->isp_wwpn;
613 hba->fc_nports = MAX_TARGETS;
615 hba->fc_topology = 0;
616 hba->nvram_node_wwn = 0ull;
617 hba->nvram_port_wwn = 0ull;
618 hba->active_node_wwn = 0ull;
619 hba->active_port_wwn = 0ull;
627 struct isp_fc_tsk_mgmt *fct = (struct isp_fc_tsk_mgmt *) addr;
636 if (chan < 0 || chan >= isp->isp_nchan) {
641 needmarker = retval = 0;
642 loopid = fct->loopid;
645 uint8_t local[QENTRY_LEN];
647 isp24xx_statusreq_t *sp;
648 fcparam *fcp = FCPARAM(isp, chan);
652 for (i = 0; i < MAX_FC_TARG; i++) {
653 lp = &fcp->portdb[i];
654 if (lp->handle == loopid) {
658 if (i == MAX_FC_TARG) {
663 /* XXX VALIDATE LP XXX */
664 tmf = (isp24xx_tmf_t *) local;
665 ISP_MEMZERO(tmf, QENTRY_LEN);
666 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
667 tmf->tmf_header.rqs_entry_count = 1;
668 tmf->tmf_nphdl = lp->handle;
670 tmf->tmf_timeout = 2;
671 tmf->tmf_tidlo = lp->portid;
672 tmf->tmf_tidhi = lp->portid >> 16;
673 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
674 tmf->tmf_lun[1] = fct->lun & 0xff;
675 if (fct->lun >= 256) {
676 tmf->tmf_lun[0] = 0x40 | (fct->lun >> 8);
678 switch (fct->action) {
680 tmf->tmf_flags = ISP24XX_TMF_CLEAR_ACA;
682 case IPT_TARGET_RESET:
683 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
687 tmf->tmf_flags = ISP24XX_TMF_LUN_RESET;
690 case IPT_CLEAR_TASK_SET:
691 tmf->tmf_flags = ISP24XX_TMF_CLEAR_TASK_SET;
694 case IPT_ABORT_TASK_SET:
695 tmf->tmf_flags = ISP24XX_TMF_ABORT_TASK_SET;
706 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
707 mbs.param[1] = QENTRY_LEN;
708 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
709 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
710 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
711 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
713 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
718 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
719 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
720 sp = (isp24xx_statusreq_t *) local;
721 sp->req_completion_status = 1;
722 retval = isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
723 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
724 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
725 FC_SCRATCH_RELEASE(isp, chan);
726 if (retval || sp->req_completion_status != 0) {
727 FC_SCRATCH_RELEASE(isp, chan);
736 MBSINIT(&mbs, 0, MBLOGALL, 0);
737 if (ISP_CAP_2KLOGIN(isp) == 0) {
740 switch (fct->action) {
742 mbs.param[0] = MBOX_CLEAR_ACA;
743 mbs.param[1] = loopid;
744 mbs.param[2] = fct->lun;
746 case IPT_TARGET_RESET:
747 mbs.param[0] = MBOX_TARGET_RESET;
748 mbs.param[1] = loopid;
752 mbs.param[0] = MBOX_LUN_RESET;
753 mbs.param[1] = loopid;
754 mbs.param[2] = fct->lun;
757 case IPT_CLEAR_TASK_SET:
758 mbs.param[0] = MBOX_CLEAR_TASK_SET;
759 mbs.param[1] = loopid;
760 mbs.param[2] = fct->lun;
763 case IPT_ABORT_TASK_SET:
764 mbs.param[0] = MBOX_ABORT_TASK_SET;
765 mbs.param[1] = loopid;
766 mbs.param[2] = fct->lun;
775 FCPARAM(isp, chan)->sendmarker = 1;
777 retval = isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
793 isp_intr_enable(void *arg)
796 ispsoftc_t *isp = arg;
798 for (chan = 0; chan < isp->isp_nchan; chan++) {
800 if (FCPARAM(isp, chan)->role != ISP_ROLE_NONE) {
801 ISP_ENABLE_INTS(isp);
805 if (SDPARAM(isp, chan)->role != ISP_ROLE_NONE) {
806 ISP_ENABLE_INTS(isp);
811 isp->isp_osinfo.ehook_active = 0;
813 /* Release our hook so that the boot can continue. */
814 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
821 static ISP_INLINE int isp_get_pcmd(ispsoftc_t *, union ccb *);
822 static ISP_INLINE void isp_free_pcmd(ispsoftc_t *, union ccb *);
824 static ISP_INLINE int
825 isp_get_pcmd(ispsoftc_t *isp, union ccb *ccb)
827 ISP_PCMD(ccb) = isp->isp_osinfo.pcmd_free;
828 if (ISP_PCMD(ccb) == NULL) {
831 isp->isp_osinfo.pcmd_free = ((struct isp_pcmd *)ISP_PCMD(ccb))->next;
835 static ISP_INLINE void
836 isp_free_pcmd(ispsoftc_t *isp, union ccb *ccb)
839 #ifdef ISP_TARGET_MODE
840 PISP_PCMD(ccb)->datalen = 0;
841 PISP_PCMD(ccb)->totslen = 0;
842 PISP_PCMD(ccb)->cumslen = 0;
843 PISP_PCMD(ccb)->crn = 0;
845 PISP_PCMD(ccb)->next = isp->isp_osinfo.pcmd_free;
846 isp->isp_osinfo.pcmd_free = ISP_PCMD(ccb);
847 ISP_PCMD(ccb) = NULL;
852 * Put the target mode functions here, because some are inlines
854 #ifdef ISP_TARGET_MODE
855 static ISP_INLINE void isp_tmlock(ispsoftc_t *, const char *);
856 static ISP_INLINE void isp_tmunlk(ispsoftc_t *);
857 static ISP_INLINE int is_any_lun_enabled(ispsoftc_t *, int);
858 static ISP_INLINE int is_lun_enabled(ispsoftc_t *, int, lun_id_t);
859 static ISP_INLINE tstate_t *get_lun_statep(ispsoftc_t *, int, lun_id_t);
860 static ISP_INLINE tstate_t *get_lun_statep_from_tag(ispsoftc_t *, int, uint32_t);
861 static ISP_INLINE void rls_lun_statep(ispsoftc_t *, tstate_t *);
862 static ISP_INLINE inot_private_data_t *get_ntp_from_tagdata(ispsoftc_t *, uint32_t, uint32_t, tstate_t **);
863 static ISP_INLINE atio_private_data_t *isp_get_atpd(ispsoftc_t *, tstate_t *, uint32_t);
864 static ISP_INLINE atio_private_data_t *isp_find_atpd(ispsoftc_t *, tstate_t *, uint32_t);
865 static ISP_INLINE void isp_put_atpd(ispsoftc_t *, tstate_t *, atio_private_data_t *);
866 static ISP_INLINE inot_private_data_t *isp_get_ntpd(ispsoftc_t *, tstate_t *);
867 static ISP_INLINE inot_private_data_t *isp_find_ntpd(ispsoftc_t *, tstate_t *, uint32_t, uint32_t);
868 static ISP_INLINE void isp_put_ntpd(ispsoftc_t *, tstate_t *, inot_private_data_t *);
869 static cam_status create_lun_state(ispsoftc_t *, int, struct cam_path *, tstate_t **);
870 static void destroy_lun_state(ispsoftc_t *, tstate_t *);
871 static void isp_enable_lun(ispsoftc_t *, union ccb *);
872 static cam_status isp_enable_deferred_luns(ispsoftc_t *, int);
873 static cam_status isp_enable_deferred(ispsoftc_t *, int, lun_id_t);
874 static void isp_disable_lun(ispsoftc_t *, union ccb *);
875 static int isp_enable_target_mode(ispsoftc_t *, int);
876 static int isp_disable_target_mode(ispsoftc_t *, int);
877 static void isp_ledone(ispsoftc_t *, lun_entry_t *);
878 static timeout_t isp_refire_putback_atio;
879 static timeout_t isp_refire_notify_ack;
880 static void isp_complete_ctio(union ccb *);
881 static void isp_target_putback_atio(union ccb *);
882 enum Start_Ctio_How { FROM_CAM, FROM_TIMER, FROM_SRR, FROM_CTIO_DONE };
883 static void isp_target_start_ctio(ispsoftc_t *, union ccb *, enum Start_Ctio_How);
884 static void isp_handle_platform_atio(ispsoftc_t *, at_entry_t *);
885 static void isp_handle_platform_atio2(ispsoftc_t *, at2_entry_t *);
886 static void isp_handle_platform_atio7(ispsoftc_t *, at7_entry_t *);
887 static void isp_handle_platform_ctio(ispsoftc_t *, void *);
888 static void isp_handle_platform_notify_scsi(ispsoftc_t *, in_entry_t *);
889 static void isp_handle_platform_notify_fc(ispsoftc_t *, in_fcentry_t *);
890 static void isp_handle_platform_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *);
891 static int isp_handle_platform_target_notify_ack(ispsoftc_t *, isp_notify_t *);
892 static void isp_handle_platform_target_tmf(ispsoftc_t *, isp_notify_t *);
893 static void isp_target_mark_aborted(ispsoftc_t *, union ccb *);
894 static void isp_target_mark_aborted_early(ispsoftc_t *, tstate_t *, uint32_t);
896 static ISP_INLINE void
897 isp_tmlock(ispsoftc_t *isp, const char *msg)
899 while (isp->isp_osinfo.tmbusy) {
900 isp->isp_osinfo.tmwanted = 1;
901 mtx_sleep(isp, &isp->isp_lock, PRIBIO, msg, 0);
903 isp->isp_osinfo.tmbusy = 1;
906 static ISP_INLINE void
907 isp_tmunlk(ispsoftc_t *isp)
909 isp->isp_osinfo.tmbusy = 0;
910 if (isp->isp_osinfo.tmwanted) {
911 isp->isp_osinfo.tmwanted = 0;
916 static ISP_INLINE int
917 is_any_lun_enabled(ispsoftc_t *isp, int bus)
922 for (i = 0; i < LUN_HASH_SIZE; i++) {
923 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
924 if (SLIST_FIRST(lhp))
930 static ISP_INLINE int
931 is_lun_enabled(ispsoftc_t *isp, int bus, lun_id_t lun)
936 ISP_GET_PC_ADDR(isp, bus, lun_hash[LUN_HASH_FUNC(lun)], lhp);
937 SLIST_FOREACH(tptr, lhp, next) {
938 if (tptr->ts_lun == lun) {
946 dump_tstates(ispsoftc_t *isp, int bus)
950 tstate_t *tptr = NULL;
952 if (bus >= isp->isp_nchan) {
955 for (i = 0; i < LUN_HASH_SIZE; i++) {
956 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
958 SLIST_FOREACH(tptr, lhp, next) {
959 xpt_print(tptr->owner, "[%d, %d] atio_cnt=%d inot_cnt=%d\n", i, j, tptr->atio_count, tptr->inot_count);
965 static ISP_INLINE tstate_t *
966 get_lun_statep(ispsoftc_t *isp, int bus, lun_id_t lun)
968 tstate_t *tptr = NULL;
971 if (bus < isp->isp_nchan) {
972 ISP_GET_PC_ADDR(isp, bus, lun_hash[LUN_HASH_FUNC(lun)], lhp);
973 SLIST_FOREACH(tptr, lhp, next) {
974 if (tptr->ts_lun == lun) {
983 static ISP_INLINE tstate_t *
984 get_lun_statep_from_tag(ispsoftc_t *isp, int bus, uint32_t tagval)
986 tstate_t *tptr = NULL;
987 atio_private_data_t *atp;
991 if (bus < isp->isp_nchan && tagval != 0) {
992 for (i = 0; i < LUN_HASH_SIZE; i++) {
993 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
994 SLIST_FOREACH(tptr, lhp, next) {
995 atp = isp_find_atpd(isp, tptr, tagval);
1006 static ISP_INLINE inot_private_data_t *
1007 get_ntp_from_tagdata(ispsoftc_t *isp, uint32_t tag_id, uint32_t seq_id, tstate_t **rslt)
1009 inot_private_data_t *ntp;
1014 for (bus = 0; bus < isp->isp_nchan; bus++) {
1015 for (i = 0; i < LUN_HASH_SIZE; i++) {
1016 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
1017 SLIST_FOREACH(tptr, lhp, next) {
1018 ntp = isp_find_ntpd(isp, tptr, tag_id, seq_id);
1030 static ISP_INLINE void
1031 rls_lun_statep(ispsoftc_t *isp, tstate_t *tptr)
1033 KASSERT((tptr->hold), ("tptr not held"));
1038 isp_tmcmd_restart(ispsoftc_t *isp)
1040 inot_private_data_t *ntp;
1041 inot_private_data_t *restart_queue;
1047 for (bus = 0; bus < isp->isp_nchan; bus++) {
1048 for (i = 0; i < LUN_HASH_SIZE; i++) {
1049 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
1050 SLIST_FOREACH(tptr, lhp, next) {
1051 if ((restart_queue = tptr->restart_queue) != NULL)
1052 tptr->restart_queue = NULL;
1053 while (restart_queue) {
1054 ntp = restart_queue;
1055 restart_queue = ntp->rd.nt.nt_hba;
1057 isp_prt(isp, ISP_LOGTDEBUG0, "%s: restarting resrc deprived %x", __func__, ((at7_entry_t *)ntp->rd.data)->at_rxid);
1058 isp_handle_platform_atio7(isp, (at7_entry_t *) ntp->rd.data);
1060 isp_prt(isp, ISP_LOGTDEBUG0, "%s: restarting resrc deprived %x", __func__, ((at2_entry_t *)ntp->rd.data)->at_rxid);
1061 isp_handle_platform_atio2(isp, (at2_entry_t *) ntp->rd.data);
1063 isp_put_ntpd(isp, tptr, ntp);
1064 if (tptr->restart_queue && restart_queue != NULL) {
1065 ntp = tptr->restart_queue;
1066 tptr->restart_queue = restart_queue;
1067 while (restart_queue->rd.nt.nt_hba) {
1068 restart_queue = restart_queue->rd.nt.nt_hba;
1070 restart_queue->rd.nt.nt_hba = ntp;
1075 * We only need to do this once per tptr
1077 if (!TAILQ_EMPTY(&tptr->waitq)) {
1078 ccb = (union ccb *)TAILQ_LAST(&tptr->waitq, isp_ccbq);
1079 TAILQ_REMOVE(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1080 isp_target_start_ctio(isp, ccb, FROM_TIMER);
1087 static ISP_INLINE atio_private_data_t *
1088 isp_get_atpd(ispsoftc_t *isp, tstate_t *tptr, uint32_t tag)
1090 atio_private_data_t *atp;
1092 atp = LIST_FIRST(&tptr->atfree);
1094 LIST_REMOVE(atp, next);
1096 LIST_INSERT_HEAD(&tptr->atused[ATPDPHASH(tag)], atp, next);
1101 static ISP_INLINE atio_private_data_t *
1102 isp_find_atpd(ispsoftc_t *isp, tstate_t *tptr, uint32_t tag)
1104 atio_private_data_t *atp;
1106 LIST_FOREACH(atp, &tptr->atused[ATPDPHASH(tag)], next) {
1107 if (atp->tag == tag)
1113 static ISP_INLINE void
1114 isp_put_atpd(ispsoftc_t *isp, tstate_t *tptr, atio_private_data_t *atp)
1117 isp_put_ecmd(isp, atp->ests);
1119 LIST_REMOVE(atp, next);
1120 memset(atp, 0, sizeof (*atp));
1121 LIST_INSERT_HEAD(&tptr->atfree, atp, next);
1125 isp_dump_atpd(ispsoftc_t *isp, tstate_t *tptr)
1127 atio_private_data_t *atp;
1128 const char *states[8] = { "Free", "ATIO", "CAM", "CTIO", "LAST_CTIO", "PDON", "?6", "7" };
1130 for (atp = tptr->atpool; atp < &tptr->atpool[ATPDPSIZE]; atp++) {
1131 xpt_print(tptr->owner, "ATP: [0x%x] origdlen %u bytes_xfrd %u lun %u nphdl 0x%04x s_id 0x%06x d_id 0x%06x oxid 0x%04x state %s\n",
1132 atp->tag, atp->orig_datalen, atp->bytes_xfered, atp->lun, atp->nphdl, atp->sid, atp->portid, atp->oxid, states[atp->state & 0x7]);
1137 static ISP_INLINE inot_private_data_t *
1138 isp_get_ntpd(ispsoftc_t *isp, tstate_t *tptr)
1140 inot_private_data_t *ntp;
1143 tptr->ntfree = ntp->next;
1148 static ISP_INLINE inot_private_data_t *
1149 isp_find_ntpd(ispsoftc_t *isp, tstate_t *tptr, uint32_t tag_id, uint32_t seq_id)
1151 inot_private_data_t *ntp;
1152 for (ntp = tptr->ntpool; ntp < &tptr->ntpool[ATPDPSIZE]; ntp++) {
1153 if (ntp->rd.tag_id == tag_id && ntp->rd.seq_id == seq_id) {
1160 static ISP_INLINE void
1161 isp_put_ntpd(ispsoftc_t *isp, tstate_t *tptr, inot_private_data_t *ntp)
1163 ntp->rd.tag_id = ntp->rd.seq_id = 0;
1164 ntp->next = tptr->ntfree;
1169 create_lun_state(ispsoftc_t *isp, int bus, struct cam_path *path, tstate_t **rslt)
1177 lun = xpt_path_lun_id(path);
1178 if (lun != CAM_LUN_WILDCARD) {
1179 if (lun >= ISP_MAX_LUNS(isp)) {
1180 return (CAM_LUN_INVALID);
1183 if (is_lun_enabled(isp, bus, lun)) {
1184 return (CAM_LUN_ALRDY_ENA);
1186 tptr = malloc(sizeof (tstate_t), M_DEVBUF, M_NOWAIT|M_ZERO);
1188 return (CAM_RESRC_UNAVAIL);
1191 status = xpt_create_path(&tptr->owner, NULL, xpt_path_path_id(path), xpt_path_target_id(path), lun);
1192 if (status != CAM_REQ_CMP) {
1193 free(tptr, M_DEVBUF);
1196 SLIST_INIT(&tptr->atios);
1197 SLIST_INIT(&tptr->inots);
1198 TAILQ_INIT(&tptr->waitq);
1199 LIST_INIT(&tptr->atfree);
1200 for (i = ATPDPSIZE-1; i >= 0; i--)
1201 LIST_INSERT_HEAD(&tptr->atfree, &tptr->atpool[i], next);
1202 for (i = 0; i < ATPDPHASHSIZE; i++)
1203 LIST_INIT(&tptr->atused[i]);
1204 for (i = 0; i < ATPDPSIZE-1; i++)
1205 tptr->ntpool[i].next = &tptr->ntpool[i+1];
1206 tptr->ntfree = tptr->ntpool;
1208 ISP_GET_PC_ADDR(isp, bus, lun_hash[LUN_HASH_FUNC(lun)], lhp);
1209 SLIST_INSERT_HEAD(lhp, tptr, next);
1211 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, path, "created tstate\n");
1212 return (CAM_REQ_CMP);
1215 static ISP_INLINE void
1216 destroy_lun_state(ispsoftc_t *isp, tstate_t *tptr)
1221 KASSERT((tptr->hold != 0), ("tptr is not held"));
1222 KASSERT((tptr->hold == 1), ("tptr still held (%d)", tptr->hold));
1224 ccb = (union ccb *)SLIST_FIRST(&tptr->atios);
1226 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1227 ccb->ccb_h.status = CAM_REQ_ABORTED;
1232 ccb = (union ccb *)SLIST_FIRST(&tptr->inots);
1234 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
1235 ccb->ccb_h.status = CAM_REQ_ABORTED;
1239 ISP_GET_PC_ADDR(isp, cam_sim_bus(xpt_path_sim(tptr->owner)), lun_hash[LUN_HASH_FUNC(tptr->ts_lun)], lhp);
1240 SLIST_REMOVE(lhp, tptr, tstate, next);
1241 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, tptr->owner, "destroyed tstate\n");
1242 xpt_free_path(tptr->owner);
1243 free(tptr, M_DEVBUF);
1250 isp_enable_lun(ispsoftc_t *isp, union ccb *ccb)
1252 tstate_t *tptr = NULL;
1253 int bus, tm_enabled, target_role;
1259 * We only support either a wildcard target/lun or a target ID of zero and a non-wildcard lun
1261 bus = XS_CHANNEL(ccb);
1262 target = ccb->ccb_h.target_id;
1263 lun = ccb->ccb_h.target_lun;
1264 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0|ISP_LOGCONFIG, ccb->ccb_h.path, "enabling lun %u\n", lun);
1265 if (target != CAM_TARGET_WILDCARD && target != 0) {
1266 ccb->ccb_h.status = CAM_TID_INVALID;
1270 if (target == CAM_TARGET_WILDCARD && lun != CAM_LUN_WILDCARD) {
1271 ccb->ccb_h.status = CAM_LUN_INVALID;
1276 if (target != CAM_TARGET_WILDCARD && lun == CAM_LUN_WILDCARD) {
1277 ccb->ccb_h.status = CAM_LUN_INVALID;
1281 if (isp->isp_dblev & ISP_LOGTDEBUG0) {
1282 xpt_print(ccb->ccb_h.path, "enabling lun 0x%x on channel %d\n", lun, bus);
1286 * Wait until we're not busy with the lun enables subsystem
1288 isp_tmlock(isp, "isp_enable_lun");
1291 * This is as a good a place as any to check f/w capabilities.
1295 if (ISP_CAP_TMODE(isp) == 0) {
1296 xpt_print(ccb->ccb_h.path, "firmware does not support target mode\n");
1297 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1301 * We *could* handle non-SCCLUN f/w, but we'd have to
1302 * dork with our already fragile enable/disable code.
1304 if (ISP_CAP_SCCFW(isp) == 0) {
1305 xpt_print(ccb->ccb_h.path, "firmware not SCCLUN capable\n");
1306 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1310 target_role = (FCPARAM(isp, bus)->role & ISP_ROLE_TARGET) != 0;
1313 target_role = (SDPARAM(isp, bus)->role & ISP_ROLE_TARGET) != 0;
1317 * Create the state pointer.
1318 * It should not already exist.
1320 tptr = get_lun_statep(isp, bus, lun);
1322 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
1325 ccb->ccb_h.status = create_lun_state(isp, bus, ccb->ccb_h.path, &tptr);
1326 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1331 * We have a tricky maneuver to perform here.
1333 * If target mode isn't already enabled here,
1334 * *and* our current role includes target mode,
1335 * we enable target mode here.
1338 ISP_GET_PC(isp, bus, tm_enabled, tm_enabled);
1339 if (tm_enabled == 0 && target_role != 0) {
1340 if (isp_enable_target_mode(isp, bus)) {
1341 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1342 destroy_lun_state(isp, tptr);
1350 * Now check to see whether this bus is in target mode already.
1352 * If not, a later role change into target mode will finish the job.
1354 if (tm_enabled == 0) {
1355 ISP_SET_PC(isp, bus, tm_enable_defer, 1);
1356 ccb->ccb_h.status = CAM_REQ_CMP;
1357 xpt_print(ccb->ccb_h.path, "Target Mode not enabled yet- lun enable deferred\n");
1364 ccb->ccb_h.status = isp_enable_deferred(isp, bus, lun);
1367 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1369 destroy_lun_state(isp, tptr);
1377 rls_lun_statep(isp, tptr);
1381 * And we're outta here....
1388 isp_enable_deferred_luns(ispsoftc_t *isp, int bus)
1390 tstate_t *tptr = NULL;
1395 ISP_GET_PC(isp, bus, tm_enabled, i);
1397 return (CAM_REQ_CMP);
1399 ISP_GET_PC(isp, bus, tm_enable_defer, i);
1401 return (CAM_REQ_CMP);
1404 * If this succeeds, it will set tm_enable
1406 if (isp_enable_target_mode(isp, bus)) {
1407 return (CAM_REQ_CMP_ERR);
1409 isp_tmlock(isp, "isp_enable_deferred_luns");
1410 for (n = i = 0; i < LUN_HASH_SIZE; i++) {
1411 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
1412 SLIST_FOREACH(tptr, lhp, next) {
1414 if (tptr->enabled == 0) {
1415 if (isp_enable_deferred(isp, bus, tptr->ts_lun) == CAM_REQ_CMP) {
1427 return (CAM_REQ_CMP_ERR);
1429 ISP_SET_PC(isp, bus, tm_enable_defer, 0);
1430 return (CAM_REQ_CMP);
1434 isp_enable_deferred(ispsoftc_t *isp, int bus, lun_id_t lun)
1437 int luns_already_enabled;
1439 ISP_GET_PC(isp, bus, tm_luns_enabled, luns_already_enabled);
1440 isp_prt(isp, ISP_LOGTINFO, "%s: bus %d lun %u luns_enabled %d", __func__, bus, lun, luns_already_enabled);
1441 if (IS_24XX(isp) || (IS_FC(isp) && luns_already_enabled)) {
1442 status = CAM_REQ_CMP;
1444 int cmd_cnt, not_cnt;
1447 cmd_cnt = DFLT_CMND_CNT;
1448 not_cnt = DFLT_INOT_CNT;
1453 status = CAM_REQ_INPROG;
1454 isp->isp_osinfo.rptr = &status;
1455 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun == CAM_LUN_WILDCARD? 0 : lun, cmd_cnt, not_cnt)) {
1456 status = CAM_RESRC_UNAVAIL;
1458 mtx_sleep(&status, &isp->isp_lock, PRIBIO, "isp_enable_deferred", 0);
1460 isp->isp_osinfo.rptr = NULL;
1462 if (status == CAM_REQ_CMP) {
1463 ISP_SET_PC(isp, bus, tm_luns_enabled, 1);
1464 isp_prt(isp, ISP_LOGCONFIG|ISP_LOGTINFO, "bus %d lun %u now enabled for target mode", bus, lun);
1470 isp_disable_lun(ispsoftc_t *isp, union ccb *ccb)
1472 tstate_t *tptr = NULL;
1478 bus = XS_CHANNEL(ccb);
1479 target = ccb->ccb_h.target_id;
1480 lun = ccb->ccb_h.target_lun;
1481 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0|ISP_LOGCONFIG, ccb->ccb_h.path, "disabling lun %u\n", lun);
1482 if (target != CAM_TARGET_WILDCARD && target != 0) {
1483 ccb->ccb_h.status = CAM_TID_INVALID;
1488 if (target == CAM_TARGET_WILDCARD && lun != CAM_LUN_WILDCARD) {
1489 ccb->ccb_h.status = CAM_LUN_INVALID;
1494 if (target != CAM_TARGET_WILDCARD && lun == CAM_LUN_WILDCARD) {
1495 ccb->ccb_h.status = CAM_LUN_INVALID;
1501 * See if we're busy disabling a lun now.
1503 isp_tmlock(isp, "isp_disable_lun");
1504 status = CAM_REQ_INPROG;
1507 * Find the state pointer.
1509 if ((tptr = get_lun_statep(isp, bus, lun)) == NULL) {
1510 status = CAM_PATH_INVALID;
1515 * If we're a 24XX card, we're done.
1518 status = CAM_REQ_CMP;
1523 * For SCC FW, we only deal with lun zero.
1525 if (IS_FC(isp) && lun > 0) {
1526 status = CAM_REQ_CMP;
1529 isp->isp_osinfo.rptr = &status;
1530 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun, 0, 0)) {
1531 status = CAM_RESRC_UNAVAIL;
1533 mtx_sleep(ccb, &isp->isp_lock, PRIBIO, "isp_disable_lun", 0);
1535 isp->isp_osinfo.rptr = NULL;
1537 if (status == CAM_REQ_CMP) {
1540 * If we have no more luns enabled for this bus,
1541 * delete all tracked wwns for it (if we are FC),
1542 * and disable target mode.
1544 if (is_any_lun_enabled(isp, bus) == 0) {
1545 isp_del_all_wwn_entries(isp, bus);
1546 if (isp_disable_target_mode(isp, bus)) {
1547 status = CAM_REQ_CMP_ERR;
1551 ccb->ccb_h.status = status;
1552 if (status == CAM_REQ_CMP) {
1553 destroy_lun_state(isp, tptr);
1554 xpt_print(ccb->ccb_h.path, "lun now disabled for target mode\n");
1557 rls_lun_statep(isp, tptr);
1564 isp_enable_target_mode(ispsoftc_t *isp, int bus)
1568 ISP_GET_PC(isp, bus, tm_enabled, tm_enabled);
1569 if (tm_enabled != 0) {
1574 MBSINIT(&mbs, MBOX_ENABLE_TARGET_MODE, MBLOGALL, 0);
1575 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
1576 mbs.param[1] = ENABLE_TARGET_FLAG|ENABLE_TQING_FLAG;
1577 mbs.param[2] = bus << 7;
1578 if (isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs) < 0 || mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1579 isp_prt(isp, ISP_LOGERR, "Unable to enable Target Role on Bus %d", bus);
1583 ISP_SET_PC(isp, bus, tm_enabled, 1);
1584 isp_prt(isp, ISP_LOGINFO, "Target Role enabled on Bus %d", bus);
1589 isp_disable_target_mode(ispsoftc_t *isp, int bus)
1593 ISP_GET_PC(isp, bus, tm_enabled, tm_enabled);
1594 if (tm_enabled == 0) {
1599 MBSINIT(&mbs, MBOX_ENABLE_TARGET_MODE, MBLOGALL, 0);
1600 mbs.param[2] = bus << 7;
1601 if (isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs) < 0 || mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1602 isp_prt(isp, ISP_LOGERR, "Unable to disable Target Role on Bus %d", bus);
1606 ISP_SET_PC(isp, bus, tm_enabled, 0);
1607 isp_prt(isp, ISP_LOGINFO, "Target Role disabled on Bus %d", bus);
1612 isp_ledone(ispsoftc_t *isp, lun_entry_t *lep)
1616 rptr = isp->isp_osinfo.rptr;
1617 if (lep->le_status != LUN_OK) {
1618 isp_prt(isp, ISP_LOGERR, "ENABLE/MODIFY LUN returned 0x%x", lep->le_status);
1620 *rptr = CAM_REQ_CMP_ERR;
1625 *rptr = CAM_REQ_CMP;
1632 isp_target_start_ctio(ispsoftc_t *isp, union ccb *ccb, enum Start_Ctio_How how)
1634 int fctape, sendstatus, resid;
1637 atio_private_data_t *atp;
1638 struct ccb_scsiio *cso;
1639 uint32_t dmaresult, handle, xfrlen, sense_length, tmp;
1640 uint8_t local[QENTRY_LEN];
1642 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), XS_LUN(ccb));
1644 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), CAM_LUN_WILDCARD);
1646 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] cannot find tstate pointer", __func__, ccb->csio.tag_id);
1647 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
1652 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,
1653 (ccb->ccb_h.flags & CAM_SEND_STATUS) != 0, ((ccb->ccb_h.flags & CAM_SEND_SENSE)? ccb->csio.sense_len : 0));
1659 * Insert at the tail of the list, if any, waiting CTIO CCBs
1661 TAILQ_INSERT_TAIL(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1664 case FROM_CTIO_DONE:
1665 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1669 while (TAILQ_FIRST(&tptr->waitq) != NULL) {
1670 ccb = (union ccb *) TAILQ_FIRST(&tptr->waitq);
1671 TAILQ_REMOVE(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1674 xfrlen = cso->dxfer_len;
1676 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
1677 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "a data transfer length of zero but no status to send is wrong\n");
1678 ccb->ccb_h.status = CAM_REQ_INVALID;
1684 atp = isp_find_atpd(isp, tptr, cso->tag_id);
1686 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] cannot find private data adjunct in %s", __func__, cso->tag_id, __func__);
1687 isp_dump_atpd(isp, tptr);
1688 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1694 * Is this command a dead duck?
1697 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] not sending a CTIO for a dead command", __func__, cso->tag_id);
1698 ccb->ccb_h.status = CAM_REQ_ABORTED;
1704 * Check to make sure we're still in target mode.
1706 fcp = FCPARAM(isp, XS_CHANNEL(ccb));
1707 if ((fcp->role & ISP_ROLE_TARGET) == 0) {
1708 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] stopping sending a CTIO because we're no longer in target mode", __func__, cso->tag_id);
1709 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1715 * We're only handling ATPD_CCB_OUTSTANDING outstanding CCB at a time (one of which
1716 * could be split into two CTIOs to split data and status).
1718 if (atp->ctcnt >= ATPD_CCB_OUTSTANDING) {
1719 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);
1720 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1725 * Does the initiator expect FC-Tape style responses?
1727 if ((atp->word3 & PRLI_WD3_RETRY) && fcp->fctape_enabled) {
1734 * If we already did the data xfer portion of a CTIO that sends data
1735 * and status, don't do it again and do the status portion now.
1738 isp_prt(isp, ISP_LOGTINFO, "[0x%x] now sending synthesized status orig_dl=%u xfered=%u bit=%u",
1739 cso->tag_id, atp->orig_datalen, atp->bytes_xfered, atp->bytes_in_transit);
1740 xfrlen = 0; /* we already did the data transfer */
1743 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1749 if (ccb->ccb_h.flags & CAM_SEND_SENSE) {
1750 KASSERT((sendstatus != 0), ("how can you have CAM_SEND_SENSE w/o CAM_SEND_STATUS?"));
1752 * Sense length is not the entire sense data structure size. Periph
1753 * drivers don't seem to be setting sense_len to reflect the actual
1754 * size. We'll peek inside to get the right amount.
1756 sense_length = cso->sense_len;
1759 * This 'cannot' happen
1761 if (sense_length > (XCMD_SIZE - MIN_FCP_RESPONSE_SIZE)) {
1762 sense_length = XCMD_SIZE - MIN_FCP_RESPONSE_SIZE;
1768 memset(local, 0, QENTRY_LEN);
1771 * Check for overflow
1773 tmp = atp->bytes_xfered + atp->bytes_in_transit + xfrlen;
1774 if (tmp > atp->orig_datalen) {
1775 isp_prt(isp, ISP_LOGERR, "%s: [0x%x] data overflow by %u bytes", __func__, cso->tag_id, tmp - atp->orig_datalen);
1776 ccb->ccb_h.status = CAM_DATA_RUN_ERR;
1782 ct7_entry_t *cto = (ct7_entry_t *) local;
1784 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
1785 cto->ct_header.rqs_entry_count = 1;
1786 cto->ct_header.rqs_seqno |= ATPD_SEQ_NOTIFY_CAM;
1787 ATPD_SET_SEQNO(cto, atp);
1788 cto->ct_nphdl = atp->nphdl;
1789 cto->ct_rxid = atp->tag;
1790 cto->ct_iid_lo = atp->portid;
1791 cto->ct_iid_hi = atp->portid >> 16;
1792 cto->ct_oxid = atp->oxid;
1793 cto->ct_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(ccb));
1794 cto->ct_timeout = 120;
1795 cto->ct_flags = atp->tattr << CT7_TASK_ATTR_SHIFT;
1798 * Mode 1, status, no data. Only possible when we are sending status, have
1799 * no data to transfer, and any sense data can fit into a ct7_entry_t.
1801 * Mode 2, status, no data. We have to use this in the case that
1802 * the sense data won't fit into a ct7_entry_t.
1805 if (sendstatus && xfrlen == 0) {
1806 cto->ct_flags |= CT7_SENDSTATUS | CT7_NO_DATA;
1807 resid = atp->orig_datalen - atp->bytes_xfered - atp->bytes_in_transit;
1808 if (sense_length <= MAXRESPLEN_24XX) {
1810 cto->ct_resid = -resid;
1811 } else if (resid > 0) {
1812 cto->ct_resid = resid;
1814 cto->ct_flags |= CT7_FLAG_MODE1;
1815 cto->ct_scsi_status = cso->scsi_status;
1817 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
1818 } else if (resid > 0) {
1819 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
1822 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1825 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
1826 cto->rsp.m1.ct_resplen = cto->ct_senselen = sense_length;
1827 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, sense_length);
1831 char buf[XCMD_SIZE];
1834 if (atp->ests == NULL) {
1835 atp->ests = isp_get_ecmd(isp);
1836 if (atp->ests == NULL) {
1837 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1841 memset(buf, 0, sizeof (buf));
1842 rp = (fcp_rsp_iu_t *)buf;
1844 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1845 rp->fcp_rsp_bits |= FCP_CONF_REQ;
1847 cto->ct_flags |= CT7_FLAG_MODE2;
1848 rp->fcp_rsp_scsi_status = cso->scsi_status;
1850 rp->fcp_rsp_resid = -resid;
1851 rp->fcp_rsp_bits |= FCP_RESID_OVERFLOW;
1852 } else if (resid > 0) {
1853 rp->fcp_rsp_resid = resid;
1854 rp->fcp_rsp_bits |= FCP_RESID_UNDERFLOW;
1857 rp->fcp_rsp_snslen = sense_length;
1858 cto->ct_senselen = sense_length;
1859 rp->fcp_rsp_bits |= FCP_SNSLEN_VALID;
1860 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1861 memcpy(((fcp_rsp_iu_t *)atp->ests)->fcp_rsp_extra, &cso->sense_data, sense_length);
1863 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1865 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
1866 isp_print_bytes(isp, "FCP Response Frame After Swizzling", MIN_FCP_RESPONSE_SIZE + sense_length, atp->ests);
1868 addr = isp->isp_osinfo.ecmd_dma;
1869 addr += ((((isp_ecmd_t *)atp->ests) - isp->isp_osinfo.ecmd_base) * XCMD_SIZE);
1870 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,
1871 (uintmax_t) isp->isp_osinfo.ecmd_dma, (uintmax_t)addr, MIN_FCP_RESPONSE_SIZE + sense_length);
1872 cto->rsp.m2.ct_datalen = MIN_FCP_RESPONSE_SIZE + sense_length;
1873 cto->rsp.m2.ct_fcp_rsp_iudata.ds_base = DMA_LO32(addr);
1874 cto->rsp.m2.ct_fcp_rsp_iudata.ds_basehi = DMA_HI32(addr);
1875 cto->rsp.m2.ct_fcp_rsp_iudata.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
1878 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO7[0x%x] seq %u nc %d CDB0=%x sstatus=0x%x flags=0x%x resid=%d slen %u sense: %x %x/%x/%x", __func__,
1879 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,
1880 cso->sense_data.error_code, cso->sense_data.sense_buf[1], cso->sense_data.sense_buf[11], cso->sense_data.sense_buf[12]);
1882 isp_prt(isp, ISP_LOGDEBUG0, "%s: CTIO7[0x%x] seq %u nc %d CDB0=%x sstatus=0x%x flags=0x%x resid=%d", __func__,
1883 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid);
1885 atp->state = ATPD_STATE_LAST_CTIO;
1889 * Mode 0 data transfers, *possibly* with status.
1892 cto->ct_flags |= CT7_FLAG_MODE0;
1893 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1894 cto->ct_flags |= CT7_DATA_IN;
1896 cto->ct_flags |= CT7_DATA_OUT;
1899 cto->rsp.m0.reloff = atp->bytes_xfered + atp->bytes_in_transit;
1900 cto->rsp.m0.ct_xfrlen = xfrlen;
1903 if (ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame && xfrlen > ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame) {
1904 isp_prt(isp, ISP_LOGWARN, "%s: truncating data frame with xfrlen %d to %d", __func__, xfrlen, xfrlen - (xfrlen >> 2));
1905 ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame = 0;
1906 cto->rsp.m0.ct_xfrlen -= xfrlen >> 2;
1910 resid = atp->orig_datalen - atp->bytes_xfered - xfrlen;
1911 if (cso->scsi_status == SCSI_STATUS_OK && resid == 0 /* && fctape == 0 */) {
1912 cto->ct_flags |= CT7_SENDSTATUS;
1913 atp->state = ATPD_STATE_LAST_CTIO;
1915 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1918 atp->sendst = 1; /* send status later */
1919 cto->ct_header.rqs_seqno &= ~ATPD_SEQ_NOTIFY_CAM;
1920 atp->state = ATPD_STATE_CTIO;
1923 atp->state = ATPD_STATE_CTIO;
1925 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO7[0x%x] seq %u nc %d CDB0=%x sstatus=0x%x flags=0x%x xfrlen=%u off=%u", __func__,
1926 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cto->ct_scsi_status, cto->ct_flags, xfrlen, atp->bytes_xfered);
1928 } else if (IS_FC(isp)) {
1929 ct2_entry_t *cto = (ct2_entry_t *) local;
1931 if (isp->isp_osinfo.sixtyfourbit)
1932 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO3;
1934 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1935 cto->ct_header.rqs_entry_count = 1;
1936 cto->ct_header.rqs_seqno |= ATPD_SEQ_NOTIFY_CAM;
1937 ATPD_SET_SEQNO(cto, atp);
1938 if (ISP_CAP_2KLOGIN(isp) == 0) {
1939 ((ct2e_entry_t *)cto)->ct_iid = cso->init_id;
1941 cto->ct_iid = cso->init_id;
1942 if (ISP_CAP_SCCFW(isp) == 0) {
1943 cto->ct_lun = ccb->ccb_h.target_lun;
1946 cto->ct_timeout = 10;
1947 cto->ct_rxid = cso->tag_id;
1950 * Mode 1, status, no data. Only possible when we are sending status, have
1951 * no data to transfer, and the sense length can fit in the ct7_entry.
1953 * Mode 2, status, no data. We have to use this in the case the response
1954 * length won't fit into a ct2_entry_t.
1956 * We'll fill out this structure with information as if this were a
1957 * Mode 1. The hardware layer will create the Mode 2 FCP RSP IU as
1958 * needed based upon this.
1960 if (sendstatus && xfrlen == 0) {
1961 cto->ct_flags |= CT2_SENDSTATUS | CT2_NO_DATA;
1962 resid = atp->orig_datalen - atp->bytes_xfered - atp->bytes_in_transit;
1963 if (sense_length <= MAXRESPLEN) {
1965 cto->ct_resid = -resid;
1966 } else if (resid > 0) {
1967 cto->ct_resid = resid;
1969 cto->ct_flags |= CT2_FLAG_MODE1;
1970 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1972 cto->rsp.m1.ct_scsi_status |= CT2_DATA_OVER;
1973 } else if (resid > 0) {
1974 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
1977 cto->ct_flags |= CT2_CONFIRM;
1980 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1981 cto->rsp.m1.ct_resplen = cto->rsp.m1.ct_senselen = sense_length;
1982 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, sense_length);
1986 char buf[XCMD_SIZE];
1989 if (atp->ests == NULL) {
1990 atp->ests = isp_get_ecmd(isp);
1991 if (atp->ests == NULL) {
1992 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
1996 memset(buf, 0, sizeof (buf));
1997 rp = (fcp_rsp_iu_t *)buf;
1999 cto->ct_flags |= CT2_CONFIRM;
2000 rp->fcp_rsp_bits |= FCP_CONF_REQ;
2002 cto->ct_flags |= CT2_FLAG_MODE2;
2003 rp->fcp_rsp_scsi_status = cso->scsi_status;
2005 rp->fcp_rsp_resid = -resid;
2006 rp->fcp_rsp_bits |= FCP_RESID_OVERFLOW;
2007 } else if (resid > 0) {
2008 rp->fcp_rsp_resid = resid;
2009 rp->fcp_rsp_bits |= FCP_RESID_UNDERFLOW;
2012 rp->fcp_rsp_snslen = sense_length;
2013 rp->fcp_rsp_bits |= FCP_SNSLEN_VALID;
2014 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
2015 memcpy(((fcp_rsp_iu_t *)atp->ests)->fcp_rsp_extra, &cso->sense_data, sense_length);
2017 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
2019 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
2020 isp_print_bytes(isp, "FCP Response Frame After Swizzling", MIN_FCP_RESPONSE_SIZE + sense_length, atp->ests);
2022 addr = isp->isp_osinfo.ecmd_dma;
2023 addr += ((((isp_ecmd_t *)atp->ests) - isp->isp_osinfo.ecmd_base) * XCMD_SIZE);
2024 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,
2025 (uintmax_t) isp->isp_osinfo.ecmd_dma, (uintmax_t)addr, MIN_FCP_RESPONSE_SIZE + sense_length);
2026 cto->rsp.m2.ct_datalen = MIN_FCP_RESPONSE_SIZE + sense_length;
2027 if (isp->isp_osinfo.sixtyfourbit) {
2028 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base = DMA_LO32(addr);
2029 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi = DMA_HI32(addr);
2030 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
2032 cto->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base = DMA_LO32(addr);
2033 cto->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
2037 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO2[0x%x] seq %u nc %d CDB0=%x sstatus=0x%x flags=0x%x resid=%d sense: %x %x/%x/%x", __func__,
2038 cto->ct_rxid, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid,
2039 cso->sense_data.error_code, cso->sense_data.sense_buf[1], cso->sense_data.sense_buf[11], cso->sense_data.sense_buf[12]);
2041 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO2[0x%x] seq %u nc %d CDB0=%x sstatus=0x%x flags=0x%x resid=%d", __func__, cto->ct_rxid,
2042 ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid);
2044 atp->state = ATPD_STATE_LAST_CTIO;
2048 cto->ct_flags |= CT2_FLAG_MODE0;
2049 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
2050 cto->ct_flags |= CT2_DATA_IN;
2052 cto->ct_flags |= CT2_DATA_OUT;
2055 cto->ct_reloff = atp->bytes_xfered + atp->bytes_in_transit;
2056 cto->rsp.m0.ct_xfrlen = xfrlen;
2059 resid = atp->orig_datalen - atp->bytes_xfered - xfrlen;
2060 if (cso->scsi_status == SCSI_STATUS_OK && resid == 0 /*&& fctape == 0*/) {
2061 cto->ct_flags |= CT2_SENDSTATUS;
2062 atp->state = ATPD_STATE_LAST_CTIO;
2064 cto->ct_flags |= CT2_CONFIRM;
2067 atp->sendst = 1; /* send status later */
2068 cto->ct_header.rqs_seqno &= ~ATPD_SEQ_NOTIFY_CAM;
2069 atp->state = ATPD_STATE_CTIO;
2072 atp->state = ATPD_STATE_CTIO;
2075 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO2[%x] seq %u nc %d CDB0=%x scsi status %x flags %x resid %d xfrlen %u offset %u", __func__, cto->ct_rxid,
2076 ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid, cso->dxfer_len, atp->bytes_xfered);
2078 ct_entry_t *cto = (ct_entry_t *) local;
2080 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
2081 cto->ct_header.rqs_entry_count = 1;
2082 cto->ct_header.rqs_seqno |= ATPD_SEQ_NOTIFY_CAM;
2083 ATPD_SET_SEQNO(cto, atp);
2084 cto->ct_iid = cso->init_id;
2085 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
2086 cto->ct_tgt = ccb->ccb_h.target_id;
2087 cto->ct_lun = ccb->ccb_h.target_lun;
2088 cto->ct_fwhandle = cso->tag_id;
2090 cto->ct_tag_val = atp->rxid;
2091 cto->ct_flags |= CT_TQAE;
2093 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
2094 cto->ct_flags |= CT_NODISC;
2096 if (cso->dxfer_len == 0) {
2097 cto->ct_flags |= CT_NO_DATA;
2098 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
2099 cto->ct_flags |= CT_DATA_IN;
2101 cto->ct_flags |= CT_DATA_OUT;
2103 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
2104 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
2105 cto->ct_scsi_status = cso->scsi_status;
2106 cto->ct_resid = atp->orig_datalen - atp->bytes_xfered - atp->bytes_in_transit - xfrlen;
2107 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO[%x] seq %u nc %d scsi status %x resid %d tag_id %x", __func__,
2108 cto->ct_fwhandle, ATPD_GET_SEQNO(cto), ATPD_GET_NCAM(cto), cso->scsi_status, cso->resid, cso->tag_id);
2110 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
2111 cto->ct_timeout = 10;
2114 if (isp_get_pcmd(isp, ccb)) {
2115 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "out of PCMDs\n");
2116 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
2119 if (isp_allocate_xs_tgt(isp, ccb, &handle)) {
2120 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "No XFLIST pointers for %s\n", __func__);
2121 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
2122 isp_free_pcmd(isp, ccb);
2125 atp->bytes_in_transit += xfrlen;
2126 PISP_PCMD(ccb)->datalen = xfrlen;
2130 * Call the dma setup routines for this entry (and any subsequent
2131 * CTIOs) if there's data to move, and then tell the f/w it's got
2132 * new things to play with. As with isp_start's usage of DMA setup,
2133 * any swizzling is done in the machine dependent layer. Because
2134 * of this, we put the request onto the queue area first in native
2139 ct7_entry_t *cto = (ct7_entry_t *) local;
2140 cto->ct_syshandle = handle;
2141 } else if (IS_FC(isp)) {
2142 ct2_entry_t *cto = (ct2_entry_t *) local;
2143 cto->ct_syshandle = handle;
2145 ct_entry_t *cto = (ct_entry_t *) local;
2146 cto->ct_syshandle = handle;
2149 dmaresult = ISP_DMASETUP(isp, cso, (ispreq_t *) local);
2150 if (dmaresult != CMD_QUEUED) {
2151 isp_destroy_tgt_handle(isp, handle);
2152 isp_free_pcmd(isp, ccb);
2153 if (dmaresult == CMD_EAGAIN) {
2154 TAILQ_INSERT_HEAD(&tptr->waitq, &ccb->ccb_h, periph_links.tqe);
2157 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2162 ccb->ccb_h.status = CAM_REQ_INPROG | CAM_SIM_QUEUED;
2164 ccb->ccb_h.spriv_field0 = atp->bytes_xfered;
2166 ccb->ccb_h.spriv_field0 = ~0;
2171 rls_lun_statep(isp, tptr);
2175 isp_refire_putback_atio(void *arg)
2177 union ccb *ccb = arg;
2179 ISP_ASSERT_LOCKED((ispsoftc_t *)XS_ISP(ccb));
2180 isp_target_putback_atio(ccb);
2184 isp_refire_notify_ack(void *arg)
2186 isp_tna_t *tp = arg;
2187 ispsoftc_t *isp = tp->isp;
2189 ISP_ASSERT_LOCKED(isp);
2190 if (isp_notify_ack(isp, tp->not)) {
2191 callout_schedule(&tp->timer, 5);
2199 isp_target_putback_atio(union ccb *ccb)
2202 struct ccb_scsiio *cso;
2207 qe = isp_getrqentry(isp);
2209 xpt_print(ccb->ccb_h.path,
2210 "%s: Request Queue Overflow\n", __func__);
2211 callout_reset(&PISP_PCMD(ccb)->wdog, 10,
2212 isp_refire_putback_atio, ccb);
2215 memset(qe, 0, QENTRY_LEN);
2218 at2_entry_t local, *at = &local;
2219 ISP_MEMZERO(at, sizeof (at2_entry_t));
2220 at->at_header.rqs_entry_type = RQSTYPE_ATIO2;
2221 at->at_header.rqs_entry_count = 1;
2222 if (ISP_CAP_SCCFW(isp)) {
2223 at->at_scclun = (uint16_t) ccb->ccb_h.target_lun;
2225 at->at_lun = (uint8_t) ccb->ccb_h.target_lun;
2227 at->at_status = CT_OK;
2228 at->at_rxid = cso->tag_id;
2229 at->at_iid = cso->ccb_h.target_id;
2230 isp_put_atio2(isp, at, qe);
2232 at_entry_t local, *at = &local;
2233 ISP_MEMZERO(at, sizeof (at_entry_t));
2234 at->at_header.rqs_entry_type = RQSTYPE_ATIO;
2235 at->at_header.rqs_entry_count = 1;
2236 at->at_iid = cso->init_id;
2237 at->at_iid |= XS_CHANNEL(ccb) << 7;
2238 at->at_tgt = cso->ccb_h.target_id;
2239 at->at_lun = cso->ccb_h.target_lun;
2240 at->at_status = CT_OK;
2241 at->at_tag_val = AT_GET_TAG(cso->tag_id);
2242 at->at_handle = AT_GET_HANDLE(cso->tag_id);
2243 isp_put_atio(isp, at, qe);
2245 ISP_TDQE(isp, "isp_target_putback_atio", isp->isp_reqidx, qe);
2246 ISP_SYNC_REQUEST(isp);
2247 isp_complete_ctio(ccb);
2251 isp_complete_ctio(union ccb *ccb)
2253 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
2254 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2260 * Handle ATIO stuff that the generic code can't.
2261 * This means handling CDBs.
2265 isp_handle_platform_atio(ispsoftc_t *isp, at_entry_t *aep)
2269 struct ccb_accept_tio *atiop;
2270 atio_private_data_t *atp;
2273 * The firmware status (except for the QLTM_SVALID bit)
2274 * indicates why this ATIO was sent to us.
2276 * If QLTM_SVALID is set, the firmware has recommended Sense Data.
2278 * If the DISCONNECTS DISABLED bit is set in the flags field,
2279 * we're still connected on the SCSI bus.
2281 status = aep->at_status;
2282 if ((status & ~QLTM_SVALID) == AT_PHASE_ERROR) {
2284 * Bus Phase Sequence error. We should have sense data
2285 * suggested by the f/w. I'm not sure quite yet what
2286 * to do about this for CAM.
2288 isp_prt(isp, ISP_LOGWARN, "PHASE ERROR");
2289 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2292 if ((status & ~QLTM_SVALID) != AT_CDB) {
2293 isp_prt(isp, ISP_LOGWARN, "bad atio (0x%x) leaked to platform", status);
2294 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2298 bus = GET_BUS_VAL(aep->at_iid);
2299 tptr = get_lun_statep(isp, bus, aep->at_lun);
2301 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
2304 * Because we can't autofeed sense data back with
2305 * a command for parallel SCSI, we can't give back
2306 * a CHECK CONDITION. We'll give back a BUSY status
2307 * instead. This works out okay because the only
2308 * time we should, in fact, get this, is in the
2309 * case that somebody configured us without the
2310 * blackhole driver, so they get what they deserve.
2312 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2317 atp = isp_get_atpd(isp, tptr, aep->at_handle);
2318 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
2319 if (atiop == NULL || atp == NULL) {
2321 * Because we can't autofeed sense data back with
2322 * a command for parallel SCSI, we can't give back
2323 * a CHECK CONDITION. We'll give back a QUEUE FULL status
2324 * instead. This works out okay because the only time we
2325 * should, in fact, get this, is in the case that we've
2328 xpt_print(tptr->owner, "no %s for lun %d from initiator %d\n", (atp == NULL && atiop == NULL)? "ATIOs *or* ATPS" :
2329 ((atp == NULL)? "ATPs" : "ATIOs"), aep->at_lun, aep->at_iid);
2330 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2332 isp_put_atpd(isp, tptr, atp);
2334 rls_lun_statep(isp, tptr);
2337 atp->rxid = aep->at_tag_val;
2338 atp->state = ATPD_STATE_ATIO;
2339 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2341 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2342 atiop->ccb_h.target_id = aep->at_tgt;
2343 atiop->ccb_h.target_lun = aep->at_lun;
2344 if (aep->at_flags & AT_NODISC) {
2345 atiop->ccb_h.flags |= CAM_DIS_DISCONNECT;
2347 atiop->ccb_h.flags &= ~CAM_DIS_DISCONNECT;
2350 if (status & QLTM_SVALID) {
2351 size_t amt = ISP_MIN(QLTM_SENSELEN, sizeof (atiop->sense_data));
2352 atiop->sense_len = amt;
2353 ISP_MEMCPY(&atiop->sense_data, aep->at_sense, amt);
2355 atiop->sense_len = 0;
2358 atiop->init_id = GET_IID_VAL(aep->at_iid);
2359 atiop->cdb_len = aep->at_cdblen;
2360 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, aep->at_cdblen);
2361 atiop->ccb_h.status = CAM_CDB_RECVD;
2363 * Construct a tag 'id' based upon tag value (which may be 0..255)
2364 * and the handle (which we have to preserve).
2366 atiop->tag_id = atp->tag;
2367 if (aep->at_flags & AT_TQAE) {
2368 atiop->tag_action = aep->at_tag_type;
2369 atiop->ccb_h.status |= CAM_TAG_ACTION_VALID;
2371 atp->orig_datalen = 0;
2372 atp->bytes_xfered = 0;
2373 atp->lun = aep->at_lun;
2374 atp->nphdl = aep->at_iid;
2375 atp->portid = PORT_NONE;
2377 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2378 atp->tattr = aep->at_tag_type;
2379 atp->state = ATPD_STATE_CAM;
2380 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO[0x%x] CDB=0x%x lun %d", aep->at_tag_val, atp->cdb0, atp->lun);
2381 rls_lun_statep(isp, tptr);
2385 isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
2390 struct ccb_accept_tio *atiop;
2392 atio_private_data_t *atp;
2393 inot_private_data_t *ntp;
2396 * The firmware status (except for the QLTM_SVALID bit)
2397 * indicates why this ATIO was sent to us.
2399 * If QLTM_SVALID is set, the firmware has recommended Sense Data.
2401 if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) {
2402 isp_prt(isp, ISP_LOGWARN, "bogus atio (0x%x) leaked to platform", aep->at_status);
2403 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2407 if (ISP_CAP_SCCFW(isp)) {
2408 lun = aep->at_scclun;
2412 if (ISP_CAP_2KLOGIN(isp)) {
2413 nphdl = ((at2e_entry_t *)aep)->at_iid;
2415 nphdl = aep->at_iid;
2417 tptr = get_lun_statep(isp, 0, lun);
2419 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
2421 isp_prt(isp, ISP_LOGWARN, "%s: [0x%x] no state pointer for lun %d or wildcard", __func__, aep->at_rxid, lun);
2423 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2425 isp_endcmd(isp, aep, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2432 * Start any commands pending resources first.
2434 if (tptr->restart_queue) {
2435 inot_private_data_t *restart_queue = tptr->restart_queue;
2436 tptr->restart_queue = NULL;
2437 while (restart_queue) {
2438 ntp = restart_queue;
2439 restart_queue = ntp->rd.nt.nt_hba;
2440 isp_prt(isp, ISP_LOGTDEBUG0, "%s: restarting resrc deprived %x", __func__, ((at2_entry_t *)ntp->rd.data)->at_rxid);
2441 isp_handle_platform_atio2(isp, (at2_entry_t *) ntp->rd.data);
2442 isp_put_ntpd(isp, tptr, ntp);
2444 * If a recursion caused the restart queue to start to fill again,
2445 * stop and splice the new list on top of the old list and restore
2446 * it and go to noresrc.
2448 if (tptr->restart_queue) {
2449 ntp = tptr->restart_queue;
2450 tptr->restart_queue = restart_queue;
2451 while (restart_queue->rd.nt.nt_hba) {
2452 restart_queue = restart_queue->rd.nt.nt_hba;
2454 restart_queue->rd.nt.nt_hba = ntp;
2460 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
2461 if (atiop == NULL) {
2465 atp = isp_get_atpd(isp, tptr, aep->at_rxid);
2470 atp->state = ATPD_STATE_ATIO;
2471 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2473 isp_prt(isp, ISP_LOGTDEBUG2, "Take FREE ATIO count now %d", tptr->atio_count);
2474 atiop->ccb_h.target_id = FCPARAM(isp, 0)->isp_loopid;
2475 atiop->ccb_h.target_lun = lun;
2478 * We don't get 'suggested' sense data as we do with SCSI cards.
2480 atiop->sense_len = 0;
2481 if (ISP_CAP_2KLOGIN(isp)) {
2483 * NB: We could not possibly have 2K logins if we
2484 * NB: also did not have SCC FW.
2486 atiop->init_id = ((at2e_entry_t *)aep)->at_iid;
2488 atiop->init_id = aep->at_iid;
2492 * If we're not in the port database, add ourselves.
2494 if (!IS_2100(isp) && isp_find_pdb_by_loopid(isp, 0, atiop->init_id, &lp) == 0) {
2496 (((uint64_t) aep->at_wwpn[0]) << 48) |
2497 (((uint64_t) aep->at_wwpn[1]) << 32) |
2498 (((uint64_t) aep->at_wwpn[2]) << 16) |
2499 (((uint64_t) aep->at_wwpn[3]) << 0);
2500 isp_add_wwn_entry(isp, 0, iid, atiop->init_id, PORT_ANY, 0);
2502 atiop->cdb_len = ATIO2_CDBLEN;
2503 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
2504 atiop->ccb_h.status = CAM_CDB_RECVD;
2505 atiop->tag_id = atp->tag;
2506 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
2507 case ATIO2_TC_ATTR_SIMPLEQ:
2508 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2509 atiop->tag_action = MSG_SIMPLE_Q_TAG;
2511 case ATIO2_TC_ATTR_HEADOFQ:
2512 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2513 atiop->tag_action = MSG_HEAD_OF_Q_TAG;
2515 case ATIO2_TC_ATTR_ORDERED:
2516 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2517 atiop->tag_action = MSG_ORDERED_Q_TAG;
2519 case ATIO2_TC_ATTR_ACAQ: /* ?? */
2520 case ATIO2_TC_ATTR_UNTAGGED:
2522 atiop->tag_action = 0;
2526 atp->orig_datalen = aep->at_datalen;
2527 atp->bytes_xfered = 0;
2529 atp->nphdl = atiop->init_id;
2530 atp->sid = PORT_ANY;
2531 atp->oxid = aep->at_oxid;
2532 atp->cdb0 = aep->at_cdb[0];
2533 atp->tattr = aep->at_taskflags & ATIO2_TC_ATTR_MASK;
2534 atp->state = ATPD_STATE_CAM;
2535 xpt_done((union ccb *)atiop);
2536 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO2[0x%x] CDB=0x%x lun %d datalen %u", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2537 rls_lun_statep(isp, tptr);
2540 ntp = isp_get_ntpd(isp, tptr);
2542 rls_lun_statep(isp, tptr);
2543 isp_endcmd(isp, aep, nphdl, 0, SCSI_STATUS_BUSY, 0);
2546 memcpy(ntp->rd.data, aep, QENTRY_LEN);
2547 ntp->rd.nt.nt_hba = tptr->restart_queue;
2548 tptr->restart_queue = ntp;
2549 rls_lun_statep(isp, tptr);
2553 isp_handle_platform_atio7(ispsoftc_t *isp, at7_entry_t *aep)
2556 uint16_t lun, chan, nphdl = NIL_HANDLE;
2558 uint64_t wwn = INI_NONE;
2561 struct ccb_accept_tio *atiop;
2562 atio_private_data_t *atp = NULL;
2563 atio_private_data_t *oatp;
2564 inot_private_data_t *ntp;
2566 did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2];
2567 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
2568 lun = (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | aep->at_cmnd.fcp_cmnd_lun[1];
2571 * Find the N-port handle, and Virtual Port Index for this command.
2573 * If we can't, we're somewhat in trouble because we can't actually respond w/o that information.
2574 * We also, as a matter of course, need to know the WWN of the initiator too.
2576 if (ISP_CAP_MULTI_ID(isp)) {
2578 * Find the right channel based upon D_ID
2580 isp_find_chan_by_did(isp, did, &chan);
2582 if (chan == ISP_NOCHAN) {
2586 * If we don't recognizer our own D_DID, terminate the exchange, unless we're within 2 seconds of startup
2587 * It's a bit tricky here as we need to stash this command *somewhere*.
2590 if (NANOTIME_SUB(&isp->isp_init_time, &now) > 2000000000ULL) {
2591 isp_prt(isp, ISP_LOGWARN, "%s: [RX_ID 0x%x] D_ID %x not found on any channel- dropping", __func__, aep->at_rxid, did);
2592 isp_endcmd(isp, aep, NIL_HANDLE, ISP_NOCHAN, ECMD_TERMINATE, 0);
2595 tptr = get_lun_statep(isp, 0, 0);
2597 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
2599 isp_prt(isp, ISP_LOGWARN, "%s: [RX_ID 0x%x] D_ID %x not found on any channel and no tptr- dropping", __func__, aep->at_rxid, did);
2600 isp_endcmd(isp, aep, NIL_HANDLE, ISP_NOCHAN, ECMD_TERMINATE, 0);
2604 isp_prt(isp, ISP_LOGWARN, "%s: [RX_ID 0x%x] D_ID %x not found on any channel- deferring", __func__, aep->at_rxid, did);
2607 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] D_ID 0x%06x found on Chan %d for S_ID 0x%06x", __func__, aep->at_rxid, did, chan, sid);
2613 * Find the PDB entry for this initiator
2615 if (isp_find_pdb_by_sid(isp, chan, sid, &lp) == 0) {
2617 * If we're not in the port database terminate the exchange.
2619 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",
2620 __func__, aep->at_rxid, did, chan, sid);
2621 isp_endcmd(isp, aep, NIL_HANDLE, chan, ECMD_TERMINATE, 0);
2628 * Get the tstate pointer
2630 tptr = get_lun_statep(isp, chan, lun);
2632 tptr = get_lun_statep(isp, chan, CAM_LUN_WILDCARD);
2634 isp_prt(isp, ISP_LOGWARN, "%s: [0x%x] no state pointer for lun %d or wildcard", __func__, aep->at_rxid, lun);
2636 isp_endcmd(isp, aep, nphdl, SCSI_STATUS_BUSY, 0);
2638 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2645 * Start any commands pending resources first.
2647 if (tptr->restart_queue) {
2648 inot_private_data_t *restart_queue = tptr->restart_queue;
2649 tptr->restart_queue = NULL;
2650 while (restart_queue) {
2651 ntp = restart_queue;
2652 restart_queue = ntp->rd.nt.nt_hba;
2653 isp_prt(isp, ISP_LOGTDEBUG0, "%s: restarting resrc deprived %x", __func__, ((at7_entry_t *)ntp->rd.data)->at_rxid);
2654 isp_handle_platform_atio7(isp, (at7_entry_t *) ntp->rd.data);
2655 isp_put_ntpd(isp, tptr, ntp);
2657 * If a recursion caused the restart queue to start to fill again,
2658 * stop and splice the new list on top of the old list and restore
2659 * it and go to noresrc.
2661 if (tptr->restart_queue) {
2662 isp_prt(isp, ISP_LOGTDEBUG0, "%s: restart queue refilling", __func__);
2663 if (restart_queue) {
2664 ntp = tptr->restart_queue;
2665 tptr->restart_queue = restart_queue;
2666 while (restart_queue->rd.nt.nt_hba) {
2667 restart_queue = restart_queue->rd.nt.nt_hba;
2669 restart_queue->rd.nt.nt_hba = ntp;
2677 * If the f/w is out of resources, just send a BUSY status back.
2679 if (aep->at_rxid == AT7_NORESRC_RXID) {
2680 rls_lun_statep(isp, tptr);
2681 isp_endcmd(isp, aep, nphdl, chan, SCSI_BUSY, 0);
2686 * If we're out of resources, just send a BUSY status back.
2688 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
2689 if (atiop == NULL) {
2690 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atios", aep->at_rxid);
2694 oatp = isp_find_atpd(isp, tptr, aep->at_rxid);
2696 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] tag wraparound in isp_handle_platforms_atio7 (N-Port Handle 0x%04x S_ID 0x%04x OX_ID 0x%04x) oatp state %d",
2697 aep->at_rxid, nphdl, sid, aep->at_hdr.ox_id, oatp->state);
2699 * It's not a "no resource" condition- but we can treat it like one
2703 atp = isp_get_atpd(isp, tptr, aep->at_rxid);
2705 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atps", aep->at_rxid);
2708 atp->word3 = lp->prli_word3;
2709 atp->state = ATPD_STATE_ATIO;
2710 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2712 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2713 atiop->init_id = nphdl;
2714 atiop->ccb_h.target_id = FCPARAM(isp, chan)->isp_loopid;
2715 atiop->ccb_h.target_lun = lun;
2716 atiop->sense_len = 0;
2717 cdbxlen = aep->at_cmnd.fcp_cmnd_alen_datadir >> FCP_CMND_ADDTL_CDBLEN_SHIFT;
2719 isp_prt(isp, ISP_LOGWARN, "additional CDBLEN ignored");
2721 cdbxlen = sizeof (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_cdb);
2722 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cmnd.cdb_dl.sf.fcp_cmnd_cdb, cdbxlen);
2723 atiop->cdb_len = cdbxlen;
2724 atiop->ccb_h.status = CAM_CDB_RECVD;
2725 atiop->tag_id = atp->tag;
2726 switch (aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK) {
2727 case FCP_CMND_TASK_ATTR_SIMPLE:
2728 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2729 atiop->tag_action = MSG_SIMPLE_Q_TAG;
2731 case FCP_CMND_TASK_ATTR_HEAD:
2732 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2733 atiop->tag_action = MSG_HEAD_OF_Q_TAG;
2735 case FCP_CMND_TASK_ATTR_ORDERED:
2736 atiop->ccb_h.flags |= CAM_TAG_ACTION_VALID;
2737 atiop->tag_action = MSG_ORDERED_Q_TAG;
2741 case FCP_CMND_TASK_ATTR_ACA:
2742 case FCP_CMND_TASK_ATTR_UNTAGGED:
2743 atiop->tag_action = 0;
2746 atp->orig_datalen = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
2747 atp->bytes_xfered = 0;
2751 atp->oxid = aep->at_hdr.ox_id;
2752 atp->rxid = aep->at_hdr.rx_id;
2753 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2754 atp->tattr = aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK;
2755 atp->state = ATPD_STATE_CAM;
2756 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO7[0x%x] CDB=0x%x lun %d datalen %u", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2757 xpt_done((union ccb *)atiop);
2758 rls_lun_statep(isp, tptr);
2762 isp_put_atpd(isp, tptr, atp);
2764 ntp = isp_get_ntpd(isp, tptr);
2766 rls_lun_statep(isp, tptr);
2767 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
2770 memcpy(ntp->rd.data, aep, QENTRY_LEN);
2771 ntp->rd.nt.nt_hba = tptr->restart_queue;
2772 tptr->restart_queue = ntp;
2773 rls_lun_statep(isp, tptr);
2778 * Handle starting an SRR (sequence retransmit request)
2779 * We get here when we've gotten the immediate notify
2780 * and the return of all outstanding CTIOs for this
2784 isp_handle_srr_start(ispsoftc_t *isp, tstate_t *tptr, atio_private_data_t *atp)
2786 in_fcentry_24xx_t *inot;
2787 uint32_t srr_off, ccb_off, ccb_len, ccb_end;
2790 inot = (in_fcentry_24xx_t *)atp->srr;
2791 srr_off = inot->in_srr_reloff_lo | (inot->in_srr_reloff_hi << 16);
2793 atp->srr_ccb = NULL;
2796 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] null ccb", atp->tag);
2800 ccb_off = ccb->ccb_h.spriv_field0;
2801 ccb_len = ccb->csio.dxfer_len;
2802 ccb_end = (ccb_off == ~0)? ~0 : ccb_off + ccb_len;
2804 switch (inot->in_srr_iu) {
2805 case R_CTL_INFO_SOLICITED_DATA:
2807 * We have to restart a FCP_DATA data out transaction
2810 atp->bytes_xfered = srr_off;
2812 isp_prt(isp, ISP_LOGWARN, "SRR[0x%x] SRR offset 0x%x but current CCB doesn't transfer data", atp->tag, srr_off);
2815 if (srr_off < ccb_off || ccb_off > srr_off + ccb_len) {
2816 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);
2819 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);
2821 case R_CTL_INFO_COMMAND_STATUS:
2822 isp_prt(isp, ISP_LOGTINFO, "SRR[0x%x] Got an FCP RSP SRR- resending status", atp->tag);
2825 * We have to restart a FCP_RSP IU transaction
2828 case R_CTL_INFO_DATA_DESCRIPTOR:
2830 * We have to restart an FCP DATA in transaction
2832 isp_prt(isp, ISP_LOGWARN, "Got an FCP DATA IN SRR- dropping");
2836 isp_prt(isp, ISP_LOGWARN, "Got an unknown information (%x) SRR- dropping", inot->in_srr_iu);
2841 * We can't do anything until this is acked, so we might as well start it now.
2842 * We aren't going to do the usual asynchronous ack issue because we need
2843 * to make sure this gets on the wire first.
2845 if (isp_notify_ack(isp, inot)) {
2846 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
2849 isp_target_start_ctio(isp, ccb, FROM_SRR);
2852 inot->in_reserved = 1;
2853 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2854 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2855 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2856 isp_complete_ctio(ccb);
2859 if (isp_notify_ack(isp, inot)) {
2860 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
2863 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2864 ccb->ccb_h.status = CAM_MESSAGE_RECV;
2866 * This is not a strict interpretation of MDP, but it's close
2868 ccb->csio.msg_ptr = &ccb->csio.sense_data.sense_buf[SSD_FULL_SIZE - 16];
2869 ccb->csio.msg_len = 7;
2870 ccb->csio.msg_ptr[0] = MSG_EXTENDED;
2871 ccb->csio.msg_ptr[1] = 5;
2872 ccb->csio.msg_ptr[2] = 0; /* modify data pointer */
2873 ccb->csio.msg_ptr[3] = srr_off >> 24;
2874 ccb->csio.msg_ptr[4] = srr_off >> 16;
2875 ccb->csio.msg_ptr[5] = srr_off >> 8;
2876 ccb->csio.msg_ptr[6] = srr_off;
2877 isp_complete_ctio(ccb);
2882 isp_handle_srr_notify(ispsoftc_t *isp, void *inot_raw)
2885 in_fcentry_24xx_t *inot = inot_raw;
2886 atio_private_data_t *atp;
2887 uint32_t tag = inot->in_rxid;
2888 uint32_t bus = inot->in_vpidx;
2890 if (!IS_24XX(isp)) {
2891 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot_raw);
2895 tptr = get_lun_statep_from_tag(isp, bus, tag);
2897 isp_prt(isp, ISP_LOGERR, "%s: cannot find tptr for tag %x in SRR Notify", __func__, tag);
2898 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2901 atp = isp_find_atpd(isp, tptr, tag);
2903 rls_lun_statep(isp, tptr);
2904 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x in SRR Notify", __func__, tag);
2905 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2908 atp->srr_notify_rcvd = 1;
2909 memcpy(atp->srr, inot, sizeof (atp->srr));
2910 isp_prt(isp, ISP_LOGTINFO /* ISP_LOGTDEBUG0 */, "SRR[0x%x] inot->in_rxid flags 0x%x srr_iu=%x reloff 0x%x", inot->in_rxid, inot->in_flags, inot->in_srr_iu,
2911 inot->in_srr_reloff_lo | (inot->in_srr_reloff_hi << 16));
2913 isp_handle_srr_start(isp, tptr, atp);
2914 rls_lun_statep(isp, tptr);
2918 isp_handle_platform_ctio(ispsoftc_t *isp, void *arg)
2921 int sentstatus = 0, ok = 0, notify_cam = 0, resid = 0, failure = 0;
2922 tstate_t *tptr = NULL;
2923 atio_private_data_t *atp = NULL;
2925 uint32_t handle, moved_data = 0, data_requested;
2928 * CTIO handles are 16 bits.
2929 * CTIO2 and CTIO7 are 32 bits.
2933 handle = ((ct_entry_t *)arg)->ct_syshandle;
2935 handle = ((ct2_entry_t *)arg)->ct_syshandle;
2937 ccb = isp_find_xs_tgt(isp, handle);
2939 isp_print_bytes(isp, "null ccb in isp_handle_platform_ctio", QENTRY_LEN, arg);
2942 isp_destroy_tgt_handle(isp, handle);
2943 data_requested = PISP_PCMD(ccb)->datalen;
2944 isp_free_pcmd(isp, ccb);
2945 if (isp->isp_nactive) {
2949 bus = XS_CHANNEL(ccb);
2950 tptr = get_lun_statep(isp, bus, XS_LUN(ccb));
2952 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
2955 isp_prt(isp, ISP_LOGERR, "%s: cannot find tptr for tag %x after I/O", __func__, ccb->csio.tag_id);
2960 atp = isp_find_atpd(isp, tptr, ((ct7_entry_t *)arg)->ct_rxid);
2961 } else if (IS_FC(isp)) {
2962 atp = isp_find_atpd(isp, tptr, ((ct2_entry_t *)arg)->ct_rxid);
2964 atp = isp_find_atpd(isp, tptr, ((ct_entry_t *)arg)->ct_fwhandle);
2968 * XXX: isp_clear_commands() generates fake CTIO with zero
2969 * ct_rxid value, filling only ct_syshandle. Workaround
2970 * that using tag_id from the CCB, pointed by ct_syshandle.
2972 atp = isp_find_atpd(isp, tptr, ccb->csio.tag_id);
2975 rls_lun_statep(isp, tptr);
2976 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x after I/O", __func__, ccb->csio.tag_id);
2979 KASSERT((atp->ctcnt > 0), ("ctio count not greater than zero"));
2980 atp->bytes_in_transit -= data_requested;
2982 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2985 ct7_entry_t *ct = arg;
2987 if (ct->ct_nphdl == CT7_SRR) {
2989 if (atp->srr_notify_rcvd)
2990 isp_handle_srr_start(isp, tptr, atp);
2991 rls_lun_statep(isp, tptr);
2994 if (ct->ct_nphdl == CT_HBA_RESET) {
2995 failure = CAM_UNREC_HBA_ERROR;
2997 sentstatus = ct->ct_flags & CT7_SENDSTATUS;
2998 ok = (ct->ct_nphdl == CT7_OK);
2999 notify_cam = (ct->ct_header.rqs_seqno & ATPD_SEQ_NOTIFY_CAM) != 0;
3000 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) {
3001 resid = ct->ct_resid;
3002 moved_data = data_requested - resid;
3005 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),
3006 notify_cam, ct->ct_nphdl, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
3007 } else if (IS_FC(isp)) {
3008 ct2_entry_t *ct = arg;
3009 if (ct->ct_status == CT_SRR) {
3011 if (atp->srr_notify_rcvd)
3012 isp_handle_srr_start(isp, tptr, atp);
3013 rls_lun_statep(isp, tptr);
3014 isp_target_putback_atio(ccb);
3017 if (ct->ct_status == CT_HBA_RESET) {
3018 failure = CAM_UNREC_HBA_ERROR;
3020 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
3021 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
3022 notify_cam = (ct->ct_header.rqs_seqno & ATPD_SEQ_NOTIFY_CAM) != 0;
3023 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
3024 resid = ct->ct_resid;
3025 moved_data = data_requested - resid;
3028 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO2[%x] seq %u nc %d sts 0x%x flg 0x%x sns %d resid %d %s", __func__, ct->ct_rxid, ATPD_GET_SEQNO(ct),
3029 notify_cam, ct->ct_status, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
3031 ct_entry_t *ct = arg;
3033 if (ct->ct_status == (CT_HBA_RESET & 0xff)) {
3034 failure = CAM_UNREC_HBA_ERROR;
3036 sentstatus = ct->ct_flags & CT_SENDSTATUS;
3037 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
3038 notify_cam = (ct->ct_header.rqs_seqno & ATPD_SEQ_NOTIFY_CAM) != 0;
3040 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
3041 resid = ct->ct_resid;
3042 moved_data = data_requested - resid;
3044 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO[%x] seq %u nc %d tag %x S_ID 0x%x lun %d sts %x flg %x resid %d %s", __func__, ct->ct_fwhandle, ATPD_GET_SEQNO(ct),
3045 notify_cam, ct->ct_tag_val, ct->ct_iid, ct->ct_lun, ct->ct_status, ct->ct_flags, resid, sentstatus? "FIN" : "MID");
3049 atp->bytes_xfered += moved_data;
3050 ccb->csio.resid = atp->orig_datalen - atp->bytes_xfered - atp->bytes_in_transit;
3052 if (sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
3053 ccb->ccb_h.status |= CAM_SENT_SENSE;
3055 ccb->ccb_h.status |= CAM_REQ_CMP;
3058 if (failure == CAM_UNREC_HBA_ERROR)
3059 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
3061 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
3063 atp->state = ATPD_STATE_PDON;
3064 rls_lun_statep(isp, tptr);
3067 * We never *not* notify CAM when there has been any error (ok == 0),
3068 * so we never need to do an ATIO putback if we're not notifying CAM.
3070 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done (ok=%d nc=%d nowsendstatus=%d ccb ss=%d)",
3071 (sentstatus)? " FINAL " : "MIDTERM ", atp->tag, ok, notify_cam, atp->sendst, (ccb->ccb_h.flags & CAM_SEND_STATUS) != 0);
3072 if (notify_cam == 0) {
3074 isp_target_start_ctio(isp, ccb, FROM_CTIO_DONE);
3080 * We're telling CAM we're done with this CTIO transaction.
3082 * 24XX cards never need an ATIO put back.
3084 * Other cards need one put back only on error.
3085 * In the latter case, a timeout will re-fire
3086 * and try again in case we didn't have
3087 * queue resources to do so at first. In any case,
3088 * once the putback is done we do the completion
3091 if (ok || IS_24XX(isp)) {
3092 isp_complete_ctio(ccb);
3094 isp_target_putback_atio(ccb);
3099 isp_handle_platform_notify_scsi(ispsoftc_t *isp, in_entry_t *inot)
3101 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
3105 isp_handle_platform_notify_fc(ispsoftc_t *isp, in_fcentry_t *inp)
3108 switch (inp->in_status) {
3109 case IN_PORT_LOGOUT:
3111 * XXX: Need to delete this initiator's WWN from the database
3112 * XXX: Need to send this LOGOUT upstream
3114 isp_prt(isp, ISP_LOGWARN, "port logout of S_ID 0x%x", inp->in_iid);
3116 case IN_PORT_CHANGED:
3117 isp_prt(isp, ISP_LOGWARN, "port changed for S_ID 0x%x", inp->in_iid);
3119 case IN_GLOBAL_LOGO:
3120 isp_del_all_wwn_entries(isp, 0);
3121 isp_prt(isp, ISP_LOGINFO, "all ports logged out");
3129 atio_private_data_t *atp;
3131 struct ccb_immediate_notify *inot = NULL;
3133 if (ISP_CAP_SCCFW(isp)) {
3134 lun = inp->in_scclun;
3138 if (ISP_CAP_2KLOGIN(isp)) {
3139 loopid = ((in_fcentry_e_t *)inp)->in_iid;
3141 loopid = inp->in_iid;
3143 if (isp_find_pdb_by_loopid(isp, 0, loopid, &lp)) {
3148 tptr = get_lun_statep(isp, 0, lun);
3150 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
3152 isp_prt(isp, ISP_LOGWARN, "ABORT TASK for lun %u- but no tstate", lun);
3156 atp = isp_find_atpd(isp, tptr, inp->in_seqid);
3159 inot = (struct ccb_immediate_notify *) SLIST_FIRST(&tptr->inots);
3160 isp_prt(isp, ISP_LOGTDEBUG0, "ABORT TASK RX_ID %x WWN 0x%016llx state %d", inp->in_seqid, (unsigned long long) wwn, atp->state);
3163 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
3164 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
3166 ISP_PATH_PRT(isp, ISP_LOGWARN, tptr->owner, "out of INOT structures\n");
3169 ISP_PATH_PRT(isp, ISP_LOGWARN, tptr->owner, "abort task RX_ID %x from wwn 0x%016llx, state unknown\n", inp->in_seqid, wwn);
3172 isp_notify_t tmp, *nt = &tmp;
3173 ISP_MEMZERO(nt, sizeof (isp_notify_t));
3175 nt->nt_tgt = FCPARAM(isp, 0)->isp_wwpn;
3177 nt->nt_nphdl = loopid;
3178 nt->nt_sid = PORT_ANY;
3179 nt->nt_did = PORT_ANY;
3181 nt->nt_need_ack = 1;
3183 nt->nt_ncode = NT_ABORT_TASK;
3184 nt->nt_lreserved = inot;
3185 isp_handle_platform_target_tmf(isp, nt);
3188 rls_lun_statep(isp, tptr);
3195 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp);
3200 isp_handle_platform_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot)
3203 uint16_t prli_options = 0;
3206 uint8_t *ptr = NULL;
3209 nphdl = inot->in_nphdl;
3210 if (nphdl != NIL_HANDLE) {
3211 portid = inot->in_portid_hi << 16 | inot->in_portid_lo;
3216 switch (inot->in_status) {
3217 case IN24XX_ELS_RCVD:
3220 int chan = ISP_GET_VPIDX(isp, inot->in_vpidx);
3223 * Note that we're just getting notification that an ELS was received
3224 * (possibly with some associated information sent upstream). This is
3225 * *not* the same as being given the ELS frame to accept or reject.
3227 switch (inot->in_status_subcode) {
3230 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25)) {
3231 ptr = (uint8_t *)inot; /* point to unswizzled entry! */
3232 wwn = (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF]) << 56) |
3233 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+1]) << 48) |
3234 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+2]) << 40) |
3235 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+3]) << 32) |
3236 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+4]) << 24) |
3237 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+5]) << 16) |
3238 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+6]) << 8) |
3239 (((uint64_t) ptr[IN24XX_LOGO_WWPN_OFF+7]));
3243 isp_del_wwn_entry(isp, chan, wwn, nphdl, portid);
3251 * Treat PRLI the same as PLOGI and make a database entry for it.
3253 if (inot->in_status_subcode == PLOGI) {
3256 prli_options = inot->in_prli_options;
3259 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25)) {
3260 ptr = (uint8_t *)inot; /* point to unswizzled entry! */
3261 wwn = (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF]) << 56) |
3262 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+1]) << 48) |
3263 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+2]) << 40) |
3264 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+3]) << 32) |
3265 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+4]) << 24) |
3266 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+5]) << 16) |
3267 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+6]) << 8) |
3268 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+7]));
3272 isp_add_wwn_entry(isp, chan, wwn, nphdl, portid, prli_options);
3281 ISP_SNPRINTF(buf, sizeof (buf), "ELS 0x%x", inot->in_status_subcode);
3285 if (inot->in_flags & IN24XX_FLAG_PUREX_IOCB) {
3286 isp_prt(isp, ISP_LOGERR, "%s Chan %d ELS N-port handle %x PortID 0x%06x marked as needing a PUREX response", msg, chan, nphdl, portid);
3289 isp_prt(isp, ISP_LOGTDEBUG0, "%s Chan %d ELS N-port handle %x PortID 0x%06x RX_ID 0x%x OX_ID 0x%x", msg, chan, nphdl, portid,
3290 inot->in_rxid, inot->in_oxid);
3291 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
3295 case IN24XX_PORT_LOGOUT:
3296 ptr = "PORT LOGOUT";
3297 if (isp_find_pdb_by_loopid(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), nphdl, &lp)) {
3298 isp_del_wwn_entry(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), lp->port_wwn, nphdl, lp->portid);
3301 case IN24XX_PORT_CHANGED:
3303 ptr = "PORT CHANGED";
3306 case IN24XX_LIP_RESET:
3310 isp_prt(isp, ISP_LOGINFO, "Chan %d %s (sub-status 0x%x) for N-port handle 0x%x", ISP_GET_VPIDX(isp, inot->in_vpidx), ptr, inot->in_status_subcode, nphdl);
3313 * All subcodes here are irrelevant. What is relevant
3314 * is that we need to terminate all active commands from
3315 * this initiator (known by N-port handle).
3317 /* XXX IMPLEMENT XXX */
3318 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
3321 case IN24XX_SRR_RCVD:
3322 #ifdef ISP_TARGET_MODE
3323 isp_handle_srr_notify(isp, inot);
3331 case IN24XX_LINK_RESET:
3335 case IN24XX_LINK_FAILED:
3337 ptr = "LINK FAILED";
3340 isp_prt(isp, ISP_LOGWARN, "Chan %d %s", ISP_GET_VPIDX(isp, inot->in_vpidx), ptr);
3341 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
3347 isp_handle_platform_target_notify_ack(ispsoftc_t *isp, isp_notify_t *mp)
3350 if (isp->isp_state != ISP_RUNSTATE) {
3351 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) acked- h/w not ready (dropping)", mp->nt_ncode, mp->nt_lreserved != NULL);
3356 * This case is for a Task Management Function, which shows up as an ATIO7 entry.
3358 if (IS_24XX(isp) && mp->nt_lreserved && ((isphdr_t *)mp->nt_lreserved)->rqs_entry_type == RQSTYPE_ATIO) {
3359 ct7_entry_t local, *cto = &local;
3360 at7_entry_t *aep = (at7_entry_t *)mp->nt_lreserved;
3365 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
3366 if (isp_find_pdb_by_sid(isp, mp->nt_channel, sid, &lp)) {
3371 ISP_MEMZERO(&local, sizeof (local));
3372 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
3373 cto->ct_header.rqs_entry_count = 1;
3374 cto->ct_nphdl = nphdl;
3375 cto->ct_rxid = aep->at_rxid;
3376 cto->ct_vpidx = mp->nt_channel;
3377 cto->ct_iid_lo = sid;
3378 cto->ct_iid_hi = sid >> 16;
3379 cto->ct_oxid = aep->at_hdr.ox_id;
3380 cto->ct_flags = CT7_SENDSTATUS|CT7_NOACK|CT7_NO_DATA|CT7_FLAG_MODE1;
3381 cto->ct_flags |= (aep->at_ta_len >> 12) << CT7_TASK_ATTR_SHIFT;
3382 return (isp_target_put_entry(isp, &local));
3386 * This case is for a responding to an ABTS frame
3388 if (IS_24XX(isp) && mp->nt_lreserved && ((isphdr_t *)mp->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD) {
3391 * Overload nt_need_ack here to mark whether we've terminated the associated command.
3393 if (mp->nt_need_ack) {
3394 uint8_t storage[QENTRY_LEN];
3395 ct7_entry_t *cto = (ct7_entry_t *) storage;
3396 abts_t *abts = (abts_t *)mp->nt_lreserved;
3398 ISP_MEMZERO(cto, sizeof (ct7_entry_t));
3399 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [%x] terminating after ABTS received", __func__, abts->abts_rxid_task);
3400 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
3401 cto->ct_header.rqs_entry_count = 1;
3402 cto->ct_nphdl = mp->nt_nphdl;
3403 cto->ct_rxid = abts->abts_rxid_task;
3404 cto->ct_iid_lo = mp->nt_sid;
3405 cto->ct_iid_hi = mp->nt_sid >> 16;
3406 cto->ct_oxid = abts->abts_ox_id;
3407 cto->ct_vpidx = mp->nt_channel;
3408 cto->ct_flags = CT7_NOACK|CT7_TERMINATE;
3409 if (isp_target_put_entry(isp, cto)) {
3412 mp->nt_need_ack = 0;
3414 if (isp_acknak_abts(isp, mp->nt_lreserved, 0) == ENOMEM) {
3422 * Handle logout cases here
3424 if (mp->nt_ncode == NT_GLOBAL_LOGOUT) {
3425 isp_del_all_wwn_entries(isp, mp->nt_channel);
3428 if (mp->nt_ncode == NT_LOGOUT) {
3429 if (!IS_2100(isp) && IS_FC(isp)) {
3430 isp_del_wwn_entries(isp, mp);
3435 * General purpose acknowledgement
3437 if (mp->nt_need_ack) {
3438 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) being acked", mp->nt_ncode, mp->nt_lreserved != NULL);
3440 * Don't need to use the guaranteed send because the caller can retry
3442 return (isp_notify_ack(isp, mp->nt_lreserved));
3448 * Handle task management functions.
3450 * We show up here with a notify structure filled out.
3452 * The nt_lreserved tag points to the original queue entry
3455 isp_handle_platform_target_tmf(ispsoftc_t *isp, isp_notify_t *notify)
3459 struct ccb_immediate_notify *inot;
3460 inot_private_data_t *ntp = NULL;
3463 isp_prt(isp, ISP_LOGTDEBUG0, "%s: code 0x%x sid 0x%x tagval 0x%016llx chan %d lun 0x%x", __func__, notify->nt_ncode,
3464 notify->nt_sid, (unsigned long long) notify->nt_tagval, notify->nt_channel, notify->nt_lun);
3466 * NB: This assignment is necessary because of tricky type conversion.
3467 * XXX: This is tricky and I need to check this. If the lun isn't known
3468 * XXX: for the task management function, it does not of necessity follow
3469 * XXX: that it should go up stream to the wildcard listener.
3471 if (notify->nt_lun == LUN_ANY) {
3472 lun = CAM_LUN_WILDCARD;
3474 lun = notify->nt_lun;
3476 tptr = get_lun_statep(isp, notify->nt_channel, lun);
3478 tptr = get_lun_statep(isp, notify->nt_channel, CAM_LUN_WILDCARD);
3480 isp_prt(isp, ISP_LOGWARN, "%s: no state pointer found for chan %d lun 0x%x", __func__, notify->nt_channel, lun);
3484 inot = (struct ccb_immediate_notify *) SLIST_FIRST(&tptr->inots);
3486 isp_prt(isp, ISP_LOGWARN, "%s: out of immediate notify structures for chan %d lun 0x%x", __func__, notify->nt_channel, lun);
3490 if (isp_find_pdb_by_sid(isp, notify->nt_channel, notify->nt_sid, &lp) == 0) {
3491 inot->initiator_id = CAM_TARGET_WILDCARD;
3493 inot->initiator_id = lp->handle;
3495 inot->seq_id = notify->nt_tagval;
3496 inot->tag_id = notify->nt_tagval >> 32;
3498 switch (notify->nt_ncode) {
3500 isp_target_mark_aborted_early(isp, tptr, inot->tag_id);
3501 inot->arg = MSG_ABORT_TASK;
3503 case NT_ABORT_TASK_SET:
3504 isp_target_mark_aborted_early(isp, tptr, TAG_ANY);
3505 inot->arg = MSG_ABORT_TASK_SET;
3508 inot->arg = MSG_CLEAR_ACA;
3510 case NT_CLEAR_TASK_SET:
3511 inot->arg = MSG_CLEAR_TASK_SET;
3514 inot->arg = MSG_LOGICAL_UNIT_RESET;
3516 case NT_TARGET_RESET:
3517 inot->arg = MSG_TARGET_RESET;
3520 isp_prt(isp, ISP_LOGWARN, "%s: unknown TMF code 0x%x for chan %d lun 0x%x", __func__, notify->nt_ncode, notify->nt_channel, lun);
3524 ntp = isp_get_ntpd(isp, tptr);
3526 isp_prt(isp, ISP_LOGWARN, "%s: out of inotify private structures", __func__);
3529 ISP_MEMCPY(&ntp->rd.nt, notify, sizeof (isp_notify_t));
3530 if (notify->nt_lreserved) {
3531 ISP_MEMCPY(&ntp->rd.data, notify->nt_lreserved, QENTRY_LEN);
3532 ntp->rd.nt.nt_lreserved = &ntp->rd.data;
3534 ntp->rd.seq_id = notify->nt_tagval;
3535 ntp->rd.tag_id = notify->nt_tagval >> 32;
3538 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
3539 rls_lun_statep(isp, tptr);
3540 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
3541 inot->ccb_h.status = CAM_MESSAGE_RECV;
3542 xpt_done((union ccb *)inot);
3546 rls_lun_statep(isp, tptr);
3548 if (notify->nt_need_ack && notify->nt_lreserved) {
3549 if (((isphdr_t *)notify->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD) {
3550 if (isp_acknak_abts(isp, notify->nt_lreserved, ENOMEM)) {
3551 isp_prt(isp, ISP_LOGWARN, "you lose- unable to send an ACKNAK");
3554 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, notify->nt_lreserved);
3560 * Find the associated private data and mark it as dead so
3561 * we don't try to work on it any further.
3564 isp_target_mark_aborted(ispsoftc_t *isp, union ccb *ccb)
3567 atio_private_data_t *atp;
3568 union ccb *accb = ccb->cab.abort_ccb;
3570 tptr = get_lun_statep(isp, XS_CHANNEL(accb), XS_LUN(accb));
3572 tptr = get_lun_statep(isp, XS_CHANNEL(accb), CAM_LUN_WILDCARD);
3574 ccb->ccb_h.status = CAM_REQ_INVALID;
3579 atp = isp_find_atpd(isp, tptr, accb->atio.tag_id);
3581 ccb->ccb_h.status = CAM_REQ_INVALID;
3584 ccb->ccb_h.status = CAM_REQ_CMP;
3586 rls_lun_statep(isp, tptr);
3590 isp_target_mark_aborted_early(ispsoftc_t *isp, tstate_t *tptr, uint32_t tag_id)
3592 atio_private_data_t *atp;
3593 inot_private_data_t *restart_queue = tptr->restart_queue;
3596 * First, clean any commands pending restart
3598 tptr->restart_queue = NULL;
3599 while (restart_queue) {
3600 uint32_t this_tag_id;
3601 inot_private_data_t *ntp = restart_queue;
3603 restart_queue = ntp->rd.nt.nt_hba;
3606 this_tag_id = ((at7_entry_t *)ntp->rd.data)->at_rxid;
3608 this_tag_id = ((at2_entry_t *)ntp->rd.data)->at_rxid;
3610 if ((uint64_t)tag_id == TAG_ANY || tag_id == this_tag_id) {
3611 isp_put_ntpd(isp, tptr, ntp);
3613 ntp->rd.nt.nt_hba = tptr->restart_queue;
3614 tptr->restart_queue = ntp;
3619 * Now mark other ones dead as well.
3621 for (atp = tptr->atpool; atp < &tptr->atpool[ATPDPSIZE]; atp++) {
3622 if ((uint64_t)tag_id == TAG_ANY || atp->tag == tag_id) {
3629 #ifdef ISP_INTERNAL_TARGET
3630 //#define ISP_SEPARATE_STATUS 1
3631 #define ISP_MULTI_CCBS 1
3632 #if defined(ISP_MULTI_CCBS) && !defined(ISP_SEPARATE_STATUS)
3633 #define ISP_SEPARATE_STATUS 1
3636 typedef struct periph_private_data_t {
3637 union ccb *ccb; /* original ATIO or Immediate Notify */
3638 unsigned long offset; /* current offset */
3639 int sequence; /* current CTIO sequence */
3640 int ctio_cnt; /* current # of ctio's outstanding */
3643 on_queue : 1; /* on restart queue */
3646 * Each ATIO we allocate will have periph private data associated with it
3647 * that maintains per-command state. This private to each ATIO.
3649 #define ATIO_PPD(ccb) ((ppd_t *)(((struct ccb_hdr *)ccb)->ppriv_ptr0))
3651 * Each CTIO we send downstream will get a pointer to the ATIO itself
3652 * so that on completion we can retrieve that pointer.
3654 #define ccb_atio ppriv_ptr1
3655 #define ccb_inot ppriv_ptr1
3658 * Each CTIO we send downstream will contain a sequence number
3660 #define CTIO_SEQ(ccb) ccb->ccb_h.ppriv_field0
3662 #define MAX_ISP_TARG_TRANSFER (2 << 20)
3663 #define NISP_TARG_CMDS 64
3664 #define NISP_TARG_NOTIFIES 64
3665 #define DISK_SHIFT 9
3666 #define JUNK_SIZE 256
3667 #define MULTI_CCB_DATA_LIM 8192
3668 //#define MULTI_CCB_DATA_CNT 64
3669 #define MULTI_CCB_DATA_CNT 8
3671 extern u_int vm_kmem_size;
3673 static uint32_t disk_size;
3674 static uint8_t *disk_data = NULL;
3675 static uint8_t *junk_data;
3676 static MALLOC_DEFINE(M_ISPTARG, "ISPTARG", "ISP TARGET data");
3677 struct isptarg_softc {
3678 /* CCBs (CTIOs, ATIOs, INOTs) pending on the controller */
3679 struct isp_ccbq work_queue;
3680 struct isp_ccbq rework_queue;
3681 struct isp_ccbq running_queue;
3682 struct isp_ccbq inot_queue;
3683 struct cam_periph *periph;
3684 struct cam_path *path;
3687 static periph_ctor_t isptargctor;
3688 static periph_dtor_t isptargdtor;
3689 static periph_start_t isptargstart;
3690 static periph_init_t isptarginit;
3691 static void isptarg_done(struct cam_periph *, union ccb *);
3692 static void isptargasync(void *, u_int32_t, struct cam_path *, void *);
3695 static int isptarg_rwparm(uint8_t *, uint8_t *, uint64_t, uint32_t, uint8_t **, uint32_t *, int *);
3697 static struct periph_driver isptargdriver =
3699 isptarginit, "isptarg", TAILQ_HEAD_INITIALIZER(isptargdriver.units), 0
3708 isptargnotify(ispsoftc_t *isp, union ccb *iccb, struct ccb_immediate_notify *inot)
3710 struct ccb_notify_acknowledge *ack = &iccb->cna2;
3712 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__,
3713 inot->tag_id, inot->initiator_id, inot->seq_id, inot->ccb_h.status, inot->arg);
3714 ack->ccb_h.func_code = XPT_NOTIFY_ACKNOWLEDGE;
3715 ack->ccb_h.flags = 0;
3716 ack->ccb_h.retry_count = 0;
3717 ack->ccb_h.cbfcnp = isptarg_done;
3718 ack->ccb_h.timeout = 0;
3719 ack->ccb_h.ccb_inot = inot;
3720 ack->tag_id = inot->tag_id;
3721 ack->seq_id = inot->seq_id;
3722 ack->initiator_id = inot->initiator_id;
3727 isptargstart(struct cam_periph *periph, union ccb *iccb)
3729 const uint8_t niliqd[SHORT_INQUIRY_LENGTH] = {
3730 0x7f, 0x0, 0x5, 0x2, 32, 0, 0, 0x32,
3731 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ',
3732 'S', 'C', 'S', 'I', ' ', 'N', 'U', 'L',
3733 'L', ' ', 'D', 'E', 'V', 'I', 'C', 'E',
3736 const uint8_t iqd[SHORT_INQUIRY_LENGTH] = {
3737 0, 0x0, 0x5, 0x2, 32, 0, 0, 0x32,
3738 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ',
3739 'S', 'C', 'S', 'I', ' ', 'M', 'E', 'M',
3740 'O', 'R', 'Y', ' ', 'D', 'I', 'S', 'K',
3743 int r, i, more = 0, last, is_data_cmd = 0, is_write;
3745 struct isptarg_softc *softc = periph->softc;
3746 struct ccb_scsiio *csio;
3747 lun_id_t return_lun;
3748 struct ccb_accept_tio *atio;
3749 uint8_t *cdb, *ptr, status;
3751 uint32_t data_len, flags;
3752 struct ccb_hdr *ccbh;
3754 mtx_assert(periph->sim->mtx, MA_OWNED);
3755 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,
3756 TAILQ_FIRST(&softc->inot_queue)? 'y' : 'n', TAILQ_FIRST(&softc->work_queue)? 'y' : 'n', TAILQ_FIRST(&softc->rework_queue)? 'y' : 'n');
3758 * Check for immediate notifies first
3760 ccbh = TAILQ_FIRST(&softc->inot_queue);
3762 TAILQ_REMOVE(&softc->inot_queue, ccbh, periph_links.tqe);
3763 if (TAILQ_FIRST(&softc->inot_queue) || TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue)) {
3764 xpt_schedule(periph, 1);
3766 isptargnotify(softc->isp, iccb, (struct ccb_immediate_notify *)ccbh);
3771 * Check the rework (continuation) work queue first.
3773 ccbh = TAILQ_FIRST(&softc->rework_queue);
3775 atio = (struct ccb_accept_tio *)ccbh;
3776 TAILQ_REMOVE(&softc->rework_queue, ccbh, periph_links.tqe);
3777 more = TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue);
3780 ccbh = TAILQ_FIRST(&softc->work_queue);
3782 xpt_release_ccb(iccb);
3785 atio = (struct ccb_accept_tio *)ccbh;
3786 TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe);
3787 more = TAILQ_FIRST(&softc->work_queue) != NULL;
3790 ATIO_PPD(atio)->on_queue = 0;
3792 if (atio->tag_id == 0xffffffff || atio->ccb_h.func_code != XPT_ACCEPT_TARGET_IO) {
3796 data_len = is_write = 0;
3799 status = SCSI_STATUS_OK;
3800 flags = CAM_SEND_STATUS;
3801 memset(&atio->sense_data, 0, sizeof (atio->sense_data));
3802 cdb = atio->cdb_io.cdb_bytes;
3803 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,
3804 queue, atio->init_id, cdb[0], ATIO_PPD(atio)->offset);
3806 return_lun = XS_LUN(atio);
3807 if (return_lun != 0) {
3808 xpt_print(atio->ccb_h.path, "[0x%x] Non-Zero Lun %d: cdb0=0x%x\n", atio->tag_id, return_lun, cdb[0]);
3809 if (cdb[0] != INQUIRY && cdb[0] != REPORT_LUNS && cdb[0] != REQUEST_SENSE) {
3810 status = SCSI_STATUS_CHECK_COND;
3811 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3812 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3813 SDFIXED(atio->sense_data)->add_sense_code = 0x25; /* LOGICAL UNIT NOT SUPPORTED */
3814 atio->sense_len = SSD_MIN_SIZE;
3816 return_lun = CAM_LUN_WILDCARD;
3821 flags |= CAM_DIR_IN;
3822 data_len = sizeof (atio->sense_data);
3823 junk_data[0] = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_NO_SENSE;
3824 memset(junk_data+1, 0, data_len-1);
3825 if (data_len > cdb[4]) {
3829 data_ptr = junk_data;
3843 r = isptarg_rwparm(cdb, disk_data, disk_size, ATIO_PPD(atio)->offset, &data_ptr, &data_len, &last);
3845 status = SCSI_STATUS_CHECK_COND;
3846 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3847 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3849 SDFIXED(atio->sense_data)->add_sense_code = 0x21; /* LOGICAL BLOCK ADDRESS OUT OF RANGE */
3851 SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */
3853 atio->sense_len = SSD_MIN_SIZE;
3855 #ifdef ISP_SEPARATE_STATUS
3856 if (last && data_len) {
3861 flags &= ~CAM_SEND_STATUS;
3864 ATIO_PPD(atio)->offset += data_len;
3866 flags |= CAM_DIR_OUT;
3868 flags |= CAM_DIR_IN;
3870 flags |= CAM_DIR_NONE;
3875 flags |= CAM_DIR_IN;
3876 if (cdb[1] || cdb[2] || cdb[3]) {
3877 status = SCSI_STATUS_CHECK_COND;
3878 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3879 SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION;
3880 SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */
3881 atio->sense_len = SSD_MIN_SIZE;
3884 data_len = sizeof (iqd);
3885 if (data_len > cdb[4]) {
3889 if (XS_LUN(iccb) != 0) {
3890 memcpy(junk_data, niliqd, sizeof (iqd));
3892 memcpy(junk_data, iqd, sizeof (iqd));
3894 data_ptr = junk_data;
3897 case TEST_UNIT_READY:
3898 flags |= CAM_DIR_NONE;
3901 status = SCSI_STATUS_CHECK_COND;
3902 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3903 SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION;
3904 SDFIXED(atio->sense_data)->add_sense_code = 0x29; /* POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */
3905 atio->sense_len = SSD_MIN_SIZE;
3908 case SYNCHRONIZE_CACHE:
3913 flags |= CAM_DIR_NONE;
3917 flags |= CAM_DIR_IN;
3918 if (cdb[2] || cdb[3] || cdb[4] || cdb[5]) {
3919 status = SCSI_STATUS_CHECK_COND;
3920 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3921 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3922 SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */
3923 atio->sense_len = SSD_MIN_SIZE;
3926 if (cdb[8] & 0x1) { /* PMI */
3927 junk_data[0] = 0xff;
3928 junk_data[1] = 0xff;
3929 junk_data[2] = 0xff;
3930 junk_data[3] = 0xff;
3932 uint64_t last_blk = (disk_size >> DISK_SHIFT) - 1;
3933 if (last_blk < 0xffffffffULL) {
3934 junk_data[0] = (last_blk >> 24) & 0xff;
3935 junk_data[1] = (last_blk >> 16) & 0xff;
3936 junk_data[2] = (last_blk >> 8) & 0xff;
3937 junk_data[3] = (last_blk) & 0xff;
3939 junk_data[0] = 0xff;
3940 junk_data[1] = 0xff;
3941 junk_data[2] = 0xff;
3942 junk_data[3] = 0xff;
3945 junk_data[4] = ((1 << DISK_SHIFT) >> 24) & 0xff;
3946 junk_data[5] = ((1 << DISK_SHIFT) >> 16) & 0xff;
3947 junk_data[6] = ((1 << DISK_SHIFT) >> 8) & 0xff;
3948 junk_data[7] = ((1 << DISK_SHIFT)) & 0xff;
3949 data_ptr = junk_data;
3953 flags |= CAM_DIR_IN;
3954 memset(junk_data, 0, JUNK_SIZE);
3955 junk_data[0] = (1 << 3) >> 24;
3956 junk_data[1] = (1 << 3) >> 16;
3957 junk_data[2] = (1 << 3) >> 8;
3958 junk_data[3] = (1 << 3);
3960 for (i = 0; i < 1; i++) {
3961 ptr = &junk_data[8 + (i << 3)];
3963 ptr[0] = 0x40 | ((i >> 8) & 0x3f);
3967 data_ptr = junk_data;
3968 data_len = (ptr + 8) - junk_data;
3972 flags |= CAM_DIR_NONE;
3973 status = SCSI_STATUS_CHECK_COND;
3974 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3975 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3976 SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */
3977 atio->sense_len = SSD_MIN_SIZE;
3982 * If we are done with the transaction, tell the
3983 * controller to send status and perform a CMD_CMPLT.
3984 * If we have associated sense data, see if we can
3987 if (status == SCSI_STATUS_CHECK_COND) {
3988 flags |= CAM_SEND_SENSE;
3989 csio->sense_len = atio->sense_len;
3990 csio->sense_data = atio->sense_data;
3991 flags &= ~CAM_DIR_MASK;
3995 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);
3996 iccb->ccb_h.target_id = atio->ccb_h.target_id;
3997 iccb->ccb_h.target_lun = return_lun;
3998 iccb->ccb_h.ccb_atio = atio;
3999 CTIO_SEQ(iccb) = ATIO_PPD(atio)->sequence++;
4000 ATIO_PPD(atio)->ctio_cnt++;
4001 if (flags & CAM_SEND_STATUS) {
4002 KASSERT((ATIO_PPD(atio)->status_sent == 0), ("we have already sent status for 0x%x in %s", atio->tag_id, __func__));
4003 ATIO_PPD(atio)->status_sent = 1;
4005 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);
4008 if ((atio->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4009 cam_release_devq(periph->path, 0, 0, 0, 0);
4010 atio->ccb_h.status &= ~CAM_DEV_QFRZN;
4012 #ifdef ISP_MULTI_CCBS
4013 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) {
4014 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, atio->ccb_h.path, "%s: more still to do for 0x%x\n", __func__, atio->tag_id);
4015 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
4016 ATIO_PPD(atio)->on_queue = 1;
4021 xpt_schedule(periph, 1);
4026 isptargctor(struct cam_periph *periph, void *arg)
4028 struct isptarg_softc *softc;
4030 softc = (struct isptarg_softc *)arg;
4031 periph->softc = softc;
4032 softc->periph = periph;
4033 softc->path = periph->path;
4034 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__);
4035 return (CAM_REQ_CMP);
4039 isptargdtor(struct cam_periph *periph)
4041 struct isptarg_softc *softc;
4042 softc = (struct isptarg_softc *)periph->softc;
4043 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__);
4044 softc->periph = NULL;
4046 periph->softc = NULL;
4050 isptarg_done(struct cam_periph *periph, union ccb *ccb)
4052 struct isptarg_softc *softc;
4055 struct ccb_accept_tio *atio;
4056 struct ccb_immediate_notify *inot;
4059 softc = (struct isptarg_softc *)periph->softc;
4061 status = ccb->ccb_h.status & CAM_STATUS_MASK;
4063 switch (ccb->ccb_h.func_code) {
4064 case XPT_ACCEPT_TARGET_IO:
4065 atio = (struct ccb_accept_tio *) ccb;
4066 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] ATIO seen in %s\n", atio->tag_id, __func__);
4067 memset(ATIO_PPD(atio), 0, sizeof (ppd_t));
4068 TAILQ_INSERT_TAIL(&softc->work_queue, &ccb->ccb_h, periph_links.tqe);
4069 ATIO_PPD(atio)->on_queue = 1;
4070 xpt_schedule(periph, 1);
4072 case XPT_IMMEDIATE_NOTIFY:
4073 inot = (struct ccb_immediate_notify *) ccb;
4074 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__);
4075 TAILQ_INSERT_TAIL(&softc->inot_queue, &ccb->ccb_h, periph_links.tqe);
4076 xpt_schedule(periph, 1);
4078 case XPT_CONT_TARGET_IO:
4079 atio = ccb->ccb_h.ccb_atio;
4080 KASSERT((ATIO_PPD(atio)->ctio_cnt != 0), ("ctio zero when finishing a CTIO"));
4081 ATIO_PPD(atio)->ctio_cnt--;
4082 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4083 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
4084 case CAM_MESSAGE_RECV:
4085 newoff = (ccb->csio.msg_ptr[3] << 24) | (ccb->csio.msg_ptr[4] << 16) | (ccb->csio.msg_ptr[5] << 8) | (ccb->csio.msg_ptr[6]);
4086 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));
4087 ATIO_PPD(atio)->offset = newoff;
4088 ATIO_PPD(atio)->status_sent = 0;
4089 if (ATIO_PPD(atio)->on_queue == 0) {
4090 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
4091 ATIO_PPD(atio)->on_queue = 1;
4093 xpt_schedule(periph, 1);
4096 cam_error_print(ccb, CAM_ESF_ALL, CAM_EPF_ALL);
4097 xpt_action((union ccb *)atio);
4100 } else if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
4101 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__);
4102 if (ATIO_PPD(atio)->status_sent == 0 && ATIO_PPD(atio)->on_queue == 0) {
4103 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
4104 ATIO_PPD(atio)->on_queue = 1;
4106 xpt_schedule(periph, 1);
4108 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));
4109 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__);
4110 xpt_action((union ccb *)atio);
4112 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4113 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
4114 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
4116 xpt_release_ccb(ccb);
4118 case XPT_NOTIFY_ACKNOWLEDGE:
4119 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4120 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
4121 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
4123 inot = ccb->ccb_h.ccb_inot;
4124 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);
4125 xpt_release_ccb(ccb);
4126 xpt_action((union ccb *)inot);
4129 xpt_print(ccb->ccb_h.path, "unexpected code 0x%x\n", ccb->ccb_h.func_code);
4135 isptargasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
4137 struct ac_contract *acp = arg;
4138 struct ac_device_changed *fc = (struct ac_device_changed *) acp->contract_data;
4140 if (code != AC_CONTRACT) {
4143 xpt_print(path, "0x%016llx Port ID 0x%06x %s\n", (unsigned long long) fc->wwpn, fc->port, fc->arrived? "arrived" : "departed");
4147 isp_target_thread(ispsoftc_t *isp, int chan)
4149 union ccb *ccb = NULL;
4153 struct isptarg_softc *softc = NULL;
4154 struct cam_periph *periph = NULL, *wperiph = NULL;
4155 struct cam_path *path, *wpath;
4156 struct cam_sim *sim;
4158 if (disk_data == NULL) {
4159 disk_size = roundup2(vm_kmem_size >> 1, (1ULL << 20));
4160 if (disk_size < (50 << 20)) {
4161 disk_size = 50 << 20;
4163 disk_data = malloc(disk_size, M_ISPTARG, M_WAITOK | M_ZERO);
4164 if (disk_data == NULL) {
4165 isp_prt(isp, ISP_LOGERR, "%s: could not allocate disk data", __func__);
4168 isp_prt(isp, ISP_LOGINFO, "allocated a %ju MiB disk", (uintmax_t) (disk_size >> 20));
4170 junk_data = malloc(JUNK_SIZE, M_ISPTARG, M_WAITOK | M_ZERO);
4171 if (junk_data == NULL) {
4172 isp_prt(isp, ISP_LOGERR, "%s: could not allocate junk", __func__);
4177 softc = malloc(sizeof (*softc), M_ISPTARG, M_WAITOK | M_ZERO);
4178 if (softc == NULL) {
4179 isp_prt(isp, ISP_LOGERR, "%s: could not allocate softc", __func__);
4182 TAILQ_INIT(&softc->work_queue);
4183 TAILQ_INIT(&softc->rework_queue);
4184 TAILQ_INIT(&softc->running_queue);
4185 TAILQ_INIT(&softc->inot_queue);
4188 periphdriver_register(&isptargdriver);
4189 ISP_GET_PC(isp, chan, sim, sim);
4190 ISP_GET_PC(isp, chan, path, path);
4191 status = xpt_create_path(&wpath, NULL, cam_sim_path(sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
4192 if (status != CAM_REQ_CMP) {
4193 isp_prt(isp, ISP_LOGERR, "%s: could not allocate wildcard path", __func__);
4196 status = xpt_create_path(&path, NULL, cam_sim_path(sim), 0, 0);
4197 if (status != CAM_REQ_CMP) {
4198 xpt_free_path(wpath);
4199 isp_prt(isp, ISP_LOGERR, "%s: could not allocate path", __func__);
4204 status = cam_periph_alloc(isptargctor, NULL, isptargdtor, isptargstart, "isptarg", CAM_PERIPH_BIO, wpath, NULL, 0, softc);
4205 if (status != CAM_REQ_CMP) {
4207 isp_prt(isp, ISP_LOGERR, "%s: cam_periph_alloc for wildcard failed", __func__);
4210 wperiph = cam_periph_find(wpath, "isptarg");
4211 if (wperiph == NULL) {
4213 isp_prt(isp, ISP_LOGERR, "%s: wildcard periph already allocated but doesn't exist", __func__);
4217 status = cam_periph_alloc(isptargctor, NULL, isptargdtor, isptargstart, "isptarg", CAM_PERIPH_BIO, path, NULL, 0, softc);
4218 if (status != CAM_REQ_CMP) {
4220 isp_prt(isp, ISP_LOGERR, "%s: cam_periph_alloc failed", __func__);
4224 periph = cam_periph_find(path, "isptarg");
4225 if (periph == NULL) {
4227 isp_prt(isp, ISP_LOGERR, "%s: periph already allocated but doesn't exist", __func__);
4231 status = xpt_register_async(AC_CONTRACT, isptargasync, isp, wpath);
4232 if (status != CAM_REQ_CMP) {
4234 isp_prt(isp, ISP_LOGERR, "%s: xpt_register_async failed", __func__);
4240 ccb = xpt_alloc_ccb();
4243 * Make sure role is none.
4245 xpt_setup_ccb(&ccb->ccb_h, periph->path, 10);
4246 ccb->ccb_h.func_code = XPT_SET_SIM_KNOB;
4247 ccb->knob.xport_specific.fc.role = KNOB_ROLE_NONE;
4248 ccb->knob.xport_specific.fc.valid = KNOB_VALID_ROLE;
4257 xpt_setup_ccb(&ccb->ccb_h, periph->path, 10);
4258 ccb->ccb_h.func_code = XPT_EN_LUN;
4259 ccb->cel.enable = 1;
4263 if (ccb->ccb_h.status != CAM_REQ_CMP) {
4265 xpt_print(periph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status);
4269 xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 10);
4270 ccb->ccb_h.func_code = XPT_EN_LUN;
4271 ccb->cel.enable = 1;
4275 if (ccb->ccb_h.status != CAM_REQ_CMP) {
4277 xpt_print(wperiph->path, "failed to enable lun (0x%x)\n", ccb->ccb_h.status);
4285 ISP_GET_PC(isp, chan, target_proc, wchan);
4286 for (i = 0; i < 4; i++) {
4287 ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
4288 xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1);
4289 ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
4290 ccb->ccb_h.cbfcnp = isptarg_done;
4291 ccb->ccb_h.ppriv_ptr0 = malloc(sizeof (ppd_t), M_ISPTARG, M_WAITOK | M_ZERO);
4296 for (i = 0; i < NISP_TARG_CMDS; i++) {
4297 ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
4298 xpt_setup_ccb(&ccb->ccb_h, periph->path, 1);
4299 ccb->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
4300 ccb->ccb_h.cbfcnp = isptarg_done;
4301 ccb->ccb_h.ppriv_ptr0 = malloc(sizeof (ppd_t), M_ISPTARG, M_WAITOK | M_ZERO);
4306 for (i = 0; i < 4; i++) {
4307 ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
4308 xpt_setup_ccb(&ccb->ccb_h, wperiph->path, 1);
4309 ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY;
4310 ccb->ccb_h.cbfcnp = isptarg_done;
4315 for (i = 0; i < NISP_TARG_NOTIFIES; i++) {
4316 ccb = malloc(sizeof (*ccb), M_ISPTARG, M_WAITOK | M_ZERO);
4317 xpt_setup_ccb(&ccb->ccb_h, periph->path, 1);
4318 ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY;
4319 ccb->ccb_h.cbfcnp = isptarg_done;
4326 * Now turn it all back on
4328 xpt_setup_ccb(&ccb->ccb_h, periph->path, 10);
4329 ccb->ccb_h.func_code = XPT_SET_SIM_KNOB;
4330 ccb->knob.xport_specific.fc.valid = KNOB_VALID_ROLE;
4331 ccb->knob.xport_specific.fc.role = KNOB_ROLE_TARGET;
4337 * Okay, while things are still active, sleep...
4341 ISP_GET_PC(isp, chan, proc_active, i);
4345 msleep(wchan, &isp->isp_lock, PUSER, "tsnooze", 0);
4351 cam_periph_invalidate(wperiph);
4354 cam_periph_invalidate(periph);
4357 free(junk_data, M_ISPTARG);
4360 free(disk_data, M_ISPTARG);
4363 free(softc, M_ISPTARG);
4365 xpt_free_path(path);
4366 xpt_free_path(wpath);
4370 isp_target_thread_pi(void *arg)
4372 struct isp_spi *pi = arg;
4373 ispsoftc_t *isp = cam_sim_softc(pi->sim);
4374 int chan = cam_sim_bus(pi->sim);
4376 isp_target_thread(isp, chan);
4377 ISP_SPI_PC(isp, chan)->num_threads -= 1;
4382 isp_target_thread_fc(void *arg)
4384 struct isp_fc *fc = arg;
4385 ispsoftc_t *isp = cam_sim_softc(pi->sim);
4386 int chan = cam_sim_bus(pi->sim);
4388 isp_target_thread(isp, chan);
4389 ISP_FC_PC(isp, chan)->num_threads -= 1;
4394 isptarg_rwparm(uint8_t *cdb, uint8_t *dp, uint64_t dl, uint32_t offset, uint8_t **kp, uint32_t *tl, int *lp)
4396 uint32_t cnt, curcnt;
4402 cnt = (((uint32_t)cdb[10]) << 24) |
4403 (((uint32_t)cdb[11]) << 16) |
4404 (((uint32_t)cdb[12]) << 8) |
4405 ((uint32_t)cdb[13]);
4407 lba = (((uint64_t)cdb[2]) << 56) |
4408 (((uint64_t)cdb[3]) << 48) |
4409 (((uint64_t)cdb[4]) << 40) |
4410 (((uint64_t)cdb[5]) << 32) |
4411 (((uint64_t)cdb[6]) << 24) |
4412 (((uint64_t)cdb[7]) << 16) |
4413 (((uint64_t)cdb[8]) << 8) |
4418 cnt = (((uint32_t)cdb[6]) << 16) |
4419 (((uint32_t)cdb[7]) << 8) |
4420 ((u_int32_t)cdb[8]);
4422 lba = (((uint32_t)cdb[2]) << 24) |
4423 (((uint32_t)cdb[3]) << 16) |
4424 (((uint32_t)cdb[4]) << 8) |
4429 cnt = (((uint32_t)cdb[7]) << 8) |
4430 ((u_int32_t)cdb[8]);
4432 lba = (((uint32_t)cdb[2]) << 24) |
4433 (((uint32_t)cdb[3]) << 16) |
4434 (((uint32_t)cdb[4]) << 8) |
4443 lba = (((uint32_t)cdb[1] & 0x1f) << 16) |
4444 (((uint32_t)cdb[2]) << 8) |
4454 if (offset == cnt) {
4459 if (lba + cnt > dl) {
4463 curcnt = MAX_ISP_TARG_TRANSFER;
4464 if (offset + curcnt >= cnt) {
4465 curcnt = cnt - offset;
4470 #ifdef ISP_MULTI_CCBS
4471 if (curcnt > MULTI_CCB_DATA_LIM)
4472 curcnt = MULTI_CCB_DATA_LIM;
4475 *kp = &dp[lba + offset];
4483 isp_cam_async(void *cbarg, uint32_t code, struct cam_path *path, void *arg)
4485 struct cam_sim *sim;
4489 sim = (struct cam_sim *)cbarg;
4490 isp = (ispsoftc_t *) cam_sim_softc(sim);
4491 bus = cam_sim_bus(sim);
4492 tgt = xpt_path_target_id(path);
4495 case AC_LOST_DEVICE:
4497 uint16_t oflags, nflags;
4498 sdparam *sdp = SDPARAM(isp, bus);
4501 nflags = sdp->isp_devparam[tgt].nvrm_flags;
4502 #ifndef ISP_TARGET_MODE
4503 nflags &= DPARM_SAFE_DFLT;
4504 if (isp->isp_loaded_fw) {
4505 nflags |= DPARM_NARROW | DPARM_ASYNC;
4508 nflags = DPARM_DEFAULT;
4510 oflags = sdp->isp_devparam[tgt].goal_flags;
4511 sdp->isp_devparam[tgt].goal_flags = nflags;
4512 sdp->isp_devparam[tgt].dev_update = 1;
4514 (void) isp_control(isp, ISPCTL_UPDATE_PARAMS, bus);
4515 sdp->isp_devparam[tgt].goal_flags = oflags;
4520 isp_prt(isp, ISP_LOGWARN, "isp_cam_async: Code 0x%x", code);
4526 isp_poll(struct cam_sim *sim)
4528 ispsoftc_t *isp = cam_sim_softc(sim);
4530 uint16_t sema, mbox;
4532 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
4533 isp_intr(isp, isr, sema, mbox);
4539 isp_watchdog(void *arg)
4541 struct ccb_scsiio *xs = arg;
4543 uint32_t ohandle = ISP_HANDLE_FREE, handle;
4547 handle = isp_find_handle(isp, xs);
4550 * Hand crank the interrupt code just to be sure the command isn't stuck somewhere.
4552 if (handle != ISP_HANDLE_FREE) {
4554 uint16_t sema, mbox;
4555 if (ISP_READ_ISR(isp, &isr, &sema, &mbox) != 0) {
4556 isp_intr(isp, isr, sema, mbox);
4559 handle = isp_find_handle(isp, xs);
4561 if (handle != ISP_HANDLE_FREE) {
4563 * Try and make sure the command is really dead before
4564 * we release the handle (and DMA resources) for reuse.
4566 * If we are successful in aborting the command then
4567 * we're done here because we'll get the command returned
4570 if (isp_control(isp, ISPCTL_ABORT_CMD, xs) == 0) {
4575 * Note that after calling the above, the command may in
4576 * fact have been completed.
4578 xs = isp_find_xs(isp, handle);
4581 * If the command no longer exists, then we won't
4582 * be able to find the xs again with this handle.
4589 * After this point, the command is really dead.
4591 if (XS_XFRLEN(xs)) {
4592 ISP_DMAFREE(isp, xs, handle);
4594 isp_destroy_handle(isp, handle);
4595 isp_prt(isp, ISP_LOGERR, "%s: timeout for handle 0x%x", __func__, handle);
4596 xs->ccb_h.status &= ~CAM_STATUS_MASK;
4597 xs->ccb_h.status |= CAM_CMD_TIMEOUT;
4598 isp_prt_endcmd(isp, xs);
4601 if (ohandle != ISP_HANDLE_FREE) {
4602 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle 0x%x, recovered during interrupt", __func__, ohandle);
4604 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle already free", __func__);
4610 isp_make_here(ispsoftc_t *isp, fcportdb_t *fcp, int chan, int tgt)
4613 struct isp_fc *fc = ISP_FC_PC(isp, chan);
4615 if (isp_autoconfig == 0) {
4620 * Allocate a CCB, create a wildcard path for this target and schedule a rescan.
4622 ccb = xpt_alloc_ccb_nowait();
4624 isp_prt(isp, ISP_LOGWARN, "Chan %d unable to alloc CCB for rescan", chan);
4627 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(fc->sim),
4628 tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
4629 isp_prt(isp, ISP_LOGWARN, "unable to create path for rescan");
4635 * Since we're about to issue a rescan, mark this device as not
4638 fcp->reported_gone = 0;
4644 isp_make_gone(ispsoftc_t *isp, fcportdb_t *fcp, int chan, int tgt)
4646 struct cam_path *tp;
4647 struct isp_fc *fc = ISP_FC_PC(isp, chan);
4649 if (isp_autoconfig == 0) {
4652 if (xpt_create_path(&tp, NULL, cam_sim_path(fc->sim), tgt, CAM_LUN_WILDCARD) == CAM_REQ_CMP) {
4654 * We're about to send out the lost device async
4655 * notification, so indicate that we have reported it gone.
4657 fcp->reported_gone = 1;
4658 xpt_async(AC_LOST_DEVICE, tp, NULL);
4664 * Gone Device Timer Function- when we have decided that a device has gone
4665 * away, we wait a specific period of time prior to telling the OS it has
4668 * This timer function fires once a second and then scans the port database
4669 * for devices that are marked dead but still have a virtual target assigned.
4670 * We decrement a counter for that port database entry, and when it hits zero,
4671 * we tell the OS the device has gone away.
4676 struct isp_fc *fc = arg;
4677 taskqueue_enqueue(taskqueue_thread, &fc->gtask);
4681 isp_gdt_task(void *arg, int pending)
4683 struct isp_fc *fc = arg;
4684 ispsoftc_t *isp = fc->isp;
4685 int chan = fc - isp->isp_osinfo.pc.fc;
4687 int dbidx, tgt, more_to_do = 0;
4690 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d GDT timer expired", chan);
4691 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
4692 lp = &FCPARAM(isp, chan)->portdb[dbidx];
4694 if (lp->state != FC_PORTDB_STATE_ZOMBIE) {
4697 if (lp->dev_map_idx == 0 || lp->target_mode) {
4700 if (lp->gone_timer != 0) {
4701 isp_prt(isp, ISP_LOG_SANCFG, "%s: Chan %d more to do for target %u (timer=%u)", __func__, chan, lp->dev_map_idx - 1, lp->gone_timer);
4702 lp->gone_timer -= 1;
4706 tgt = lp->dev_map_idx - 1;
4707 FCPARAM(isp, chan)->isp_dev_map[tgt] = 0;
4708 lp->dev_map_idx = 0;
4709 lp->state = FC_PORTDB_STATE_NIL;
4710 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, lp->portid, tgt, "Gone Device Timeout");
4711 isp_make_gone(isp, lp, chan, tgt);
4715 callout_reset(&fc->gdt, hz, isp_gdt, fc);
4717 callout_deactivate(&fc->gdt);
4718 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Stopping Gone Device Timer @ %lu", chan, (unsigned long) time_uptime);
4725 * Loop Down Timer Function- when loop goes down, a timer is started and
4726 * and after it expires we come here and take all probational devices that
4727 * the OS knows about and the tell the OS that they've gone away.
4729 * We don't clear the devices out of our port database because, when loop
4730 * come back up, we have to do some actual cleanup with the chip at that
4731 * point (implicit PLOGO, e.g., to get the chip's port database state right).
4736 struct isp_fc *fc = arg;
4737 taskqueue_enqueue(taskqueue_thread, &fc->ltask);
4741 isp_ldt_task(void *arg, int pending)
4743 struct isp_fc *fc = arg;
4744 ispsoftc_t *isp = fc->isp;
4745 int chan = fc - isp->isp_osinfo.pc.fc;
4750 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Loop Down Timer expired @ %lu", chan, (unsigned long) time_uptime);
4751 callout_deactivate(&fc->ldt);
4754 * Notify to the OS all targets who we now consider have departed.
4756 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
4757 lp = &FCPARAM(isp, chan)->portdb[dbidx];
4759 if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
4762 if (lp->dev_map_idx == 0 || lp->target_mode) {
4767 * XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
4771 for (i = 0; i < isp->isp_maxcmds; i++) {
4772 struct ccb_scsiio *xs;
4774 if (!ISP_VALID_HANDLE(isp, isp->isp_xflist[i].handle)) {
4777 if ((xs = isp->isp_xflist[i].cmd) == NULL) {
4780 if (dbidx != (FCPARAM(isp, chan)->isp_dev_map[XS_TGT(xs)] - 1)) {
4783 isp_prt(isp, ISP_LOGWARN, "command handle 0x%x for %d.%d.%d orphaned by loop down timeout",
4784 isp->isp_xflist[i].handle, chan, XS_TGT(xs), XS_LUN(xs));
4788 * Mark that we've announced that this device is gone....
4793 * but *don't* change the state of the entry. Just clear
4794 * any target id stuff and announce to CAM that the
4795 * device is gone. This way any necessary PLOGO stuff
4796 * will happen when loop comes back up.
4799 tgt = lp->dev_map_idx - 1;
4800 FCPARAM(isp, chan)->isp_dev_map[tgt] = 0;
4801 lp->dev_map_idx = 0;
4802 lp->state = FC_PORTDB_STATE_NIL;
4803 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, lp->portid, tgt, "Loop Down Timeout");
4804 isp_make_gone(isp, lp, chan, tgt);
4807 if (FCPARAM(isp, chan)->role & ISP_ROLE_INITIATOR) {
4808 isp_unfreeze_loopdown(isp, chan);
4811 * The loop down timer has expired. Wake up the kthread
4812 * to notice that fact (or make it false).
4815 fc->loop_down_time = fc->loop_down_limit+1;
4821 isp_kthread(void *arg)
4823 struct isp_fc *fc = arg;
4824 ispsoftc_t *isp = fc->isp;
4825 int chan = fc - isp->isp_osinfo.pc.fc;
4828 mtx_lock(&isp->isp_osinfo.lock);
4830 while (isp->isp_osinfo.is_exiting == 0) {
4833 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d checking FC state", __func__, chan);
4834 lb = isp_fc_runstate(isp, chan, 250000);
4837 * Our action is different based upon whether we're supporting
4838 * Initiator mode or not. If we are, we might freeze the simq
4839 * when loop is down and set all sorts of different delays to
4842 * If not, we simply just wait for loop to come up.
4844 if (lb && (FCPARAM(isp, chan)->role & ISP_ROLE_INITIATOR)) {
4846 * Increment loop down time by the last sleep interval
4848 fc->loop_down_time += slp;
4851 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC loop not up (down count %d)", __func__, chan, fc->loop_down_time);
4853 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC got to %d (down count %d)", __func__, chan, lb, fc->loop_down_time);
4857 * If we've never seen loop up and we've waited longer
4858 * than quickboot time, or we've seen loop up but we've
4859 * waited longer than loop_down_limit, give up and go
4860 * to sleep until loop comes up.
4862 if (FCPARAM(isp, chan)->loop_seen_once == 0) {
4863 lim = isp_quickboot_time;
4865 lim = fc->loop_down_limit;
4867 if (fc->loop_down_time >= lim) {
4868 isp_freeze_loopdown(isp, chan, "loop limit hit");
4870 } else if (fc->loop_down_time < 10) {
4872 } else if (fc->loop_down_time < 30) {
4874 } else if (fc->loop_down_time < 60) {
4876 } else if (fc->loop_down_time < 120) {
4883 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC Loop Down", __func__, chan);
4884 fc->loop_down_time += slp;
4885 if (fc->loop_down_time > 300)
4890 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC state OK", __func__, chan);
4891 fc->loop_down_time = 0;
4897 * If this is past the first loop up or the loop is dead and if we'd frozen the simq, unfreeze it
4898 * now so that CAM can start sending us commands.
4900 * If the FC state isn't okay yet, they'll hit that in isp_start which will freeze the queue again
4901 * or kill the commands, as appropriate.
4904 if (FCPARAM(isp, chan)->loop_seen_once || fc->loop_dead) {
4905 isp_unfreeze_loopdown(isp, chan);
4908 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep time %d", __func__, chan, slp);
4910 msleep(fc, &isp->isp_osinfo.lock, PRIBIO, "ispf", slp * hz);
4913 * If slp is zero, we're waking up for the first time after
4914 * things have been okay. In this case, we set a deferral state
4915 * for all commands and delay hysteresis seconds before starting
4916 * the FC state evaluation. This gives the loop/fabric a chance
4919 if (slp == 0 && fc->hysteresis) {
4920 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep hysteresis ticks %d", __func__, chan, fc->hysteresis * hz);
4921 mtx_unlock(&isp->isp_osinfo.lock);
4922 pause("ispt", fc->hysteresis * hz);
4923 mtx_lock(&isp->isp_osinfo.lock);
4926 fc->num_threads -= 1;
4927 mtx_unlock(&isp->isp_osinfo.lock);
4932 isp_action(struct cam_sim *sim, union ccb *ccb)
4934 int bus, tgt, ts, error, lim;
4936 struct ccb_trans_settings *cts;
4938 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
4940 isp = (ispsoftc_t *)cam_sim_softc(sim);
4941 mtx_assert(&isp->isp_lock, MA_OWNED);
4942 isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
4943 ISP_PCMD(ccb) = NULL;
4945 if (isp->isp_state != ISP_RUNSTATE && ccb->ccb_h.func_code == XPT_SCSI_IO) {
4947 if (isp->isp_state != ISP_INITSTATE) {
4949 * Lie. Say it was a selection timeout.
4951 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
4952 isp_done((struct ccb_scsiio *) ccb);
4955 isp->isp_state = ISP_RUNSTATE;
4958 switch (ccb->ccb_h.func_code) {
4959 case XPT_SCSI_IO: /* Execute the requested I/O operation */
4960 bus = XS_CHANNEL(ccb);
4962 * Do a couple of preliminary checks...
4964 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
4965 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
4966 ccb->ccb_h.status = CAM_REQ_INVALID;
4967 isp_done((struct ccb_scsiio *) ccb);
4971 ccb->csio.req_map = NULL;
4973 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
4974 xpt_print(ccb->ccb_h.path, "invalid target\n");
4975 ccb->ccb_h.status = CAM_PATH_INVALID;
4976 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
4977 xpt_print(ccb->ccb_h.path, "invalid lun\n");
4978 ccb->ccb_h.status = CAM_PATH_INVALID;
4980 if (ccb->ccb_h.status == CAM_PATH_INVALID) {
4985 ccb->csio.scsi_status = SCSI_STATUS_OK;
4986 if (isp_get_pcmd(isp, ccb)) {
4987 isp_prt(isp, ISP_LOGWARN, "out of PCMDs");
4988 cam_freeze_devq(ccb->ccb_h.path);
4989 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
4990 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4994 error = isp_start((XS_T *) ccb);
4997 ccb->ccb_h.status |= CAM_SIM_QUEUED;
4998 if (ccb->ccb_h.timeout == CAM_TIME_INFINITY) {
5001 ts = ccb->ccb_h.timeout;
5002 if (ts == CAM_TIME_DEFAULT) {
5005 ts = isp_mstohz(ts);
5006 callout_reset(&PISP_PCMD(ccb)->wdog, ts, isp_watchdog, ccb);
5010 * We get this result for FC devices if the loop state isn't ready yet
5011 * or if the device in question has gone zombie on us.
5013 * If we've never seen Loop UP at all, we requeue this request and wait
5014 * for the initial loop up delay to expire.
5016 lim = ISP_FC_PC(isp, bus)->loop_down_limit;
5017 if (FCPARAM(isp, bus)->loop_seen_once == 0 || ISP_FC_PC(isp, bus)->loop_down_time >= lim) {
5018 if (FCPARAM(isp, bus)->loop_seen_once == 0) {
5019 isp_prt(isp, ISP_LOGDEBUG0, "%d.%d loop not seen yet @ %lu", XS_TGT(ccb), XS_LUN(ccb), (unsigned long) time_uptime);
5021 isp_prt(isp, ISP_LOGDEBUG0, "%d.%d downtime (%d) > lim (%d)", XS_TGT(ccb), XS_LUN(ccb), ISP_FC_PC(isp, bus)->loop_down_time, lim);
5023 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
5024 isp_done((struct ccb_scsiio *) ccb);
5027 isp_prt(isp, ISP_LOGDEBUG0, "%d.%d retry later", XS_TGT(ccb), XS_LUN(ccb));
5028 cam_freeze_devq(ccb->ccb_h.path);
5029 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
5030 ccb->ccb_h.status = CAM_REQUEUE_REQ;
5031 isp_free_pcmd(isp, ccb);
5035 isp_free_pcmd(isp, ccb);
5036 cam_freeze_devq(ccb->ccb_h.path);
5037 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 100, 0);
5038 ccb->ccb_h.status = CAM_REQUEUE_REQ;
5042 isp_done((struct ccb_scsiio *) ccb);
5045 isp_prt(isp, ISP_LOGERR, "What's this? 0x%x at %d in file %s", error, __LINE__, __FILE__);
5046 ccb->ccb_h.status = CAM_REQUEUE_REQ;
5047 isp_free_pcmd(isp, ccb);
5052 #ifdef ISP_TARGET_MODE
5053 case XPT_EN_LUN: /* Enable/Disable LUN as a target */
5054 if (ccb->cel.enable) {
5055 isp_enable_lun(isp, ccb);
5057 isp_disable_lun(isp, ccb);
5060 case XPT_IMMED_NOTIFY:
5061 case XPT_IMMEDIATE_NOTIFY: /* Add Immediate Notify Resource */
5062 case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
5064 tstate_t *tptr = get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun);
5066 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), CAM_LUN_WILDCARD);
5072 if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY) {
5073 str = "XPT_IMMEDIATE_NOTIFY";
5074 tag = ccb->cin1.seq_id;
5076 tag = ccb->atio.tag_id;
5077 str = "XPT_ACCEPT_TARGET_IO";
5079 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "%s: [0x%x] no state pointer found for %s\n", __func__, tag, str);
5080 dump_tstates(isp, XS_CHANNEL(ccb));
5081 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
5084 ccb->ccb_h.spriv_field0 = 0;
5085 ccb->ccb_h.spriv_ptr1 = isp;
5087 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
5088 if (ccb->atio.tag_id) {
5089 atio_private_data_t *atp = isp_find_atpd(isp, tptr, ccb->atio.tag_id);
5091 isp_put_atpd(isp, tptr, atp);
5095 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h, sim_links.sle);
5096 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE ATIO (tag id 0x%x), count now %d\n",
5097 ccb->atio.tag_id, tptr->atio_count);
5098 ccb->atio.tag_id = 0;
5099 } else if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY) {
5100 if (ccb->cin1.tag_id) {
5101 inot_private_data_t *ntp = isp_find_ntpd(isp, tptr, ccb->cin1.tag_id, ccb->cin1.seq_id);
5103 isp_put_ntpd(isp, tptr, ntp);
5107 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
5108 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
5109 ccb->cin1.seq_id, tptr->inot_count);
5110 ccb->cin1.seq_id = 0;
5111 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
5113 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
5114 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
5115 ccb->cin1.seq_id, tptr->inot_count);
5116 ccb->cin1.seq_id = 0;
5118 rls_lun_statep(isp, tptr);
5119 ccb->ccb_h.status = CAM_REQ_INPROG;
5122 case XPT_NOTIFY_ACK:
5123 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5125 case XPT_NOTIFY_ACKNOWLEDGE: /* notify ack */
5128 inot_private_data_t *ntp;
5131 * XXX: Because we cannot guarantee that the path information in the notify acknowledge ccb
5132 * XXX: matches that for the immediate notify, we have to *search* for the notify structure
5135 * All the relevant path information is in the associated immediate notify
5137 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);
5138 ntp = get_ntp_from_tagdata(isp, ccb->cna2.tag_id, ccb->cna2.seq_id, &tptr);
5140 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__,
5141 ccb->cna2.tag_id, ccb->cna2.seq_id);
5142 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
5146 if (isp_handle_platform_target_notify_ack(isp, &ntp->rd.nt)) {
5147 rls_lun_statep(isp, tptr);
5148 cam_freeze_devq(ccb->ccb_h.path);
5149 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
5150 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
5151 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
5154 isp_put_ntpd(isp, tptr, ntp);
5155 rls_lun_statep(isp, tptr);
5156 ccb->ccb_h.status = CAM_REQ_CMP;
5157 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);
5161 case XPT_CONT_TARGET_IO:
5162 isp_target_start_ctio(isp, ccb, FROM_CAM);
5165 case XPT_RESET_DEV: /* BDR the specified SCSI device */
5169 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
5170 tgt = ccb->ccb_h.target_id;
5173 fc = ISP_FC_PC(isp, bus);
5177 error = isp_control(isp, ISPCTL_RESET_DEV, bus, tgt);
5179 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5182 * If we have a FC device, reset the Command
5183 * Reference Number, because the target will expect
5184 * that we re-start the CRN at 1 after a reset.
5187 isp_fcp_reset_crn(fc, tgt, /*tgt_set*/ 1);
5189 ccb->ccb_h.status = CAM_REQ_CMP;
5194 case XPT_ABORT: /* Abort the specified CCB */
5196 union ccb *accb = ccb->cab.abort_ccb;
5197 switch (accb->ccb_h.func_code) {
5198 #ifdef ISP_TARGET_MODE
5199 case XPT_ACCEPT_TARGET_IO:
5200 isp_target_mark_aborted(isp, ccb);
5204 error = isp_control(isp, ISPCTL_ABORT_CMD, accb);
5206 ccb->ccb_h.status = CAM_UA_ABORT;
5208 ccb->ccb_h.status = CAM_REQ_CMP;
5212 ccb->ccb_h.status = CAM_REQ_INVALID;
5216 * This is not a queued CCB, so the caller expects it to be
5217 * complete when control is returned.
5221 #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
5222 case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */
5224 if (!IS_CURRENT_SETTINGS(cts)) {
5225 ccb->ccb_h.status = CAM_REQ_INVALID;
5229 tgt = cts->ccb_h.target_id;
5230 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
5232 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
5233 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
5234 sdparam *sdp = SDPARAM(isp, bus);
5237 if (spi->valid == 0 && scsi->valid == 0) {
5238 ccb->ccb_h.status = CAM_REQ_CMP;
5244 * We always update (internally) from goal_flags
5245 * so any request to change settings just gets
5246 * vectored to that location.
5248 dptr = &sdp->isp_devparam[tgt].goal_flags;
5250 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
5251 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
5252 *dptr |= DPARM_DISC;
5254 *dptr &= ~DPARM_DISC;
5257 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
5258 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
5259 *dptr |= DPARM_TQING;
5261 *dptr &= ~DPARM_TQING;
5264 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
5265 if (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT)
5266 *dptr |= DPARM_WIDE;
5268 *dptr &= ~DPARM_WIDE;
5274 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) && (spi->valid & CTS_SPI_VALID_SYNC_RATE) && (spi->sync_period && spi->sync_offset)) {
5275 *dptr |= DPARM_SYNC;
5277 * XXX: CHECK FOR LEGALITY
5279 sdp->isp_devparam[tgt].goal_period = spi->sync_period;
5280 sdp->isp_devparam[tgt].goal_offset = spi->sync_offset;
5282 *dptr &= ~DPARM_SYNC;
5284 isp_prt(isp, ISP_LOGDEBUG0, "SET (%d.%d.%d) to flags %x off %x per %x", bus, tgt, cts->ccb_h.target_lun, sdp->isp_devparam[tgt].goal_flags,
5285 sdp->isp_devparam[tgt].goal_offset, sdp->isp_devparam[tgt].goal_period);
5286 sdp->isp_devparam[tgt].dev_update = 1;
5289 ccb->ccb_h.status = CAM_REQ_CMP;
5292 case XPT_GET_TRAN_SETTINGS:
5294 tgt = cts->ccb_h.target_id;
5295 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
5297 fcparam *fcp = FCPARAM(isp, bus);
5298 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
5299 struct ccb_trans_settings_fc *fc = &cts->xport_specific.fc;
5300 unsigned int hdlidx;
5302 cts->protocol = PROTO_SCSI;
5303 cts->protocol_version = SCSI_REV_2;
5304 cts->transport = XPORT_FC;
5305 cts->transport_version = 0;
5307 scsi->valid = CTS_SCSI_VALID_TQ;
5308 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
5309 fc->valid = CTS_FC_VALID_SPEED;
5310 fc->bitrate = 100000;
5311 fc->bitrate *= fcp->isp_gbspeed;
5312 hdlidx = fcp->isp_dev_map[tgt] - 1;
5313 if (hdlidx < MAX_FC_TARG) {
5314 fcportdb_t *lp = &fcp->portdb[hdlidx];
5315 fc->wwnn = lp->node_wwn;
5316 fc->wwpn = lp->port_wwn;
5317 fc->port = lp->portid;
5318 fc->valid |= CTS_FC_VALID_WWNN | CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT;
5321 struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi;
5322 struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
5323 sdparam *sdp = SDPARAM(isp, bus);
5324 uint16_t dval, pval, oval;
5326 if (IS_CURRENT_SETTINGS(cts)) {
5327 sdp->isp_devparam[tgt].dev_refresh = 1;
5329 (void) isp_control(isp, ISPCTL_UPDATE_PARAMS, bus);
5330 dval = sdp->isp_devparam[tgt].actv_flags;
5331 oval = sdp->isp_devparam[tgt].actv_offset;
5332 pval = sdp->isp_devparam[tgt].actv_period;
5334 dval = sdp->isp_devparam[tgt].nvrm_flags;
5335 oval = sdp->isp_devparam[tgt].nvrm_offset;
5336 pval = sdp->isp_devparam[tgt].nvrm_period;
5339 cts->protocol = PROTO_SCSI;
5340 cts->protocol_version = SCSI_REV_2;
5341 cts->transport = XPORT_SPI;
5342 cts->transport_version = 2;
5348 if (dval & DPARM_DISC) {
5349 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
5351 if ((dval & DPARM_SYNC) && oval && pval) {
5352 spi->sync_offset = oval;
5353 spi->sync_period = pval;
5355 spi->sync_offset = 0;
5356 spi->sync_period = 0;
5358 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
5359 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
5360 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
5361 if (dval & DPARM_WIDE) {
5362 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5364 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5366 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
5367 scsi->valid = CTS_SCSI_VALID_TQ;
5368 if (dval & DPARM_TQING) {
5369 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
5371 spi->valid |= CTS_SPI_VALID_DISC;
5373 isp_prt(isp, ISP_LOGDEBUG0, "GET %s (%d.%d.%d) to flags %x off %x per %x", IS_CURRENT_SETTINGS(cts)? "ACTIVE" : "NVRAM",
5374 bus, tgt, cts->ccb_h.target_lun, dval, oval, pval);
5376 ccb->ccb_h.status = CAM_REQ_CMP;
5380 case XPT_CALC_GEOMETRY:
5381 cam_calc_geometry(&ccb->ccg, 1);
5385 case XPT_RESET_BUS: /* Reset the specified bus */
5386 bus = cam_sim_bus(sim);
5387 error = isp_control(isp, ISPCTL_RESET_BUS, bus);
5389 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5394 xpt_print(ccb->ccb_h.path, "reset bus on channel %d\n", bus);
5397 xpt_async(AC_BUS_RESET, ISP_FC_PC(isp, bus)->path, 0);
5399 xpt_async(AC_BUS_RESET, ISP_SPI_PC(isp, bus)->path, 0);
5401 ccb->ccb_h.status = CAM_REQ_CMP;
5405 case XPT_TERM_IO: /* Terminate the I/O process */
5406 ccb->ccb_h.status = CAM_REQ_INVALID;
5410 case XPT_SET_SIM_KNOB: /* Set SIM knobs */
5412 struct ccb_sim_knob *kp = &ccb->knob;
5416 ccb->ccb_h.status = CAM_REQ_INVALID;
5421 bus = cam_sim_bus(xpt_path_sim(kp->ccb_h.path));
5422 fcp = FCPARAM(isp, bus);
5424 if (kp->xport_specific.fc.valid & KNOB_VALID_ADDRESS) {
5425 fcp->isp_wwnn = ISP_FC_PC(isp, bus)->def_wwnn = kp->xport_specific.fc.wwnn;
5426 fcp->isp_wwpn = ISP_FC_PC(isp, bus)->def_wwpn = kp->xport_specific.fc.wwpn;
5427 isp_prt(isp, ISP_LOGALL, "Setting Channel %d wwns to 0x%jx 0x%jx", bus, fcp->isp_wwnn, fcp->isp_wwpn);
5429 ccb->ccb_h.status = CAM_REQ_CMP;
5430 if (kp->xport_specific.fc.valid & KNOB_VALID_ROLE) {
5434 switch (kp->xport_specific.fc.role) {
5435 case KNOB_ROLE_NONE:
5436 if (fcp->role != ISP_ROLE_NONE) {
5438 newrole = ISP_ROLE_NONE;
5441 case KNOB_ROLE_TARGET:
5442 if (fcp->role != ISP_ROLE_TARGET) {
5444 newrole = ISP_ROLE_TARGET;
5447 case KNOB_ROLE_INITIATOR:
5448 if (fcp->role != ISP_ROLE_INITIATOR) {
5450 newrole = ISP_ROLE_INITIATOR;
5453 case KNOB_ROLE_BOTH:
5455 if (fcp->role != ISP_ROLE_BOTH) {
5457 newrole = ISP_ROLE_BOTH;
5461 * We don't really support dual role at present on FC cards.
5463 * We should, but a bunch of things are currently broken,
5464 * so don't allow it.
5466 isp_prt(isp, ISP_LOGERR, "cannot support dual role at present");
5467 ccb->ccb_h.status = CAM_REQ_INVALID;
5472 ISP_PATH_PRT(isp, ISP_LOGCONFIG, ccb->ccb_h.path, "changing role on from %d to %d\n", fcp->role, newrole);
5473 #ifdef ISP_TARGET_MODE
5474 ISP_SET_PC(isp, bus, tm_enabled, 0);
5475 ISP_SET_PC(isp, bus, tm_luns_enabled, 0);
5477 if (isp_control(isp, ISPCTL_CHANGE_ROLE,
5478 bus, newrole) != 0) {
5479 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5483 #ifdef ISP_TARGET_MODE
5484 if (newrole == ISP_ROLE_TARGET || newrole == ISP_ROLE_BOTH) {
5486 * Give the new role a chance to complain and settle
5488 msleep(isp, &isp->isp_lock, PRIBIO, "taking a breather", 2);
5489 ccb->ccb_h.status = isp_enable_deferred_luns(isp, bus);
5497 case XPT_GET_SIM_KNOB: /* Get SIM knobs */
5499 struct ccb_sim_knob *kp = &ccb->knob;
5504 bus = cam_sim_bus(xpt_path_sim(kp->ccb_h.path));
5505 fcp = FCPARAM(isp, bus);
5507 kp->xport_specific.fc.wwnn = fcp->isp_wwnn;
5508 kp->xport_specific.fc.wwpn = fcp->isp_wwpn;
5509 switch (fcp->role) {
5511 kp->xport_specific.fc.role = KNOB_ROLE_NONE;
5513 case ISP_ROLE_TARGET:
5514 kp->xport_specific.fc.role = KNOB_ROLE_TARGET;
5516 case ISP_ROLE_INITIATOR:
5517 kp->xport_specific.fc.role = KNOB_ROLE_INITIATOR;
5520 kp->xport_specific.fc.role = KNOB_ROLE_BOTH;
5523 kp->xport_specific.fc.valid = KNOB_VALID_ADDRESS | KNOB_VALID_ROLE;
5524 ccb->ccb_h.status = CAM_REQ_CMP;
5526 ccb->ccb_h.status = CAM_REQ_INVALID;
5531 case XPT_PATH_INQ: /* Path routing inquiry */
5533 struct ccb_pathinq *cpi = &ccb->cpi;
5535 cpi->version_num = 1;
5536 #ifdef ISP_TARGET_MODE
5537 cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
5539 cpi->target_sprt = 0;
5541 cpi->hba_eng_cnt = 0;
5542 cpi->max_target = ISP_MAX_TARGETS(isp) - 1;
5543 cpi->max_lun = ISP_MAX_LUNS(isp) - 1;
5544 cpi->bus_id = cam_sim_bus(sim);
5545 if (isp->isp_osinfo.sixtyfourbit)
5546 cpi->maxio = (ISP_NSEG64_MAX - 1) * PAGE_SIZE;
5548 cpi->maxio = (ISP_NSEG_MAX - 1) * PAGE_SIZE;
5550 bus = cam_sim_bus(xpt_path_sim(cpi->ccb_h.path));
5552 fcparam *fcp = FCPARAM(isp, bus);
5554 cpi->hba_misc = PIM_NOBUSRESET | PIM_UNMAPPED;
5557 * Because our loop ID can shift from time to time,
5558 * make our initiator ID out of range of our bus.
5560 cpi->initiator_id = cpi->max_target + 1;
5563 * Set base transfer capabilities for Fibre Channel, for this HBA.
5566 cpi->base_transfer_speed = 8000000;
5567 } else if (IS_24XX(isp)) {
5568 cpi->base_transfer_speed = 4000000;
5569 } else if (IS_23XX(isp)) {
5570 cpi->base_transfer_speed = 2000000;
5572 cpi->base_transfer_speed = 1000000;
5574 cpi->hba_inquiry = PI_TAG_ABLE;
5575 cpi->transport = XPORT_FC;
5576 cpi->transport_version = 0;
5577 cpi->xport_specific.fc.wwnn = fcp->isp_wwnn;
5578 cpi->xport_specific.fc.wwpn = fcp->isp_wwpn;
5579 cpi->xport_specific.fc.port = fcp->isp_portid;
5580 cpi->xport_specific.fc.bitrate = fcp->isp_gbspeed * 1000;
5582 sdparam *sdp = SDPARAM(isp, bus);
5583 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
5584 cpi->hba_misc = PIM_UNMAPPED;
5585 cpi->initiator_id = sdp->isp_initiator_id;
5586 cpi->base_transfer_speed = 3300;
5587 cpi->transport = XPORT_SPI;
5588 cpi->transport_version = 2;
5590 cpi->protocol = PROTO_SCSI;
5591 cpi->protocol_version = SCSI_REV_2;
5592 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
5593 strncpy(cpi->hba_vid, "Qlogic", HBA_IDLEN);
5594 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
5595 cpi->unit_number = cam_sim_unit(sim);
5596 cpi->ccb_h.status = CAM_REQ_CMP;
5601 ccb->ccb_h.status = CAM_REQ_INVALID;
5607 #define ISPDDB (CAM_DEBUG_INFO|CAM_DEBUG_TRACE|CAM_DEBUG_CDB)
5610 isp_done(XS_T *sccb)
5612 ispsoftc_t *isp = XS_ISP(sccb);
5616 XS_SETERR(sccb, CAM_REQ_CMP);
5618 if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP && (sccb->scsi_status != SCSI_STATUS_OK)) {
5619 sccb->ccb_h.status &= ~CAM_STATUS_MASK;
5620 if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) && (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) {
5621 sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
5623 sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
5627 sccb->ccb_h.status &= ~CAM_SIM_QUEUED;
5628 status = sccb->ccb_h.status & CAM_STATUS_MASK;
5629 if (status != CAM_REQ_CMP) {
5630 if (status != CAM_SEL_TIMEOUT)
5631 isp_prt(isp, ISP_LOGDEBUG0, "target %d lun %d CAM status 0x%x SCSI status 0x%x", XS_TGT(sccb), XS_LUN(sccb), sccb->ccb_h.status, sccb->scsi_status);
5632 else if ((IS_FC(isp))
5633 && (XS_TGT(sccb) < MAX_FC_TARG)) {
5637 fcp = FCPARAM(isp, XS_CHANNEL(sccb));
5638 hdlidx = fcp->isp_dev_map[XS_TGT(sccb)] - 1;
5640 * Note that we have reported that this device is
5641 * gone. If it reappears, we'll need to issue a
5644 if (hdlidx >= 0 && hdlidx < MAX_FC_TARG)
5645 fcp->portdb[hdlidx].reported_gone = 1;
5647 if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
5648 sccb->ccb_h.status |= CAM_DEV_QFRZN;
5649 xpt_freeze_devq(sccb->ccb_h.path, 1);
5653 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) && (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5654 xpt_print(sccb->ccb_h.path, "cam completion status 0x%x\n", sccb->ccb_h.status);
5657 if (ISP_PCMD(sccb)) {
5658 if (callout_active(&PISP_PCMD(sccb)->wdog))
5659 callout_stop(&PISP_PCMD(sccb)->wdog);
5660 isp_free_pcmd(isp, (union ccb *) sccb);
5662 xpt_done((union ccb *) sccb);
5666 isp_async(ispsoftc_t *isp, ispasync_t cmd, ...)
5669 static const char prom0[] = "Chan %d PortID 0x%06x handle 0x%x %s %s WWPN 0x%08x%08x";
5670 static const char prom2[] = "Chan %d PortID 0x%06x handle 0x%x %s %s tgt %u WWPN 0x%08x%08x";
5676 struct cam_path *tmppath;
5680 case ISPASYNC_NEW_TGT_PARAMS:
5682 struct ccb_trans_settings_scsi *scsi;
5683 struct ccb_trans_settings_spi *spi;
5686 struct ccb_trans_settings cts;
5688 memset(&cts, 0, sizeof (struct ccb_trans_settings));
5691 bus = va_arg(ap, int);
5692 tgt = va_arg(ap, int);
5694 sdp = SDPARAM(isp, bus);
5696 if (xpt_create_path(&tmppath, NULL, cam_sim_path(ISP_SPI_PC(isp, bus)->sim), tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
5697 isp_prt(isp, ISP_LOGWARN, "isp_async cannot make temp path for %d.%d", tgt, bus);
5700 flags = sdp->isp_devparam[tgt].actv_flags;
5701 cts.type = CTS_TYPE_CURRENT_SETTINGS;
5702 cts.protocol = PROTO_SCSI;
5703 cts.transport = XPORT_SPI;
5705 scsi = &cts.proto_specific.scsi;
5706 spi = &cts.xport_specific.spi;
5708 if (flags & DPARM_TQING) {
5709 scsi->valid |= CTS_SCSI_VALID_TQ;
5710 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
5713 if (flags & DPARM_DISC) {
5714 spi->valid |= CTS_SPI_VALID_DISC;
5715 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
5717 spi->flags |= CTS_SPI_VALID_BUS_WIDTH;
5718 if (flags & DPARM_WIDE) {
5719 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
5721 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
5723 if (flags & DPARM_SYNC) {
5724 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
5725 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
5726 spi->sync_period = sdp->isp_devparam[tgt].actv_period;
5727 spi->sync_offset = sdp->isp_devparam[tgt].actv_offset;
5729 isp_prt(isp, ISP_LOGDEBUG2, "NEW_TGT_PARAMS bus %d tgt %d period %x offset %x flags %x", bus, tgt, sdp->isp_devparam[tgt].actv_period, sdp->isp_devparam[tgt].actv_offset, flags);
5730 xpt_setup_ccb(&cts.ccb_h, tmppath, 1);
5731 xpt_async(AC_TRANSFER_NEG, tmppath, &cts);
5732 xpt_free_path(tmppath);
5735 case ISPASYNC_BUS_RESET:
5738 bus = va_arg(ap, int);
5740 isp_prt(isp, ISP_LOGINFO, "SCSI bus reset on bus %d detected", bus);
5742 xpt_async(AC_BUS_RESET, ISP_FC_PC(isp, bus)->path, NULL);
5744 xpt_async(AC_BUS_RESET, ISP_SPI_PC(isp, bus)->path, NULL);
5750 msg = "LIP Received";
5753 case ISPASYNC_LOOP_RESET:
5758 case ISPASYNC_LOOP_DOWN:
5764 bus = va_arg(ap, int);
5767 FCPARAM(isp, bus)->link_active = 0;
5769 fc = ISP_FC_PC(isp, bus);
5770 if (cmd == ISPASYNC_LOOP_DOWN && fc->ready) {
5772 * We don't do any simq freezing if we are only in target mode
5774 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5776 isp_freeze_loopdown(isp, bus, msg);
5778 if (!callout_active(&fc->ldt)) {
5779 callout_reset(&fc->ldt, fc->loop_down_limit * hz, isp_ldt, fc);
5780 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Starting Loop Down Timer @ %lu", (unsigned long) time_uptime);
5784 isp_fcp_reset_crn(fc, /*tgt*/0, /*tgt_set*/ 0);
5786 isp_prt(isp, ISP_LOGINFO, "Chan %d: %s", bus, msg);
5789 case ISPASYNC_LOOP_UP:
5791 bus = va_arg(ap, int);
5793 fc = ISP_FC_PC(isp, bus);
5795 * Now we just note that Loop has come up. We don't
5796 * actually do anything because we're waiting for a
5797 * Change Notify before activating the FC cleanup
5798 * thread to look at the state of the loop again.
5800 FCPARAM(isp, bus)->link_active = 1;
5802 fc->loop_down_time = 0;
5803 isp_prt(isp, ISP_LOGINFO, "Chan %d Loop UP", bus);
5805 case ISPASYNC_DEV_ARRIVED:
5807 bus = va_arg(ap, int);
5808 lp = va_arg(ap, fcportdb_t *);
5810 fc = ISP_FC_PC(isp, bus);
5813 if ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) && (lp->prli_word3 & PRLI_WD3_TARGET_FUNCTION)) {
5814 int dbidx = lp - FCPARAM(isp, bus)->portdb;
5817 for (i = 0; i < MAX_FC_TARG; i++) {
5818 if (i >= FL_ID && i <= SNS_ID) {
5821 if (FCPARAM(isp, bus)->isp_dev_map[i] == 0) {
5825 if (i < MAX_FC_TARG) {
5826 FCPARAM(isp, bus)->isp_dev_map[i] = dbidx + 1;
5827 lp->dev_map_idx = i + 1;
5829 isp_prt(isp, ISP_LOGWARN, "out of target ids");
5830 isp_dump_portdb(isp, bus);
5833 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5834 if (lp->dev_map_idx) {
5835 tgt = lp->dev_map_idx - 1;
5836 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "arrived at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5837 isp_fcp_reset_crn(fc, tgt, /*tgt_set*/ 1);
5838 isp_make_here(isp, lp, bus, tgt);
5840 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "arrived", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5843 case ISPASYNC_DEV_CHANGED:
5845 bus = va_arg(ap, int);
5846 lp = va_arg(ap, fcportdb_t *);
5848 fc = ISP_FC_PC(isp, bus);
5851 if (isp_change_is_bad) {
5852 lp->state = FC_PORTDB_STATE_NIL;
5853 if (lp->dev_map_idx) {
5854 tgt = lp->dev_map_idx - 1;
5855 FCPARAM(isp, bus)->isp_dev_map[tgt] = 0;
5856 lp->dev_map_idx = 0;
5857 isp_prt(isp, ISP_LOGCONFIG, prom3, bus, lp->portid, tgt, "change is bad");
5858 isp_make_gone(isp, lp, bus, tgt);
5860 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5861 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "changed and departed",
5862 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5865 lp->portid = lp->new_portid;
5866 lp->prli_word3 = lp->new_prli_word3;
5867 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5868 if (lp->dev_map_idx) {
5869 int t = lp->dev_map_idx - 1;
5870 FCPARAM(isp, bus)->isp_dev_map[t] = (lp - FCPARAM(isp, bus)->portdb) + 1;
5871 tgt = lp->dev_map_idx - 1;
5872 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "changed at", tgt,
5873 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5874 isp_fcp_reset_crn(fc, tgt, /*tgt_set*/ 1);
5876 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "changed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5880 case ISPASYNC_DEV_STAYED:
5882 bus = va_arg(ap, int);
5883 lp = va_arg(ap, fcportdb_t *);
5885 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5886 if (lp->dev_map_idx) {
5887 fc = ISP_FC_PC(isp, bus);
5888 tgt = lp->dev_map_idx - 1;
5889 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "stayed at", tgt,
5890 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5892 * Only issue a rescan if we've actually reported
5893 * that this device is gone.
5895 if (lp->reported_gone != 0) {
5896 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "rescanned at", tgt,
5897 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5898 isp_make_here(isp, lp, bus, tgt);
5901 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "stayed",
5902 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5905 case ISPASYNC_DEV_GONE:
5907 bus = va_arg(ap, int);
5908 lp = va_arg(ap, fcportdb_t *);
5909 now = va_arg(ap, int);
5911 fc = ISP_FC_PC(isp, bus);
5913 * If this has a virtual target and we haven't marked it
5914 * that we're going to have isp_gdt tell the OS it's gone,
5915 * set the isp_gdt timer running on it.
5917 * If it isn't marked that isp_gdt is going to get rid of it,
5918 * announce that it's gone.
5921 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5922 if (lp->dev_map_idx && lp->announced == 0 && now) {
5924 tgt = lp->dev_map_idx - 1;
5925 FCPARAM(isp, bus)->isp_dev_map[tgt] = 0;
5926 lp->dev_map_idx = 0;
5927 isp_make_gone(isp, lp, bus, tgt);
5928 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "gone at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5929 isp_fcp_reset_crn(fc, tgt, /*tgt_set*/ 1);
5930 } else if (lp->dev_map_idx && lp->announced == 0) {
5932 lp->state = FC_PORTDB_STATE_ZOMBIE;
5933 lp->gone_timer = ISP_FC_PC(isp, bus)->gone_device_time;
5934 if (fc->ready && !callout_active(&fc->gdt)) {
5935 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);
5936 callout_reset(&fc->gdt, hz, isp_gdt, fc);
5938 tgt = lp->dev_map_idx - 1;
5939 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "gone zombie at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5940 isp_fcp_reset_crn(fc, tgt, /*tgt_set*/ 1);
5941 } else if (lp->announced == 0) {
5942 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "departed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5945 case ISPASYNC_CHANGE_NOTIFY:
5948 int evt, nphdl, nlstate, reason;
5951 bus = va_arg(ap, int);
5952 evt = va_arg(ap, int);
5953 if (IS_24XX(isp) && evt == ISPASYNC_CHANGE_PDB) {
5954 nphdl = va_arg(ap, int);
5955 nlstate = va_arg(ap, int);
5956 reason = va_arg(ap, int);
5959 nlstate = reason = 0;
5962 fc = ISP_FC_PC(isp, bus);
5964 if (evt == ISPASYNC_CHANGE_PDB) {
5965 msg = "Chan %d Port Database Changed";
5966 } else if (evt == ISPASYNC_CHANGE_SNS) {
5967 msg = "Chan %d Name Server Database Changed";
5969 msg = "Chan %d Other Change Notify";
5973 * If the loop down timer is running, cancel it.
5975 if (fc->ready && callout_active(&fc->ldt)) {
5976 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Stopping Loop Down Timer @ %lu", (unsigned long) time_uptime);
5977 callout_stop(&fc->ldt);
5979 isp_prt(isp, ISP_LOGINFO, msg, bus);
5980 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5981 isp_freeze_loopdown(isp, bus, msg);
5986 #ifdef ISP_TARGET_MODE
5987 case ISPASYNC_TARGET_NOTIFY:
5989 isp_notify_t *notify;
5991 notify = va_arg(ap, isp_notify_t *);
5993 switch (notify->nt_ncode) {
5995 case NT_ABORT_TASK_SET:
5997 case NT_CLEAR_TASK_SET:
5999 case NT_TARGET_RESET:
6001 * These are task management functions.
6003 isp_handle_platform_target_tmf(isp, notify);
6010 * No action need be taken here.
6014 isp_del_all_wwn_entries(isp, ISP_NOCHAN);
6016 case NT_GLOBAL_LOGOUT:
6019 * This is device arrival/departure notification
6021 isp_handle_platform_target_notify_ack(isp, notify);
6025 struct ac_contract ac;
6026 struct ac_device_changed *fc;
6028 ac.contract_number = AC_CONTRACT_DEV_CHG;
6029 fc = (struct ac_device_changed *) ac.contract_data;
6030 fc->wwpn = notify->nt_wwn;
6031 fc->port = notify->nt_sid;
6032 fc->target = notify->nt_nphdl;
6034 xpt_async(AC_CONTRACT, ISP_FC_PC(isp, notify->nt_channel)->path, &ac);
6039 struct ac_contract ac;
6040 struct ac_device_changed *fc;
6042 ac.contract_number = AC_CONTRACT_DEV_CHG;
6043 fc = (struct ac_device_changed *) ac.contract_data;
6044 fc->wwpn = notify->nt_wwn;
6045 fc->port = notify->nt_sid;
6046 fc->target = notify->nt_nphdl;
6048 xpt_async(AC_CONTRACT, ISP_FC_PC(isp, notify->nt_channel)->path, &ac);
6052 isp_prt(isp, ISP_LOGALL, "target notify code 0x%x", notify->nt_ncode);
6053 isp_handle_platform_target_notify_ack(isp, notify);
6058 case ISPASYNC_TARGET_NOTIFY_ACK:
6062 inot = va_arg(ap, void *);
6064 if (isp_notify_ack(isp, inot)) {
6065 isp_tna_t *tp = malloc(sizeof (*tp), M_DEVBUF, M_NOWAIT);
6069 memcpy(tp->data, inot, sizeof (tp->data));
6074 callout_init_mtx(&tp->timer, &isp->isp_lock, 0);
6075 callout_reset(&tp->timer, 5,
6076 isp_refire_notify_ack, tp);
6078 isp_prt(isp, ISP_LOGERR, "you lose- cannot allocate a notify refire");
6083 case ISPASYNC_TARGET_ACTION:
6088 hp = va_arg(ap, isphdr_t *);
6090 switch (hp->rqs_entry_type) {
6092 isp_prt(isp, ISP_LOGWARN, "%s: unhandled target action 0x%x", __func__, hp->rqs_entry_type);
6094 case RQSTYPE_NOTIFY:
6096 isp_handle_platform_notify_scsi(isp, (in_entry_t *) hp);
6097 } else if (IS_24XX(isp)) {
6098 isp_handle_platform_notify_24xx(isp, (in_fcentry_24xx_t *) hp);
6100 isp_handle_platform_notify_fc(isp, (in_fcentry_t *) hp);
6105 isp_handle_platform_atio7(isp, (at7_entry_t *) hp);
6107 isp_handle_platform_atio(isp, (at_entry_t *) hp);
6111 isp_handle_platform_atio2(isp, (at2_entry_t *) hp);
6117 isp_handle_platform_ctio(isp, hp);
6119 case RQSTYPE_ABTS_RCVD:
6121 abts_t *abts = (abts_t *)hp;
6122 isp_notify_t notify, *nt = ¬ify;
6128 did = (abts->abts_did_hi << 16) | abts->abts_did_lo;
6129 sid = (abts->abts_sid_hi << 16) | abts->abts_sid_lo;
6130 ISP_MEMZERO(nt, sizeof (isp_notify_t));
6134 nt->nt_nphdl = abts->abts_nphdl;
6136 isp_find_chan_by_did(isp, did, &chan);
6137 if (chan == ISP_NOCHAN) {
6138 nt->nt_tgt = TGT_ANY;
6140 nt->nt_tgt = FCPARAM(isp, chan)->isp_wwpn;
6141 if (isp_find_pdb_by_loopid(isp, chan, abts->abts_nphdl, &lp)) {
6142 nt->nt_wwn = lp->port_wwn;
6144 nt->nt_wwn = INI_ANY;
6148 * Try hard to find the lun for this command.
6150 tptr = get_lun_statep_from_tag(isp, chan, abts->abts_rxid_task);
6152 nt->nt_lun = tptr->ts_lun;
6153 rls_lun_statep(isp, tptr);
6155 nt->nt_lun = LUN_ANY;
6157 nt->nt_need_ack = 1;
6158 nt->nt_tagval = abts->abts_rxid_task;
6159 nt->nt_tagval |= (((uint64_t) abts->abts_rxid_abts) << 32);
6160 if (abts->abts_rxid_task == ISP24XX_NO_TASK) {
6161 isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS from N-Port handle 0x%x Port 0x%06x has no task id (rx_id 0x%04x ox_id 0x%04x)",
6162 abts->abts_rxid_abts, abts->abts_nphdl, sid, abts->abts_rx_id, abts->abts_ox_id);
6164 isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS from N-Port handle 0x%x Port 0x%06x for task 0x%x (rx_id 0x%04x ox_id 0x%04x)",
6165 abts->abts_rxid_abts, abts->abts_nphdl, sid, abts->abts_rxid_task, abts->abts_rx_id, abts->abts_ox_id);
6167 nt->nt_channel = chan;
6168 nt->nt_ncode = NT_ABORT_TASK;
6169 nt->nt_lreserved = hp;
6170 isp_handle_platform_target_tmf(isp, nt);
6173 case RQSTYPE_ENABLE_LUN:
6174 case RQSTYPE_MODIFY_LUN:
6175 isp_ledone(isp, (lun_entry_t *) hp);
6181 case ISPASYNC_FW_CRASH:
6183 uint16_t mbox1, mbox6;
6184 mbox1 = ISP_READ(isp, OUTMAILBOX1);
6185 if (IS_DUALBUS(isp)) {
6186 mbox6 = ISP_READ(isp, OUTMAILBOX6);
6190 isp_prt(isp, ISP_LOGERR, "Internal Firmware Error on bus %d @ RISC Address 0x%x", mbox6, mbox1);
6191 mbox1 = isp->isp_osinfo.mbox_sleep_ok;
6192 isp->isp_osinfo.mbox_sleep_ok = 0;
6194 isp->isp_osinfo.mbox_sleep_ok = mbox1;
6195 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
6199 isp_prt(isp, ISP_LOGERR, "unknown isp_async event %d", cmd);
6206 * Locks are held before coming here.
6209 isp_uninit(ispsoftc_t *isp)
6212 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
6214 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
6216 ISP_DISABLE_INTS(isp);
6220 * When we want to get the 'default' WWNs (when lacking NVRAM), we pick them
6221 * up from our platform default (defww{p|n}n) and morph them based upon
6224 * When we want to get the 'active' WWNs, we get NVRAM WWNs and then morph them
6225 * based upon channel.
6229 isp_default_wwn(ispsoftc_t * isp, int chan, int isactive, int iswwnn)
6232 struct isp_fc *fc = ISP_FC_PC(isp, chan);
6235 * If we're asking for a active WWN, the default overrides get
6236 * returned, otherwise the NVRAM value is picked.
6238 * If we're asking for a default WWN, we just pick the default override.
6241 seed = iswwnn ? fc->def_wwnn : fc->def_wwpn;
6245 seed = iswwnn ? FCPARAM(isp, chan)->isp_wwnn_nvram : FCPARAM(isp, chan)->isp_wwpn_nvram;
6249 return (0x400000007F000009ull);
6252 seed = iswwnn ? fc->def_wwnn : fc->def_wwpn;
6255 * For channel zero just return what we have. For either ACTIVE or
6256 * DEFAULT cases, we depend on default override of NVRAM values for
6264 * For other channels, we are doing one of three things:
6266 * 1. If what we have now is non-zero, return it. Otherwise we morph
6267 * values from channel 0. 2. If we're here for a WWPN we synthesize
6268 * it if Channel 0's wwpn has a type 2 NAA. 3. If we're here for a
6269 * WWNN we synthesize it if Channel 0's wwnn has a type 2 NAA.
6275 seed = iswwnn ? ISP_FC_PC(isp, 0)->def_wwnn : ISP_FC_PC(isp, 0)->def_wwpn;
6277 seed = iswwnn ? FCPARAM(isp, 0)->isp_wwnn_nvram : FCPARAM(isp, 0)->isp_wwpn_nvram;
6279 if (((seed >> 60) & 0xf) == 2) {
6281 * The type 2 NAA fields for QLogic cards appear be laid out
6284 * bits 63..60 NAA == 2 bits 59..57 unused/zero bit 56
6285 * port (1) or node (0) WWN distinguishor bit 48
6286 * physical port on dual-port chips (23XX/24XX)
6288 * This is somewhat nutty, particularly since bit 48 is
6289 * irrelevant as they assign separate serial numbers to
6290 * different physical ports anyway.
6292 * We'll stick our channel number plus one first into bits
6293 * 57..59 and thence into bits 52..55 which allows for 8 bits
6294 * of channel which is comfortably more than our maximum
6297 seed &= ~0x0FF0000000000000ULL;
6299 seed |= ((uint64_t) (chan + 1) & 0xf) << 56;
6300 seed |= ((uint64_t) ((chan + 1) >> 4) & 0xf) << 52;
6309 isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
6315 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
6318 snprintf(lbuf, sizeof (lbuf), "%s: ", device_get_nameunit(isp->isp_dev));
6321 vsnprintf(&lbuf[loc], sizeof (lbuf) - loc - 1, fmt, ap);
6323 printf("%s\n", lbuf);
6327 isp_xs_prt(ispsoftc_t *isp, XS_T *xs, int level, const char *fmt, ...)
6330 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
6333 xpt_print_path(xs->ccb_h.path);
6341 isp_nanotime_sub(struct timespec *b, struct timespec *a)
6344 struct timespec x = *b;
6346 elapsed = GET_NANOSEC(&x);
6353 isp_mbox_acquire(ispsoftc_t *isp)
6355 if (isp->isp_osinfo.mboxbsy) {
6358 isp->isp_osinfo.mboxcmd_done = 0;
6359 isp->isp_osinfo.mboxbsy = 1;
6365 isp_mbox_wait_complete(ispsoftc_t *isp, mbreg_t *mbp)
6367 unsigned int usecs = mbp->timeout;
6368 unsigned int max, olim, ilim;
6371 usecs = MBCMD_DEFAULT_TIMEOUT;
6373 max = isp->isp_mbxwrk0 + 1;
6375 if (isp->isp_osinfo.mbox_sleep_ok) {
6376 unsigned int ms = (usecs + 999) / 1000;
6378 isp->isp_osinfo.mbox_sleep_ok = 0;
6379 isp->isp_osinfo.mbox_sleeping = 1;
6380 for (olim = 0; olim < max; olim++) {
6381 msleep(&isp->isp_mbxworkp, &isp->isp_osinfo.lock, PRIBIO, "ispmbx_sleep", isp_mstohz(ms));
6382 if (isp->isp_osinfo.mboxcmd_done) {
6386 isp->isp_osinfo.mbox_sleep_ok = 1;
6387 isp->isp_osinfo.mbox_sleeping = 0;
6389 for (olim = 0; olim < max; olim++) {
6390 for (ilim = 0; ilim < usecs; ilim += 100) {
6392 uint16_t sema, mbox;
6393 if (isp->isp_osinfo.mboxcmd_done) {
6396 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
6397 isp_intr(isp, isr, sema, mbox);
6398 if (isp->isp_osinfo.mboxcmd_done) {
6404 if (isp->isp_osinfo.mboxcmd_done) {
6409 if (isp->isp_osinfo.mboxcmd_done == 0) {
6410 isp_prt(isp, ISP_LOGWARN, "%s Mailbox Command (0x%x) Timeout (%uus) (started @ %s:%d)",
6411 isp->isp_osinfo.mbox_sleep_ok? "Interrupting" : "Polled", isp->isp_lastmbxcmd, usecs, mbp->func, mbp->lineno);
6412 mbp->param[0] = MBOX_TIMEOUT;
6413 isp->isp_osinfo.mboxcmd_done = 1;
6418 isp_mbox_notify_done(ispsoftc_t *isp)
6420 if (isp->isp_osinfo.mbox_sleeping) {
6421 wakeup(&isp->isp_mbxworkp);
6423 isp->isp_osinfo.mboxcmd_done = 1;
6427 isp_mbox_release(ispsoftc_t *isp)
6429 isp->isp_osinfo.mboxbsy = 0;
6433 isp_fc_scratch_acquire(ispsoftc_t *isp, int chan)
6436 if (isp->isp_osinfo.pc.fc[chan].fcbsy) {
6439 isp->isp_osinfo.pc.fc[chan].fcbsy = 1;
6449 t.tv_sec = ms / 1000;
6450 t.tv_usec = (ms % 1000) * 1000;
6462 isp_platform_intr(void *arg)
6464 ispsoftc_t *isp = arg;
6466 uint16_t sema, mbox;
6470 if (ISP_READ_ISR(isp, &isr, &sema, &mbox) == 0) {
6471 isp->isp_intbogus++;
6473 isp_intr(isp, isr, sema, mbox);
6479 isp_common_dmateardown(ispsoftc_t *isp, struct ccb_scsiio *csio, uint32_t hdl)
6481 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
6482 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTREAD);
6484 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTWRITE);
6486 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
6490 * Reset the command reference number for all LUNs on a specific target
6491 * (needed when a target arrives again) or for all targets on a port
6492 * (needed for events like a LIP).
6495 isp_fcp_reset_crn(struct isp_fc *fc, uint32_t tgt, int tgt_set)
6498 struct isp_nexus *nxp;
6501 isp_prt(fc->isp, ISP_LOG_SANCFG, "resetting CRN on all targets");
6503 isp_prt(fc->isp, ISP_LOG_SANCFG, "resetting CRN target %u", tgt);
6505 for (i = 0; i < NEXUS_HASH_WIDTH; i++) {
6506 nxp = fc->nexus_hash[i];
6508 if ((tgt_set != 0) && (tgt == nxp->tgt))
6517 isp_fcp_next_crn(ispsoftc_t *isp, uint8_t *crnp, XS_T *cmd)
6519 uint32_t chan, tgt, lun;
6521 struct isp_nexus *nxp;
6524 if (isp->isp_type < ISP_HA_FC_2300)
6527 chan = XS_CHANNEL(cmd);
6530 fc = &isp->isp_osinfo.pc.fc[chan];
6531 idx = NEXUS_HASH(tgt, lun);
6532 nxp = fc->nexus_hash[idx];
6535 if (nxp->tgt == tgt && nxp->lun == lun)
6540 nxp = fc->nexus_free_list;
6542 nxp = malloc(sizeof (struct isp_nexus), M_DEVBUF, M_ZERO|M_NOWAIT);
6547 fc->nexus_free_list = nxp->next;
6551 nxp->next = fc->nexus_hash[idx];
6552 fc->nexus_hash[idx] = nxp;
6555 if (nxp->crnseed == 0)
6558 PISP_PCMD(cmd)->crn = nxp->crnseed;
6559 *crnp = nxp->crnseed++;
6566 * We enter with the lock held
6569 isp_timer(void *arg)
6571 ispsoftc_t *isp = arg;
6572 #ifdef ISP_TARGET_MODE
6573 isp_tmcmd_restart(isp);
6575 callout_reset(&isp->isp_osinfo.tmo, isp_timer_count, isp_timer, isp);
6579 isp_get_ecmd(ispsoftc_t *isp)
6581 isp_ecmd_t *ecmd = isp->isp_osinfo.ecmd_free;
6583 isp->isp_osinfo.ecmd_free = ecmd->next;
6589 isp_put_ecmd(ispsoftc_t *isp, isp_ecmd_t *ecmd)
6591 ecmd->next = isp->isp_osinfo.ecmd_free;
6592 isp->isp_osinfo.ecmd_free = ecmd;