1 /* $FreeBSD: src/sys/dev/isp/isp_freebsd.c,v 1.32.2.20 2002/10/11 18:49:25 mjacob Exp $ */
2 /* $DragonFly: src/sys/dev/disk/isp/isp_freebsd.c,v 1.21 2008/05/18 20:30:22 pavalos Exp $ */
4 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
6 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/unistd.h>
30 #include <sys/kthread.h>
32 #include <sys/device.h>
33 #include <machine/stdarg.h> /* for use by isp_prt below */
35 #include "isp_ioctl.h"
36 #include "isp_freebsd.h"
38 static d_ioctl_t ispioctl;
39 static void isp_intr_enable(void *);
40 static void isp_cam_async(void *, u_int32_t, struct cam_path *, void *);
41 static void isp_poll(struct cam_sim *);
42 static timeout_t isp_watchdog;
43 static void isp_kthread(void *);
44 static void isp_action(struct cam_sim *, union ccb *);
47 #define ISP_CDEV_MAJOR 248
48 static struct dev_ops isp_ops = {
49 { "isp", ISP_CDEV_MAJOR, D_TAPE },
55 static struct ispsoftc *isplist = NULL;
58 isp_attach(struct ispsoftc *isp)
60 int primary, secondary;
61 struct ccb_setasync csa;
62 struct cam_devq *devq;
64 struct cam_path *path;
67 * Establish (in case of 12X0) which bus is the primary.
74 * Create the device queue for our SIM(s).
76 devq = cam_simq_alloc(isp->isp_maxcmds);
82 * Construct our SIM entry.
84 ISPLOCK_2_CAMLOCK(isp);
85 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
86 device_get_unit(isp->isp_dev), &sim_mplock, 1, isp->isp_maxcmds, devq);
87 cam_simq_release(devq); /* leaves 1 ref due to cam_sim_alloc */
89 CAMLOCK_2_ISPLOCK(isp);
92 CAMLOCK_2_ISPLOCK(isp);
94 isp->isp_osinfo.ehook.ich_func = isp_intr_enable;
95 isp->isp_osinfo.ehook.ich_arg = isp;
96 isp->isp_osinfo.ehook.ich_desc = "isp";
97 ISPLOCK_2_CAMLOCK(isp);
98 if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) {
100 CAMLOCK_2_ISPLOCK(isp);
101 isp_prt(isp, ISP_LOGERR,
102 "could not establish interrupt enable hook");
106 if (xpt_bus_register(sim, primary) != CAM_SUCCESS) {
108 CAMLOCK_2_ISPLOCK(isp);
112 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
113 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
114 xpt_bus_deregister(cam_sim_path(sim));
116 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
117 CAMLOCK_2_ISPLOCK(isp);
121 xpt_setup_ccb(&csa.ccb_h, path, 5);
122 csa.ccb_h.func_code = XPT_SASYNC_CB;
123 csa.event_enable = AC_LOST_DEVICE;
124 csa.callback = isp_cam_async;
125 csa.callback_arg = sim;
126 xpt_action((union ccb *)&csa);
127 CAMLOCK_2_ISPLOCK(isp);
129 isp->isp_path = path;
131 * Create a kernel thread for fibre channel instances. We
132 * don't have dual channel FC cards.
135 ISPLOCK_2_CAMLOCK(isp);
136 if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kthread,
137 "%s: fc_thrd", device_get_nameunit(isp->isp_dev))) {
138 xpt_bus_deregister(cam_sim_path(sim));
140 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
141 CAMLOCK_2_ISPLOCK(isp);
142 isp_prt(isp, ISP_LOGERR, "could not create kthread");
145 CAMLOCK_2_ISPLOCK(isp);
150 * If we have a second channel, construct SIM entry for that.
152 if (IS_DUALBUS(isp)) {
153 ISPLOCK_2_CAMLOCK(isp);
154 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
155 device_get_unit(isp->isp_dev), &sim_mplock, 1, isp->isp_maxcmds, devq);
157 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
158 xpt_free_path(isp->isp_path);
159 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
162 if (xpt_bus_register(sim, secondary) != CAM_SUCCESS) {
163 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
164 xpt_free_path(isp->isp_path);
166 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
167 CAMLOCK_2_ISPLOCK(isp);
171 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
172 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
173 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
174 xpt_free_path(isp->isp_path);
175 xpt_bus_deregister(cam_sim_path(sim));
177 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
178 CAMLOCK_2_ISPLOCK(isp);
182 xpt_setup_ccb(&csa.ccb_h, path, 5);
183 csa.ccb_h.func_code = XPT_SASYNC_CB;
184 csa.event_enable = AC_LOST_DEVICE;
185 csa.callback = isp_cam_async;
186 csa.callback_arg = sim;
187 xpt_action((union ccb *)&csa);
188 CAMLOCK_2_ISPLOCK(isp);
190 isp->isp_path2 = path;
193 * Create device nodes
195 dev_ops_add(&isp_ops, -1, device_get_unit(isp->isp_dev));
196 make_dev(&isp_ops, device_get_unit(isp->isp_dev), UID_ROOT,
197 GID_OPERATOR, 0600, "%s", device_get_nameunit(isp->isp_dev));
199 if (isp->isp_role != ISP_ROLE_NONE) {
200 isp->isp_state = ISP_RUNSTATE;
202 if (isplist == NULL) {
205 struct ispsoftc *tmp = isplist;
206 while (tmp->isp_osinfo.next) {
207 tmp = tmp->isp_osinfo.next;
209 tmp->isp_osinfo.next = isp;
215 isp_freeze_loopdown(struct ispsoftc *isp, char *msg)
217 if (isp->isp_osinfo.simqfrozen == 0) {
218 isp_prt(isp, ISP_LOGDEBUG0, "%s: freeze simq (loopdown)", msg);
219 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
220 ISPLOCK_2_CAMLOCK(isp);
221 xpt_freeze_simq(isp->isp_sim, 1);
222 CAMLOCK_2_ISPLOCK(isp);
224 isp_prt(isp, ISP_LOGDEBUG0, "%s: mark frozen (loopdown)", msg);
225 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
230 ispioctl(struct dev_ioctl_args *ap)
232 cdev_t dev = ap->a_head.a_dev;
233 struct ispsoftc *isp;
238 if (minor(dev) == device_get_unit(isp->isp_dev)) {
241 isp = isp->isp_osinfo.next;
247 #ifdef ISP_FW_CRASH_DUMP
248 case ISP_GET_FW_CRASH_DUMP:
250 u_int16_t *ptr = FCPARAM(isp)->isp_dump_data;
255 sz = QLA2200_RISC_IMAGE_DUMP_SIZE;
257 sz = QLA2300_RISC_IMAGE_DUMP_SIZE;
260 void *uaddr = *((void **) addr);
261 if (copyout(ptr, uaddr, sz)) {
273 case ISP_FORCE_CRASH_DUMP:
275 isp_freeze_loopdown(isp, "ispioctl(ISP_FORCE_CRASH_DUMP)");
284 int olddblev = isp->isp_dblev;
285 isp->isp_dblev = *(int *)ap->a_data;
286 *(int *)ap->a_data = olddblev;
299 if (isp_fc_runstate(isp, 5 * 1000000)) {
310 if (isp_control(isp, ISPCTL_SEND_LIP, 0)) {
318 case ISP_FC_GETDINFO:
320 struct isp_fc_device *ifc = (struct isp_fc_device *) ap->a_data;
323 if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) {
328 lp = &FCPARAM(isp)->portdb[ifc->loopid];
330 ifc->loopid = lp->loopid;
331 ifc->portid = lp->portid;
332 ifc->node_wwn = lp->node_wwn;
333 ifc->port_wwn = lp->port_wwn;
343 isp_stats_t *sp = (isp_stats_t *) ap->a_data;
345 MEMZERO(sp, sizeof (*sp));
346 sp->isp_stat_version = ISP_STATS_VERSION;
347 sp->isp_type = isp->isp_type;
348 sp->isp_revision = isp->isp_revision;
350 sp->isp_stats[ISP_INTCNT] = isp->isp_intcnt;
351 sp->isp_stats[ISP_INTBOGUS] = isp->isp_intbogus;
352 sp->isp_stats[ISP_INTMBOXC] = isp->isp_intmboxc;
353 sp->isp_stats[ISP_INGOASYNC] = isp->isp_intoasync;
354 sp->isp_stats[ISP_RSLTCCMPLT] = isp->isp_rsltccmplt;
355 sp->isp_stats[ISP_FPHCCMCPLT] = isp->isp_fphccmplt;
356 sp->isp_stats[ISP_RSCCHIWAT] = isp->isp_rscchiwater;
357 sp->isp_stats[ISP_FPCCHIWAT] = isp->isp_fpcchiwater;
365 isp->isp_intbogus = 0;
366 isp->isp_intmboxc = 0;
367 isp->isp_intoasync = 0;
368 isp->isp_rsltccmplt = 0;
369 isp->isp_fphccmplt = 0;
370 isp->isp_rscchiwater = 0;
371 isp->isp_fpcchiwater = 0;
375 case ISP_FC_GETHINFO:
377 struct isp_hba_device *hba = (struct isp_hba_device *) ap->a_data;
378 MEMZERO(hba, sizeof (*hba));
380 hba->fc_speed = FCPARAM(isp)->isp_gbspeed;
381 hba->fc_scsi_supported = 1;
382 hba->fc_topology = FCPARAM(isp)->isp_topo + 1;
383 hba->fc_loopid = FCPARAM(isp)->isp_loopid;
384 hba->active_node_wwn = FCPARAM(isp)->isp_nodewwn;
385 hba->active_port_wwn = FCPARAM(isp)->isp_portwwn;
390 case ISP_GET_FC_PARAM:
392 struct isp_fc_param *f = (struct isp_fc_param *) ap->a_data;
399 if (strcmp(f->param_name, "framelength") == 0) {
400 f->parameter = FCPARAM(isp)->isp_maxfrmlen;
404 if (strcmp(f->param_name, "exec_throttle") == 0) {
405 f->parameter = FCPARAM(isp)->isp_execthrottle;
409 if (strcmp(f->param_name, "fullduplex") == 0) {
410 if (FCPARAM(isp)->isp_fwoptions & ICBOPT_FULL_DUPLEX)
415 if (strcmp(f->param_name, "loopid") == 0) {
416 f->parameter = FCPARAM(isp)->isp_loopid;
423 case ISP_SET_FC_PARAM:
425 struct isp_fc_param *f = (struct isp_fc_param *) ap->a_data;
426 u_int32_t param = f->parameter;
433 if (strcmp(f->param_name, "framelength") == 0) {
434 if (param != 512 && param != 1024 && param != 1024) {
438 FCPARAM(isp)->isp_maxfrmlen = param;
442 if (strcmp(f->param_name, "exec_throttle") == 0) {
443 if (param < 16 || param > 255) {
447 FCPARAM(isp)->isp_execthrottle = param;
451 if (strcmp(f->param_name, "fullduplex") == 0) {
452 if (param != 0 && param != 1) {
457 FCPARAM(isp)->isp_fwoptions |=
460 FCPARAM(isp)->isp_fwoptions &=
466 if (strcmp(f->param_name, "loopid") == 0) {
467 if (param < 0 || param > 125) {
471 FCPARAM(isp)->isp_loopid = param;
485 isp_intr_enable(void *arg)
487 struct ispsoftc *isp = arg;
488 if (isp->isp_role != ISP_ROLE_NONE) {
491 /* Release our hook so that the boot can continue. */
492 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
496 * Put the target mode functions here, because some are inlines
499 #ifdef ISP_TARGET_MODE
501 static INLINE int is_lun_enabled(struct ispsoftc *, int, lun_id_t);
502 static INLINE int are_any_luns_enabled(struct ispsoftc *, int);
503 static INLINE tstate_t *get_lun_statep(struct ispsoftc *, int, lun_id_t);
504 static INLINE void rls_lun_statep(struct ispsoftc *, tstate_t *);
505 static INLINE int isp_psema_sig_rqe(struct ispsoftc *, int);
506 static INLINE int isp_cv_wait_timed_rqe(struct ispsoftc *, int, int);
507 static INLINE void isp_cv_signal_rqe(struct ispsoftc *, int, int);
508 static INLINE void isp_vsema_rqe(struct ispsoftc *, int);
509 static INLINE atio_private_data_t *isp_get_atpd(struct ispsoftc *, int);
511 create_lun_state(struct ispsoftc *, int, struct cam_path *, tstate_t **);
512 static void destroy_lun_state(struct ispsoftc *, tstate_t *);
513 static void isp_en_lun(struct ispsoftc *, union ccb *);
514 static cam_status isp_abort_tgt_ccb(struct ispsoftc *, union ccb *);
515 static timeout_t isp_refire_putback_atio;
516 static void isp_complete_ctio(union ccb *);
517 static void isp_target_putback_atio(union ccb *);
518 static cam_status isp_target_start_ctio(struct ispsoftc *, union ccb *);
519 static int isp_handle_platform_atio(struct ispsoftc *, at_entry_t *);
520 static int isp_handle_platform_atio2(struct ispsoftc *, at2_entry_t *);
521 static int isp_handle_platform_ctio(struct ispsoftc *, void *);
522 static int isp_handle_platform_notify_scsi(struct ispsoftc *, in_entry_t *);
523 static int isp_handle_platform_notify_fc(struct ispsoftc *, in_fcentry_t *);
526 is_lun_enabled(struct ispsoftc *isp, int bus, lun_id_t lun)
529 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
534 if (tptr->lun == (lun_id_t) lun && tptr->bus == bus) {
537 } while ((tptr = tptr->next) != NULL);
542 are_any_luns_enabled(struct ispsoftc *isp, int port)
545 if (IS_DUALBUS(isp)) {
546 lo = (port * (LUN_HASH_SIZE >> 1));
547 hi = lo + (LUN_HASH_SIZE >> 1);
552 for (lo = 0; lo < hi; lo++) {
553 if (isp->isp_osinfo.lun_hash[lo]) {
560 static INLINE tstate_t *
561 get_lun_statep(struct ispsoftc *isp, int bus, lun_id_t lun)
563 tstate_t *tptr = NULL;
565 if (lun == CAM_LUN_WILDCARD) {
566 if (isp->isp_osinfo.tmflags[bus] & TM_WILDCARD_ENABLED) {
567 tptr = &isp->isp_osinfo.tsdflt[bus];
572 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
579 if (tptr->lun == lun && tptr->bus == bus) {
583 } while ((tptr = tptr->next) != NULL);
588 rls_lun_statep(struct ispsoftc *isp, tstate_t *tptr)
595 isp_psema_sig_rqe(struct ispsoftc *isp, int bus)
597 while (isp->isp_osinfo.tmflags[bus] & TM_BUSY) {
598 isp->isp_osinfo.tmflags[bus] |= TM_WANTED;
599 if (tsleep(&isp->isp_osinfo.tmflags[bus], PCATCH, "i0", 0)) {
602 isp->isp_osinfo.tmflags[bus] |= TM_BUSY;
608 isp_cv_wait_timed_rqe(struct ispsoftc *isp, int bus, int timo)
610 if (tsleep(&isp->isp_osinfo.rstatus[bus], 0, "qt1", timo)) {
617 isp_cv_signal_rqe(struct ispsoftc *isp, int bus, int status)
619 isp->isp_osinfo.rstatus[bus] = status;
620 wakeup(&isp->isp_osinfo.rstatus[bus]);
624 isp_vsema_rqe(struct ispsoftc *isp, int bus)
626 if (isp->isp_osinfo.tmflags[bus] & TM_WANTED) {
627 isp->isp_osinfo.tmflags[bus] &= ~TM_WANTED;
628 wakeup(&isp->isp_osinfo.tmflags[bus]);
630 isp->isp_osinfo.tmflags[bus] &= ~TM_BUSY;
633 static __inline atio_private_data_t *
634 isp_get_atpd(struct ispsoftc *isp, int tag)
636 atio_private_data_t *atp;
637 for (atp = isp->isp_osinfo.atpdp;
638 atp < &isp->isp_osinfo.atpdp[ATPDPSIZE]; atp++) {
646 create_lun_state(struct ispsoftc *isp, int bus,
647 struct cam_path *path, tstate_t **rslt)
652 tstate_t *tptr, *new;
654 lun = xpt_path_lun_id(path);
656 return (CAM_LUN_INVALID);
658 if (is_lun_enabled(isp, bus, lun)) {
659 return (CAM_LUN_ALRDY_ENA);
661 new = kmalloc(sizeof (tstate_t), M_DEVBUF, M_WAITOK | M_ZERO);
662 status = xpt_create_path(&new->owner, NULL, xpt_path_path_id(path),
663 xpt_path_target_id(path), xpt_path_lun_id(path));
664 if (status != CAM_REQ_CMP) {
665 kfree(new, M_DEVBUF);
670 SLIST_INIT(&new->atios);
671 SLIST_INIT(&new->inots);
674 hfx = LUN_HASH_FUNC(isp, new->bus, new->lun);
675 tptr = isp->isp_osinfo.lun_hash[hfx];
677 isp->isp_osinfo.lun_hash[hfx] = new;
684 return (CAM_REQ_CMP);
688 destroy_lun_state(struct ispsoftc *isp, tstate_t *tptr)
693 hfx = LUN_HASH_FUNC(isp, tptr->bus, tptr->lun);
697 pw = isp->isp_osinfo.lun_hash[hfx];
700 } else if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
701 isp->isp_osinfo.lun_hash[hfx] = pw->next;
706 if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
717 kfree(tptr, M_DEVBUF);
721 * we enter with our locks held.
724 isp_en_lun(struct ispsoftc *isp, union ccb *ccb)
726 const char lfmt[] = "Lun now %sabled for target mode on channel %d";
727 struct ccb_en_lun *cel = &ccb->cel;
730 int bus, cmd, av, wildcard;
735 bus = XS_CHANNEL(ccb) & 0x1;
736 tgt = ccb->ccb_h.target_id;
737 lun = ccb->ccb_h.target_lun;
740 * Do some sanity checking first.
743 if ((lun != CAM_LUN_WILDCARD) &&
744 (lun < 0 || lun >= (lun_id_t) isp->isp_maxluns)) {
745 ccb->ccb_h.status = CAM_LUN_INVALID;
750 sdparam *sdp = isp->isp_param;
752 if (tgt != CAM_TARGET_WILDCARD &&
753 tgt != sdp->isp_initiator_id) {
754 ccb->ccb_h.status = CAM_TID_INVALID;
758 if (tgt != CAM_TARGET_WILDCARD &&
759 tgt != FCPARAM(isp)->isp_iid) {
760 ccb->ccb_h.status = CAM_TID_INVALID;
764 * This is as a good a place as any to check f/w capabilities.
766 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_TMODE) == 0) {
767 isp_prt(isp, ISP_LOGERR,
768 "firmware does not support target mode");
769 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
773 * XXX: We *could* handle non-SCCLUN f/w, but we'd have to
774 * XXX: dorks with our already fragile enable/disable code.
776 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
777 isp_prt(isp, ISP_LOGERR,
778 "firmware not SCCLUN capable");
782 if (tgt == CAM_TARGET_WILDCARD) {
783 if (lun == CAM_LUN_WILDCARD) {
786 ccb->ccb_h.status = CAM_LUN_INVALID;
794 * Next check to see whether this is a target/lun wildcard action.
796 * If so, we know that we can accept commands for luns that haven't
797 * been enabled yet and send them upstream. Otherwise, we have to
798 * handle them locally (if we see them at all).
802 tptr = &isp->isp_osinfo.tsdflt[bus];
804 if (isp->isp_osinfo.tmflags[bus] &
805 TM_WILDCARD_ENABLED) {
806 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
810 xpt_create_path(&tptr->owner, NULL,
811 xpt_path_path_id(ccb->ccb_h.path),
812 xpt_path_target_id(ccb->ccb_h.path),
813 xpt_path_lun_id(ccb->ccb_h.path));
814 if (ccb->ccb_h.status != CAM_REQ_CMP) {
817 SLIST_INIT(&tptr->atios);
818 SLIST_INIT(&tptr->inots);
819 isp->isp_osinfo.tmflags[bus] |= TM_WILDCARD_ENABLED;
821 if ((isp->isp_osinfo.tmflags[bus] &
822 TM_WILDCARD_ENABLED) == 0) {
823 ccb->ccb_h.status = CAM_REQ_CMP;
827 ccb->ccb_h.status = CAM_SCSI_BUSY;
830 xpt_free_path(tptr->owner);
831 isp->isp_osinfo.tmflags[bus] &= ~TM_WILDCARD_ENABLED;
836 * Now check to see whether this bus needs to be
837 * enabled/disabled with respect to target mode.
840 if (cel->enable && !(isp->isp_osinfo.tmflags[bus] & TM_TMODE_ENABLED)) {
841 av |= ENABLE_TARGET_FLAG;
842 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
844 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
846 isp->isp_osinfo.tmflags[bus] &=
847 ~TM_WILDCARD_ENABLED;
848 xpt_free_path(tptr->owner);
852 isp->isp_osinfo.tmflags[bus] |= TM_TMODE_ENABLED;
853 isp_prt(isp, ISP_LOGINFO,
854 "Target Mode enabled on channel %d", bus);
855 } else if (cel->enable == 0 &&
856 (isp->isp_osinfo.tmflags[bus] & TM_TMODE_ENABLED) && wildcard) {
857 if (are_any_luns_enabled(isp, bus)) {
858 ccb->ccb_h.status = CAM_SCSI_BUSY;
861 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
863 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
866 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
867 isp_prt(isp, ISP_LOGINFO,
868 "Target Mode disabled on channel %d", bus);
872 ccb->ccb_h.status = CAM_REQ_CMP;
878 create_lun_state(isp, bus, ccb->ccb_h.path, &tptr);
879 if (ccb->ccb_h.status != CAM_REQ_CMP) {
883 tptr = get_lun_statep(isp, bus, lun);
885 ccb->ccb_h.status = CAM_LUN_INVALID;
890 if (isp_psema_sig_rqe(isp, bus)) {
891 rls_lun_statep(isp, tptr);
893 destroy_lun_state(isp, tptr);
894 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
899 u_int32_t seq = isp->isp_osinfo.rollinfo++;
900 int c, n, ulun = lun;
902 cmd = RQSTYPE_ENABLE_LUN;
905 if (IS_FC(isp) && lun != 0) {
906 cmd = RQSTYPE_MODIFY_LUN;
909 * For SCC firmware, we only deal with setting
910 * (enabling or modifying) lun 0.
915 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq)) {
916 xpt_print_path(ccb->ccb_h.path);
917 isp_prt(isp, ISP_LOGWARN, "isp_lun_cmd failed");
920 if (isp_cv_wait_timed_rqe(isp, bus, 30 * hz)) {
921 xpt_print_path(ccb->ccb_h.path);
922 isp_prt(isp, ISP_LOGERR,
923 "wait for ENABLE/MODIFY LUN timed out");
926 rstat = isp->isp_osinfo.rstatus[bus];
927 if (rstat != LUN_OK) {
928 xpt_print_path(ccb->ccb_h.path);
929 isp_prt(isp, ISP_LOGERR,
930 "ENABLE/MODIFY LUN returned 0x%x", rstat);
934 int c, n, ulun = lun;
938 seq = isp->isp_osinfo.rollinfo++;
939 cmd = -RQSTYPE_MODIFY_LUN;
943 if (IS_FC(isp) && lun != 0) {
946 * For SCC firmware, we only deal with setting
947 * (enabling or modifying) lun 0.
951 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq)) {
952 xpt_print_path(ccb->ccb_h.path);
953 isp_prt(isp, ISP_LOGERR, "isp_lun_cmd failed");
956 if (isp_cv_wait_timed_rqe(isp, bus, 30 * hz)) {
957 xpt_print_path(ccb->ccb_h.path);
958 isp_prt(isp, ISP_LOGERR,
959 "wait for MODIFY LUN timed out");
962 rstat = isp->isp_osinfo.rstatus[bus];
963 if (rstat != LUN_OK) {
964 xpt_print_path(ccb->ccb_h.path);
965 isp_prt(isp, ISP_LOGERR,
966 "MODIFY LUN returned 0x%x", rstat);
969 if (IS_FC(isp) && lun) {
973 seq = isp->isp_osinfo.rollinfo++;
976 cmd = -RQSTYPE_ENABLE_LUN;
977 if (isp_lun_cmd(isp, cmd, bus, tgt, lun, 0, 0, seq)) {
978 xpt_print_path(ccb->ccb_h.path);
979 isp_prt(isp, ISP_LOGERR, "isp_lun_cmd failed");
982 if (isp_cv_wait_timed_rqe(isp, bus, 30 * hz)) {
983 xpt_print_path(ccb->ccb_h.path);
984 isp_prt(isp, ISP_LOGERR,
985 "wait for DISABLE LUN timed out");
988 rstat = isp->isp_osinfo.rstatus[bus];
989 if (rstat != LUN_OK) {
990 xpt_print_path(ccb->ccb_h.path);
991 isp_prt(isp, ISP_LOGWARN,
992 "DISABLE LUN returned 0x%x", rstat);
995 if (are_any_luns_enabled(isp, bus) == 0) {
996 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
998 isp_prt(isp, ISP_LOGWARN,
999 "disable target mode on channel %d failed",
1003 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
1004 xpt_print_path(ccb->ccb_h.path);
1005 isp_prt(isp, ISP_LOGINFO,
1006 "Target Mode disabled on channel %d", bus);
1011 isp_vsema_rqe(isp, bus);
1013 if (rstat != LUN_OK) {
1014 xpt_print_path(ccb->ccb_h.path);
1015 isp_prt(isp, ISP_LOGWARN,
1016 "lun %sable failed", (cel->enable) ? "en" : "dis");
1017 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1018 rls_lun_statep(isp, tptr);
1020 destroy_lun_state(isp, tptr);
1022 xpt_print_path(ccb->ccb_h.path);
1023 isp_prt(isp, ISP_LOGINFO, lfmt,
1024 (cel->enable) ? "en" : "dis", bus);
1025 rls_lun_statep(isp, tptr);
1026 if (cel->enable == 0) {
1027 destroy_lun_state(isp, tptr);
1029 ccb->ccb_h.status = CAM_REQ_CMP;
1034 isp_abort_tgt_ccb(struct ispsoftc *isp, union ccb *ccb)
1037 struct ccb_hdr_slist *lp;
1038 struct ccb_hdr *curelm;
1040 union ccb *accb = ccb->cab.abort_ccb;
1042 if (accb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
1043 if (IS_FC(isp) && (accb->ccb_h.target_id !=
1044 ((fcparam *) isp->isp_param)->isp_loopid)) {
1045 return (CAM_PATH_INVALID);
1046 } else if (IS_SCSI(isp) && (accb->ccb_h.target_id !=
1047 ((sdparam *) isp->isp_param)->isp_initiator_id)) {
1048 return (CAM_PATH_INVALID);
1051 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), accb->ccb_h.target_lun);
1053 return (CAM_PATH_INVALID);
1055 if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
1057 } else if (accb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
1060 rls_lun_statep(isp, tptr);
1061 return (CAM_UA_ABORT);
1063 curelm = SLIST_FIRST(lp);
1065 if (curelm == &accb->ccb_h) {
1067 SLIST_REMOVE_HEAD(lp, sim_links.sle);
1069 while(curelm != NULL) {
1070 struct ccb_hdr *nextelm;
1072 nextelm = SLIST_NEXT(curelm, sim_links.sle);
1073 if (nextelm == &accb->ccb_h) {
1075 SLIST_NEXT(curelm, sim_links.sle) =
1076 SLIST_NEXT(nextelm, sim_links.sle);
1082 rls_lun_statep(isp, tptr);
1084 accb->ccb_h.status = CAM_REQ_ABORTED;
1085 return (CAM_REQ_CMP);
1087 return(CAM_PATH_INVALID);
1091 isp_target_start_ctio(struct ispsoftc *isp, union ccb *ccb)
1094 struct ccb_scsiio *cso = &ccb->csio;
1095 u_int16_t *hp, save_handle;
1096 u_int16_t nxti, optr;
1097 u_int8_t local[QENTRY_LEN];
1100 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1101 xpt_print_path(ccb->ccb_h.path);
1102 kprintf("Request Queue Overflow in isp_target_start_ctio\n");
1103 return (CAM_RESRC_UNAVAIL);
1105 bzero(local, QENTRY_LEN);
1108 * We're either moving data or completing a command here.
1112 atio_private_data_t *atp;
1113 ct2_entry_t *cto = (ct2_entry_t *) local;
1115 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1116 cto->ct_header.rqs_entry_count = 1;
1117 cto->ct_iid = cso->init_id;
1118 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
1119 cto->ct_lun = ccb->ccb_h.target_lun;
1122 atp = isp_get_atpd(isp, cso->tag_id);
1124 isp_prt(isp, ISP_LOGERR,
1125 "cannot find private data adjunct for tag %x",
1130 cto->ct_rxid = cso->tag_id;
1131 if (cso->dxfer_len == 0) {
1132 cto->ct_flags |= CT2_FLAG_MODE1 | CT2_NO_DATA;
1133 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1134 cto->ct_flags |= CT2_SENDSTATUS;
1135 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1137 atp->orig_datalen - atp->bytes_xfered;
1138 if (cto->ct_resid < 0) {
1139 cto->rsp.m1.ct_scsi_status |=
1141 } else if (cto->ct_resid > 0) {
1142 cto->rsp.m1.ct_scsi_status |=
1146 if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) {
1147 int m = min(cso->sense_len, MAXRESPLEN);
1148 bcopy(&cso->sense_data, cto->rsp.m1.ct_resp, m);
1149 cto->rsp.m1.ct_senselen = m;
1150 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1153 cto->ct_flags |= CT2_FLAG_MODE0;
1154 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1155 cto->ct_flags |= CT2_DATA_IN;
1157 cto->ct_flags |= CT2_DATA_OUT;
1159 cto->ct_reloff = atp->bytes_xfered;
1160 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
1161 cto->ct_flags |= CT2_SENDSTATUS;
1162 cto->rsp.m0.ct_scsi_status = cso->scsi_status;
1165 (atp->bytes_xfered + cso->dxfer_len);
1166 if (cto->ct_resid < 0) {
1167 cto->rsp.m0.ct_scsi_status |=
1169 } else if (cto->ct_resid > 0) {
1170 cto->rsp.m0.ct_scsi_status |=
1174 atp->last_xframt = cso->dxfer_len;
1177 * If we're sending data and status back together,
1178 * we can't also send back sense data as well.
1180 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1183 if (cto->ct_flags & CT2_SENDSTATUS) {
1184 isp_prt(isp, ISP_LOGTDEBUG0,
1185 "CTIO2[%x] STATUS %x origd %u curd %u resid %u",
1186 cto->ct_rxid, cso->scsi_status, atp->orig_datalen,
1187 cso->dxfer_len, cto->ct_resid);
1188 cto->ct_flags |= CT2_CCINCR;
1189 atp->state = ATPD_STATE_LAST_CTIO;
1191 atp->state = ATPD_STATE_CTIO;
1192 cto->ct_timeout = 10;
1193 hp = &cto->ct_syshandle;
1195 ct_entry_t *cto = (ct_entry_t *) local;
1197 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
1198 cto->ct_header.rqs_entry_count = 1;
1199 cto->ct_iid = cso->init_id;
1200 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
1201 cto->ct_tgt = ccb->ccb_h.target_id;
1202 cto->ct_lun = ccb->ccb_h.target_lun;
1203 cto->ct_fwhandle = AT_GET_HANDLE(cso->tag_id);
1204 if (AT_HAS_TAG(cso->tag_id)) {
1205 cto->ct_tag_val = (u_int8_t) AT_GET_TAG(cso->tag_id);
1206 cto->ct_flags |= CT_TQAE;
1208 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
1209 cto->ct_flags |= CT_NODISC;
1211 if (cso->dxfer_len == 0) {
1212 cto->ct_flags |= CT_NO_DATA;
1213 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1214 cto->ct_flags |= CT_DATA_IN;
1216 cto->ct_flags |= CT_DATA_OUT;
1218 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1219 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
1220 cto->ct_scsi_status = cso->scsi_status;
1221 cto->ct_resid = cso->resid;
1222 isp_prt(isp, ISP_LOGTDEBUG0,
1223 "CTIO[%x] SCSI STATUS 0x%x resid %d tag_id %x",
1224 cto->ct_fwhandle, cso->scsi_status, cso->resid,
1227 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1228 cto->ct_timeout = 10;
1229 hp = &cto->ct_syshandle;
1232 if (isp_save_xs(isp, (XS_T *)ccb, hp)) {
1233 xpt_print_path(ccb->ccb_h.path);
1234 kprintf("No XFLIST pointers for isp_target_start_ctio\n");
1235 return (CAM_RESRC_UNAVAIL);
1240 * Call the dma setup routines for this entry (and any subsequent
1241 * CTIOs) if there's data to move, and then tell the f/w it's got
1242 * new things to play with. As with isp_start's usage of DMA setup,
1243 * any swizzling is done in the machine dependent layer. Because
1244 * of this, we put the request onto the queue area first in native
1250 switch (ISP_DMASETUP(isp, cso, (ispreq_t *) local, &nxti, optr)) {
1252 ISP_ADD_REQUEST(isp, nxti);
1253 return (CAM_REQ_INPROG);
1256 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1257 isp_destroy_handle(isp, save_handle);
1258 return (CAM_RESRC_UNAVAIL);
1261 isp_destroy_handle(isp, save_handle);
1262 return (XS_ERR(ccb));
1267 isp_refire_putback_atio(void *arg)
1270 isp_target_putback_atio(arg);
1275 isp_target_putback_atio(union ccb *ccb)
1277 struct ispsoftc *isp;
1278 struct ccb_scsiio *cso;
1279 u_int16_t nxti, optr;
1284 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1285 (void) timeout(isp_refire_putback_atio, ccb, 10);
1286 isp_prt(isp, ISP_LOGWARN,
1287 "isp_target_putback_atio: Request Queue Overflow");
1290 bzero(qe, QENTRY_LEN);
1293 at2_entry_t local, *at = &local;
1294 MEMZERO(at, sizeof (at2_entry_t));
1295 at->at_header.rqs_entry_type = RQSTYPE_ATIO2;
1296 at->at_header.rqs_entry_count = 1;
1297 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) != 0) {
1298 at->at_scclun = (uint16_t) ccb->ccb_h.target_lun;
1300 at->at_lun = (uint8_t) ccb->ccb_h.target_lun;
1302 at->at_status = CT_OK;
1303 at->at_rxid = cso->tag_id;
1304 at->at_iid = cso->ccb_h.target_id;
1305 isp_put_atio2(isp, at, qe);
1307 at_entry_t local, *at = &local;
1308 MEMZERO(at, sizeof (at_entry_t));
1309 at->at_header.rqs_entry_type = RQSTYPE_ATIO;
1310 at->at_header.rqs_entry_count = 1;
1311 at->at_iid = cso->init_id;
1312 at->at_iid |= XS_CHANNEL(ccb) << 7;
1313 at->at_tgt = cso->ccb_h.target_id;
1314 at->at_lun = cso->ccb_h.target_lun;
1315 at->at_status = CT_OK;
1316 at->at_tag_val = AT_GET_TAG(cso->tag_id);
1317 at->at_handle = AT_GET_HANDLE(cso->tag_id);
1318 isp_put_atio(isp, at, qe);
1320 ISP_TDQE(isp, "isp_target_putback_atio", (int) optr, qe);
1321 ISP_ADD_REQUEST(isp, nxti);
1322 isp_complete_ctio(ccb);
1326 isp_complete_ctio(union ccb *ccb)
1328 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1329 ccb->ccb_h.status |= CAM_REQ_CMP;
1331 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1336 * Handle ATIO stuff that the generic code can't.
1337 * This means handling CDBs.
1341 isp_handle_platform_atio(struct ispsoftc *isp, at_entry_t *aep)
1344 int status, bus, iswildcard;
1345 struct ccb_accept_tio *atiop;
1348 * The firmware status (except for the QLTM_SVALID bit)
1349 * indicates why this ATIO was sent to us.
1351 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1353 * If the DISCONNECTS DISABLED bit is set in the flags field,
1354 * we're still connected on the SCSI bus.
1356 status = aep->at_status;
1357 if ((status & ~QLTM_SVALID) == AT_PHASE_ERROR) {
1359 * Bus Phase Sequence error. We should have sense data
1360 * suggested by the f/w. I'm not sure quite yet what
1361 * to do about this for CAM.
1363 isp_prt(isp, ISP_LOGWARN, "PHASE ERROR");
1364 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1367 if ((status & ~QLTM_SVALID) != AT_CDB) {
1368 isp_prt(isp, ISP_LOGWARN, "bad atio (0x%x) leaked to platform",
1370 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1374 bus = GET_BUS_VAL(aep->at_iid);
1375 tptr = get_lun_statep(isp, bus, aep->at_lun);
1377 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
1385 * Because we can't autofeed sense data back with
1386 * a command for parallel SCSI, we can't give back
1387 * a CHECK CONDITION. We'll give back a BUSY status
1388 * instead. This works out okay because the only
1389 * time we should, in fact, get this, is in the
1390 * case that somebody configured us without the
1391 * blackhole driver, so they get what they deserve.
1393 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1397 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1398 if (atiop == NULL) {
1400 * Because we can't autofeed sense data back with
1401 * a command for parallel SCSI, we can't give back
1402 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1403 * instead. This works out okay because the only time we
1404 * should, in fact, get this, is in the case that we've
1407 xpt_print_path(tptr->owner);
1408 isp_prt(isp, ISP_LOGWARN,
1409 "no ATIOS for lun %d from initiator %d on channel %d",
1410 aep->at_lun, GET_IID_VAL(aep->at_iid), bus);
1411 if (aep->at_flags & AT_TQAE)
1412 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1414 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1415 rls_lun_statep(isp, tptr);
1418 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1420 atiop->ccb_h.target_id = aep->at_tgt;
1421 atiop->ccb_h.target_lun = aep->at_lun;
1423 if (aep->at_flags & AT_NODISC) {
1424 atiop->ccb_h.flags = CAM_DIS_DISCONNECT;
1426 atiop->ccb_h.flags = 0;
1429 if (status & QLTM_SVALID) {
1430 size_t amt = imin(QLTM_SENSELEN, sizeof (atiop->sense_data));
1431 atiop->sense_len = amt;
1432 MEMCPY(&atiop->sense_data, aep->at_sense, amt);
1434 atiop->sense_len = 0;
1437 atiop->init_id = GET_IID_VAL(aep->at_iid);
1438 atiop->cdb_len = aep->at_cdblen;
1439 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, aep->at_cdblen);
1440 atiop->ccb_h.status = CAM_CDB_RECVD;
1442 * Construct a tag 'id' based upon tag value (which may be 0..255)
1443 * and the handle (which we have to preserve).
1445 AT_MAKE_TAGID(atiop->tag_id, aep);
1446 if (aep->at_flags & AT_TQAE) {
1447 atiop->tag_action = aep->at_tag_type;
1448 atiop->ccb_h.status |= CAM_TAG_ACTION_VALID;
1450 xpt_done((union ccb*)atiop);
1451 isp_prt(isp, ISP_LOGTDEBUG0,
1452 "ATIO[%x] CDB=0x%x bus %d iid%d->lun%d tag 0x%x ttype 0x%x %s",
1453 aep->at_handle, aep->at_cdb[0] & 0xff, GET_BUS_VAL(aep->at_iid),
1454 GET_IID_VAL(aep->at_iid), aep->at_lun, aep->at_tag_val & 0xff,
1455 aep->at_tag_type, (aep->at_flags & AT_NODISC)?
1456 "nondisc" : "disconnecting");
1457 rls_lun_statep(isp, tptr);
1462 isp_handle_platform_atio2(struct ispsoftc *isp, at2_entry_t *aep)
1466 struct ccb_accept_tio *atiop;
1467 atio_private_data_t *atp;
1470 * The firmware status (except for the QLTM_SVALID bit)
1471 * indicates why this ATIO was sent to us.
1473 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1475 if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) {
1476 isp_prt(isp, ISP_LOGWARN,
1477 "bogus atio (0x%x) leaked to platform", aep->at_status);
1478 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1482 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) != 0) {
1483 lun = aep->at_scclun;
1487 tptr = get_lun_statep(isp, 0, lun);
1489 isp_prt(isp, ISP_LOGWARN, "no state pointer for lun %d", lun);
1490 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
1495 * What we'd like to know is whether or not we have a listener
1496 * upstream that really hasn't configured yet. If we do, then
1497 * we can give a more sensible reply here. If not, then we can
1498 * reject this out of hand.
1500 * Choices for what to send were
1502 * Not Ready, Unit Not Self-Configured Yet
1505 * for the former and
1507 * Illegal Request, Logical Unit Not Supported
1512 * We used to decide whether there was at least one listener
1513 * based upon whether the black hole driver was configured.
1514 * However, recent config(8) changes have made this hard to do
1518 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1522 atp = isp_get_atpd(isp, 0);
1523 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1524 if (atiop == NULL || atp == NULL) {
1526 * Because we can't autofeed sense data back with
1527 * a command for parallel SCSI, we can't give back
1528 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1529 * instead. This works out okay because the only time we
1530 * should, in fact, get this, is in the case that we've
1533 xpt_print_path(tptr->owner);
1534 isp_prt(isp, ISP_LOGWARN,
1535 "no %s for lun %d from initiator %d",
1536 (atp == NULL && atiop == NULL)? "ATIO2s *or* ATPS" :
1537 ((atp == NULL)? "ATPs" : "ATIO2s"), lun, aep->at_iid);
1538 rls_lun_statep(isp, tptr);
1539 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1542 atp->state = ATPD_STATE_ATIO;
1543 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1545 isp_prt(isp, ISP_LOGTDEBUG0, "Take FREE ATIO2 lun %d, count now %d",
1546 lun, tptr->atio_count);
1548 if (tptr == &isp->isp_osinfo.tsdflt[0]) {
1549 atiop->ccb_h.target_id =
1550 ((fcparam *)isp->isp_param)->isp_loopid;
1551 atiop->ccb_h.target_lun = lun;
1554 * We don't get 'suggested' sense data as we do with SCSI cards.
1556 atiop->sense_len = 0;
1558 atiop->init_id = aep->at_iid;
1559 atiop->cdb_len = ATIO2_CDBLEN;
1560 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
1561 atiop->ccb_h.status = CAM_CDB_RECVD;
1562 atiop->tag_id = aep->at_rxid;
1563 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
1564 case ATIO2_TC_ATTR_SIMPLEQ:
1565 atiop->tag_action = MSG_SIMPLE_Q_TAG;
1567 case ATIO2_TC_ATTR_HEADOFQ:
1568 atiop->tag_action = MSG_HEAD_OF_Q_TAG;
1570 case ATIO2_TC_ATTR_ORDERED:
1571 atiop->tag_action = MSG_ORDERED_Q_TAG;
1573 case ATIO2_TC_ATTR_ACAQ: /* ?? */
1574 case ATIO2_TC_ATTR_UNTAGGED:
1576 atiop->tag_action = 0;
1579 atiop->ccb_h.flags = CAM_TAG_ACTION_VALID;
1581 atp->tag = atiop->tag_id;
1583 atp->orig_datalen = aep->at_datalen;
1584 atp->last_xframt = 0;
1585 atp->bytes_xfered = 0;
1586 atp->state = ATPD_STATE_CAM;
1587 xpt_done((union ccb*)atiop);
1589 isp_prt(isp, ISP_LOGTDEBUG0,
1590 "ATIO2[%x] CDB=0x%x iid%d->lun%d tattr 0x%x datalen %u",
1591 aep->at_rxid, aep->at_cdb[0] & 0xff, aep->at_iid,
1592 lun, aep->at_taskflags, aep->at_datalen);
1593 rls_lun_statep(isp, tptr);
1598 isp_handle_platform_ctio(struct ispsoftc *isp, void *arg)
1601 int sentstatus, ok, notify_cam, resid = 0;
1605 * CTIO and CTIO2 are close enough....
1608 ccb = (union ccb *) isp_find_xs(isp, ((ct_entry_t *)arg)->ct_syshandle);
1609 KASSERT((ccb != NULL), ("null ccb in isp_handle_platform_ctio"));
1610 isp_destroy_handle(isp, ((ct_entry_t *)arg)->ct_syshandle);
1613 ct2_entry_t *ct = arg;
1614 atio_private_data_t *atp = isp_get_atpd(isp, ct->ct_rxid);
1616 isp_prt(isp, ISP_LOGERR,
1617 "cannot find adjunct for %x after I/O",
1621 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
1622 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1623 if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
1624 ccb->ccb_h.status |= CAM_SENT_SENSE;
1626 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1627 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1628 resid = ct->ct_resid;
1629 atp->bytes_xfered += (atp->last_xframt - resid);
1630 atp->last_xframt = 0;
1632 if (sentstatus || !ok) {
1635 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN,
1636 "CTIO2[%x] sts 0x%x flg 0x%x sns %d resid %d %s",
1637 ct->ct_rxid, ct->ct_status, ct->ct_flags,
1638 (ccb->ccb_h.status & CAM_SENT_SENSE) != 0,
1639 resid, sentstatus? "FIN" : "MID");
1642 /* XXX: should really come after isp_complete_ctio */
1643 atp->state = ATPD_STATE_PDON;
1645 ct_entry_t *ct = arg;
1646 sentstatus = ct->ct_flags & CT_SENDSTATUS;
1647 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1649 * We *ought* to be able to get back to the original ATIO
1650 * here, but for some reason this gets lost. It's just as
1651 * well because it's squirrelled away as part of periph
1654 * We can live without it as long as we continue to use
1655 * the auto-replenish feature for CTIOs.
1657 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1658 if (ct->ct_status & QLTM_SVALID) {
1659 char *sp = (char *)ct;
1660 sp += CTIO_SENSE_OFFSET;
1661 ccb->csio.sense_len =
1662 min(sizeof (ccb->csio.sense_data), QLTM_SENSELEN);
1663 MEMCPY(&ccb->csio.sense_data, sp, ccb->csio.sense_len);
1664 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
1666 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1667 resid = ct->ct_resid;
1669 isp_prt(isp, ISP_LOGTDEBUG0,
1670 "CTIO[%x] tag %x iid %d lun %d sts %x flg %x resid %d %s",
1671 ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_lun,
1672 ct->ct_status, ct->ct_flags, resid,
1673 sentstatus? "FIN" : "MID");
1674 tval = ct->ct_fwhandle;
1676 ccb->csio.resid += resid;
1679 * We're here either because intermediate data transfers are done
1680 * and/or the final status CTIO (which may have joined with a
1681 * Data Transfer) is done.
1683 * In any case, for this platform, the upper layers figure out
1684 * what to do next, so all we do here is collect status and
1685 * pass information along. Any DMA handles have already been
1688 if (notify_cam == 0) {
1689 isp_prt(isp, ISP_LOGTDEBUG0, " INTER CTIO[0x%x] done", tval);
1693 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done",
1694 (sentstatus)? " FINAL " : "MIDTERM ", tval);
1697 isp_target_putback_atio(ccb);
1699 isp_complete_ctio(ccb);
1706 isp_handle_platform_notify_scsi(struct ispsoftc *isp, in_entry_t *inp)
1708 return (0); /* XXXX */
1712 isp_handle_platform_notify_fc(struct ispsoftc *isp, in_fcentry_t *inp)
1715 switch (inp->in_status) {
1716 case IN_PORT_LOGOUT:
1717 isp_prt(isp, ISP_LOGWARN, "port logout of iid %d",
1720 case IN_PORT_CHANGED:
1721 isp_prt(isp, ISP_LOGWARN, "port changed for iid %d",
1724 case IN_GLOBAL_LOGO:
1725 isp_prt(isp, ISP_LOGINFO, "all ports logged out");
1729 atio_private_data_t *atp = isp_get_atpd(isp, inp->in_seqid);
1730 struct ccb_immed_notify *inot = NULL;
1733 tstate_t *tptr = get_lun_statep(isp, 0, atp->lun);
1735 inot = (struct ccb_immed_notify *)
1736 SLIST_FIRST(&tptr->inots);
1738 SLIST_REMOVE_HEAD(&tptr->inots,
1742 isp_prt(isp, ISP_LOGWARN,
1743 "abort task RX_ID %x IID %d state %d",
1744 inp->in_seqid, inp->in_iid, atp->state);
1746 isp_prt(isp, ISP_LOGWARN,
1747 "abort task RX_ID %x from iid %d, state unknown",
1748 inp->in_seqid, inp->in_iid);
1751 inot->initiator_id = inp->in_iid;
1752 inot->sense_len = 0;
1753 inot->message_args[0] = MSG_ABORT_TAG;
1754 inot->message_args[1] = inp->in_seqid & 0xff;
1755 inot->message_args[2] = (inp->in_seqid >> 8) & 0xff;
1756 inot->ccb_h.status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN;
1757 xpt_done((union ccb *)inot);
1769 isp_cam_async(void *cbarg, u_int32_t code, struct cam_path *path, void *arg)
1771 struct cam_sim *sim;
1772 struct ispsoftc *isp;
1774 sim = (struct cam_sim *)cbarg;
1775 isp = (struct ispsoftc *) cam_sim_softc(sim);
1777 case AC_LOST_DEVICE:
1779 u_int16_t oflags, nflags;
1780 sdparam *sdp = isp->isp_param;
1783 tgt = xpt_path_target_id(path);
1785 sdp += cam_sim_bus(sim);
1787 nflags = sdp->isp_devparam[tgt].nvrm_flags;
1788 #ifndef ISP_TARGET_MODE
1789 nflags &= DPARM_SAFE_DFLT;
1790 if (isp->isp_loaded_fw) {
1791 nflags |= DPARM_NARROW | DPARM_ASYNC;
1794 nflags = DPARM_DEFAULT;
1796 oflags = sdp->isp_devparam[tgt].goal_flags;
1797 sdp->isp_devparam[tgt].goal_flags = nflags;
1798 sdp->isp_devparam[tgt].dev_update = 1;
1799 isp->isp_update |= (1 << cam_sim_bus(sim));
1800 (void) isp_control(isp,
1801 ISPCTL_UPDATE_PARAMS, NULL);
1802 sdp->isp_devparam[tgt].goal_flags = oflags;
1808 isp_prt(isp, ISP_LOGWARN, "isp_cam_async: Code 0x%x", code);
1814 isp_poll(struct cam_sim *sim)
1816 struct ispsoftc *isp = cam_sim_softc(sim);
1817 u_int16_t isr, sema, mbox;
1820 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
1821 isp_intr(isp, isr, sema, mbox);
1828 isp_watchdog(void *arg)
1831 struct ispsoftc *isp = XS_ISP(xs);
1836 * We've decided this command is dead. Make sure we're not trying
1837 * to kill a command that's already dead by getting it's handle and
1838 * and seeing whether it's still alive.
1841 iok = isp->isp_osinfo.intsok;
1842 isp->isp_osinfo.intsok = 0;
1843 handle = isp_find_handle(isp, xs);
1845 u_int16_t isr, sema, mbox;
1847 if (XS_CMD_DONE_P(xs)) {
1848 isp_prt(isp, ISP_LOGDEBUG1,
1849 "watchdog found done cmd (handle 0x%x)", handle);
1854 if (XS_CMD_WDOG_P(xs)) {
1855 isp_prt(isp, ISP_LOGDEBUG2,
1856 "recursive watchdog (handle 0x%x)", handle);
1862 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
1863 isp_intr(isp, isr, sema, mbox);
1865 if (XS_CMD_DONE_P(xs)) {
1866 isp_prt(isp, ISP_LOGDEBUG2,
1867 "watchdog cleanup for handle 0x%x", handle);
1868 xpt_done((union ccb *) xs);
1869 } else if (XS_CMD_GRACE_P(xs)) {
1871 * Make sure the command is *really* dead before we
1872 * release the handle (and DMA resources) for reuse.
1874 (void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
1877 * After this point, the comamnd is really dead.
1879 if (XS_XFRLEN(xs)) {
1880 ISP_DMAFREE(isp, xs, handle);
1882 isp_destroy_handle(isp, handle);
1883 xpt_print_path(xs->ccb_h.path);
1884 isp_prt(isp, ISP_LOGWARN,
1885 "watchdog timeout for handle 0x%x", handle);
1886 XS_SETERR(xs, CAM_CMD_TIMEOUT);
1890 u_int16_t nxti, optr;
1891 ispreq_t local, *mp= &local, *qe;
1894 callout_reset(&xs->ccb_h.timeout_ch, hz,
1896 if (isp_getrqentry(isp, &nxti, &optr, (void **) &qe)) {
1901 MEMZERO((void *) mp, sizeof (*mp));
1902 mp->req_header.rqs_entry_count = 1;
1903 mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
1904 mp->req_modifier = SYNC_ALL;
1905 mp->req_target = XS_CHANNEL(xs) << 7;
1906 isp_put_request(isp, mp, qe);
1907 ISP_ADD_REQUEST(isp, nxti);
1910 isp_prt(isp, ISP_LOGDEBUG2, "watchdog with no command");
1912 isp->isp_osinfo.intsok = iok;
1917 isp_kthread(void *arg)
1919 struct ispsoftc *isp = arg;
1922 isp->isp_osinfo.intsok = 1;
1925 * The first loop is for our usage where we have yet to have
1926 * gotten good fibre channel state.
1931 isp_prt(isp, ISP_LOGDEBUG0, "kthread: checking FC state");
1932 while (isp_fc_runstate(isp, 2 * 1000000) != 0) {
1933 isp_prt(isp, ISP_LOGDEBUG0, "kthread: FC state ungood");
1934 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
1935 FCPARAM(isp)->isp_loopstate < LOOP_PDB_RCVD) {
1936 if (FCPARAM(isp)->loop_seen_once == 0 ||
1937 isp->isp_osinfo.ktmature == 0) {
1941 tsleep(isp_kthread, 0, "isp_fcthrd", hz);
1946 * Even if we didn't get good loop state we may be
1947 * unfreezing the SIMQ so that we can kill off
1948 * commands (if we've never seen loop before, for example).
1950 isp->isp_osinfo.ktmature = 1;
1951 wasfrozen = isp->isp_osinfo.simqfrozen & SIMQFRZ_LOOPDOWN;
1952 isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_LOOPDOWN;
1953 if (wasfrozen && isp->isp_osinfo.simqfrozen == 0) {
1954 isp_prt(isp, ISP_LOGDEBUG0, "kthread: releasing simq");
1955 ISPLOCK_2_CAMLOCK(isp);
1956 xpt_release_simq(isp->isp_sim, 1);
1957 CAMLOCK_2_ISPLOCK(isp);
1959 tsleep(&isp->isp_osinfo.kthread, 0, "isp_fc_worker", 0);
1960 isp_prt(isp, ISP_LOGDEBUG0, "kthread: waiting until called");
1965 isp_action(struct cam_sim *sim, union ccb *ccb)
1967 int bus, tgt, error;
1968 struct ispsoftc *isp;
1969 struct ccb_trans_settings *cts;
1971 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
1973 isp = (struct ispsoftc *)cam_sim_softc(sim);
1974 ccb->ccb_h.sim_priv.entries[0].field = 0;
1975 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
1976 if (isp->isp_state != ISP_RUNSTATE &&
1977 ccb->ccb_h.func_code == XPT_SCSI_IO) {
1978 CAMLOCK_2_ISPLOCK(isp);
1980 if (isp->isp_state != ISP_INITSTATE) {
1983 * Lie. Say it was a selection timeout.
1985 ccb->ccb_h.status = CAM_SEL_TIMEOUT | CAM_DEV_QFRZN;
1986 xpt_freeze_devq(ccb->ccb_h.path, 1);
1990 isp->isp_state = ISP_RUNSTATE;
1991 ISPLOCK_2_CAMLOCK(isp);
1993 isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
1996 switch (ccb->ccb_h.func_code) {
1997 case XPT_SCSI_IO: /* Execute the requested I/O operation */
1999 * Do a couple of preliminary checks...
2001 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
2002 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
2003 ccb->ccb_h.status = CAM_REQ_INVALID;
2009 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
2010 ccb->ccb_h.status = CAM_PATH_INVALID;
2011 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
2012 ccb->ccb_h.status = CAM_PATH_INVALID;
2014 if (ccb->ccb_h.status == CAM_PATH_INVALID) {
2015 isp_prt(isp, ISP_LOGERR,
2016 "invalid tgt/lun (%d.%d) in XPT_SCSI_IO",
2017 ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
2022 ((struct ccb_scsiio *) ccb)->scsi_status = SCSI_STATUS_OK;
2023 CAMLOCK_2_ISPLOCK(isp);
2024 error = isp_start((XS_T *) ccb);
2027 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2028 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
2029 u_int64_t ticks = (u_int64_t) hz;
2030 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT)
2031 ticks = 60 * 1000 * ticks;
2033 ticks = ccb->ccb_h.timeout * hz;
2034 ticks = ((ticks + 999) / 1000) + hz + hz;
2035 if (ticks >= 0x80000000) {
2036 isp_prt(isp, ISP_LOGERR,
2037 "timeout overflow");
2040 callout_reset(&ccb->ccb_h.timeout_ch, ticks,
2043 ISPLOCK_2_CAMLOCK(isp);
2047 * This can only happen for Fibre Channel
2049 KASSERT((IS_FC(isp)), ("CMD_RQLATER for FC only"));
2050 if (FCPARAM(isp)->loop_seen_once == 0 &&
2051 isp->isp_osinfo.ktmature) {
2052 ISPLOCK_2_CAMLOCK(isp);
2053 XS_SETERR(ccb, CAM_SEL_TIMEOUT);
2057 wakeup(&isp->isp_osinfo.kthread);
2058 isp_freeze_loopdown(isp, "isp_action(RQLATER)");
2059 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
2060 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2061 ISPLOCK_2_CAMLOCK(isp);
2065 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2066 ISPLOCK_2_CAMLOCK(isp);
2070 isp_done((struct ccb_scsiio *) ccb);
2071 ISPLOCK_2_CAMLOCK(isp);
2074 isp_prt(isp, ISP_LOGERR,
2075 "What's this? 0x%x at %d in file %s",
2076 error, __LINE__, __FILE__);
2077 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
2079 ISPLOCK_2_CAMLOCK(isp);
2083 #ifdef ISP_TARGET_MODE
2084 case XPT_EN_LUN: /* Enable LUN as a target */
2087 CAMLOCK_2_ISPLOCK(isp);
2088 iok = isp->isp_osinfo.intsok;
2089 isp->isp_osinfo.intsok = 0;
2090 isp_en_lun(isp, ccb);
2091 isp->isp_osinfo.intsok = iok;
2092 ISPLOCK_2_CAMLOCK(isp);
2096 case XPT_NOTIFY_ACK: /* recycle notify ack */
2097 case XPT_IMMED_NOTIFY: /* Add Immediate Notify Resource */
2098 case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
2101 get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun);
2103 ccb->ccb_h.status = CAM_LUN_INVALID;
2107 ccb->ccb_h.sim_priv.entries[0].field = 0;
2108 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
2109 ccb->ccb_h.flags = 0;
2111 CAMLOCK_2_ISPLOCK(isp);
2112 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
2114 * Note that the command itself may not be done-
2115 * it may not even have had the first CTIO sent.
2118 isp_prt(isp, ISP_LOGTDEBUG0,
2119 "Put FREE ATIO2, lun %d, count now %d",
2120 ccb->ccb_h.target_lun, tptr->atio_count);
2121 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h,
2123 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
2124 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h,
2129 rls_lun_statep(isp, tptr);
2130 ccb->ccb_h.status = CAM_REQ_INPROG;
2131 ISPLOCK_2_CAMLOCK(isp);
2134 case XPT_CONT_TARGET_IO:
2136 CAMLOCK_2_ISPLOCK(isp);
2137 ccb->ccb_h.status = isp_target_start_ctio(isp, ccb);
2138 if (ccb->ccb_h.status != CAM_REQ_INPROG) {
2139 isp_prt(isp, ISP_LOGWARN,
2140 "XPT_CONT_TARGET_IO: status 0x%x",
2142 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2143 ISPLOCK_2_CAMLOCK(isp);
2146 ISPLOCK_2_CAMLOCK(isp);
2147 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2152 case XPT_RESET_DEV: /* BDR the specified SCSI device */
2154 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
2155 tgt = ccb->ccb_h.target_id;
2158 CAMLOCK_2_ISPLOCK(isp);
2159 error = isp_control(isp, ISPCTL_RESET_DEV, &tgt);
2160 ISPLOCK_2_CAMLOCK(isp);
2162 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2164 ccb->ccb_h.status = CAM_REQ_CMP;
2168 case XPT_ABORT: /* Abort the specified CCB */
2170 union ccb *accb = ccb->cab.abort_ccb;
2171 CAMLOCK_2_ISPLOCK(isp);
2172 switch (accb->ccb_h.func_code) {
2173 #ifdef ISP_TARGET_MODE
2174 case XPT_ACCEPT_TARGET_IO:
2175 case XPT_IMMED_NOTIFY:
2176 ccb->ccb_h.status = isp_abort_tgt_ccb(isp, ccb);
2178 case XPT_CONT_TARGET_IO:
2179 isp_prt(isp, ISP_LOGERR, "cannot abort CTIOs yet");
2180 ccb->ccb_h.status = CAM_UA_ABORT;
2184 error = isp_control(isp, ISPCTL_ABORT_CMD, ccb);
2186 ccb->ccb_h.status = CAM_UA_ABORT;
2188 ccb->ccb_h.status = CAM_REQ_CMP;
2192 ccb->ccb_h.status = CAM_REQ_INVALID;
2195 ISPLOCK_2_CAMLOCK(isp);
2199 #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
2200 case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */
2202 if (!IS_CURRENT_SETTINGS(cts)) {
2203 ccb->ccb_h.status = CAM_REQ_INVALID;
2207 tgt = cts->ccb_h.target_id;
2208 CAMLOCK_2_ISPLOCK(isp);
2210 struct ccb_trans_settings_scsi *scsi =
2211 &cts->proto_specific.scsi;
2212 struct ccb_trans_settings_spi *spi =
2213 &cts->xport_specific.spi;
2214 sdparam *sdp = isp->isp_param;
2217 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2220 * We always update (internally) from dev_flags
2221 * so any request to change settings just gets
2222 * vectored to that location.
2224 dptr = &sdp->isp_devparam[tgt].goal_flags;
2226 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
2227 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
2228 *dptr |= DPARM_DISC;
2230 *dptr &= ~DPARM_DISC;
2233 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2234 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
2235 *dptr |= DPARM_TQING;
2237 *dptr &= ~DPARM_TQING;
2240 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
2241 if (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT)
2242 *dptr |= DPARM_WIDE;
2244 *dptr &= ~DPARM_WIDE;
2250 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) &&
2251 (spi->valid & CTS_SPI_VALID_SYNC_RATE)) {
2252 *dptr |= DPARM_SYNC;
2253 isp_prt(isp, ISP_LOGDEBUG0,
2254 "enabling synchronous mode, but ignoring "
2255 "setting to period 0x%x offset 0x%x",
2256 spi->sync_period, spi->sync_offset);
2257 } else if (spi->sync_period && spi->sync_offset) {
2258 *dptr |= DPARM_SYNC;
2259 isp_prt(isp, ISP_LOGDEBUG0,
2260 "enabling synchronous mode (1), but ignoring"
2261 " setting to period 0x%x offset 0x%x",
2262 spi->sync_period, spi->sync_offset);
2264 *dptr &= ~DPARM_SYNC;
2266 isp_prt(isp, ISP_LOGDEBUG0,
2267 "SET bus %d targ %d to flags %x off %x per %x",
2268 bus, tgt, sdp->isp_devparam[tgt].goal_flags,
2269 sdp->isp_devparam[tgt].goal_offset,
2270 sdp->isp_devparam[tgt].goal_period);
2271 sdp->isp_devparam[tgt].dev_update = 1;
2272 isp->isp_update |= (1 << bus);
2274 ISPLOCK_2_CAMLOCK(isp);
2275 ccb->ccb_h.status = CAM_REQ_CMP;
2278 case XPT_GET_TRAN_SETTINGS:
2280 tgt = cts->ccb_h.target_id;
2281 CAMLOCK_2_ISPLOCK(isp);
2283 fcparam *fcp = isp->isp_param;
2284 struct ccb_trans_settings_fc *fc =
2285 &cts->xport_specific.fc;
2287 cts->protocol = PROTO_SCSI;
2288 cts->protocol_version = SCSI_REV_2;
2289 cts->transport = XPORT_FC;
2290 cts->transport_version = 0;
2292 fc->valid = CTS_FC_VALID_SPEED;
2293 fc->bitrate = 100000;
2294 if (tgt > 0 && tgt < MAX_FC_TARG) {
2295 struct lportdb *lp = &fcp->portdb[tgt];
2296 fc->wwnn = lp->node_wwn;
2297 fc->wwpn = lp->port_wwn;
2298 fc->port = lp->portid;
2299 fc->valid |= CTS_FC_VALID_WWNN |
2300 CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT;
2303 struct ccb_trans_settings_scsi *scsi =
2304 &cts->proto_specific.scsi;
2305 struct ccb_trans_settings_spi *spi =
2306 &cts->xport_specific.spi;
2307 sdparam *sdp = isp->isp_param;
2308 int bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2309 u_int16_t dval, pval, oval;
2313 if (IS_CURRENT_SETTINGS(cts)) {
2314 sdp->isp_devparam[tgt].dev_refresh = 1;
2315 isp->isp_update |= (1 << bus);
2316 (void) isp_control(isp, ISPCTL_UPDATE_PARAMS,
2318 dval = sdp->isp_devparam[tgt].actv_flags;
2319 oval = sdp->isp_devparam[tgt].actv_offset;
2320 pval = sdp->isp_devparam[tgt].actv_period;
2322 dval = sdp->isp_devparam[tgt].nvrm_flags;
2323 oval = sdp->isp_devparam[tgt].nvrm_offset;
2324 pval = sdp->isp_devparam[tgt].nvrm_period;
2327 cts->protocol = PROTO_SCSI;
2328 cts->protocol_version = SCSI_REV_2;
2329 cts->transport = XPORT_SPI;
2330 cts->transport_version = 2;
2332 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2333 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2334 if (dval & DPARM_DISC) {
2335 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
2337 if (dval & DPARM_TQING) {
2338 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
2340 if ((dval & DPARM_SYNC) && oval != 0) {
2341 spi->sync_offset = oval;
2342 spi->sync_period = pval;
2343 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2344 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2346 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
2347 if (dval & DPARM_WIDE) {
2348 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2350 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2352 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
2353 scsi->valid = CTS_SCSI_VALID_TQ;
2354 spi->valid |= CTS_SPI_VALID_DISC;
2358 isp_prt(isp, ISP_LOGDEBUG0,
2359 "GET %s bus %d targ %d to flags %x off %x per %x",
2360 IS_CURRENT_SETTINGS(cts)? "ACTIVE" : "NVRAM",
2361 bus, tgt, dval, oval, pval);
2363 ISPLOCK_2_CAMLOCK(isp);
2364 ccb->ccb_h.status = CAM_REQ_CMP;
2368 case XPT_CALC_GEOMETRY:
2370 struct ccb_calc_geometry *ccg;
2371 u_int32_t secs_per_cylinder;
2375 if (ccg->block_size == 0) {
2376 isp_prt(isp, ISP_LOGERR,
2377 "%d.%d XPT_CALC_GEOMETRY block size 0?",
2378 ccg->ccb_h.target_id, ccg->ccb_h.target_lun);
2379 ccb->ccb_h.status = CAM_REQ_INVALID;
2383 size_mb = ccg->volume_size /((1024L * 1024L) / ccg->block_size);
2384 if (size_mb > 1024) {
2386 ccg->secs_per_track = 63;
2389 ccg->secs_per_track = 32;
2391 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
2392 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
2393 ccb->ccb_h.status = CAM_REQ_CMP;
2397 case XPT_RESET_BUS: /* Reset the specified bus */
2398 bus = cam_sim_bus(sim);
2399 CAMLOCK_2_ISPLOCK(isp);
2400 error = isp_control(isp, ISPCTL_RESET_BUS, &bus);
2401 ISPLOCK_2_CAMLOCK(isp);
2403 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2405 if (cam_sim_bus(sim) && isp->isp_path2 != NULL)
2406 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
2407 else if (isp->isp_path != NULL)
2408 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
2409 ccb->ccb_h.status = CAM_REQ_CMP;
2414 case XPT_TERM_IO: /* Terminate the I/O process */
2415 ccb->ccb_h.status = CAM_REQ_INVALID;
2419 case XPT_PATH_INQ: /* Path routing inquiry */
2421 struct ccb_pathinq *cpi = &ccb->cpi;
2423 cpi->version_num = 1;
2424 #ifdef ISP_TARGET_MODE
2425 cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
2427 cpi->target_sprt = 0;
2429 cpi->hba_eng_cnt = 0;
2430 cpi->max_target = ISP_MAX_TARGETS(isp) - 1;
2431 cpi->max_lun = ISP_MAX_LUNS(isp) - 1;
2432 cpi->bus_id = cam_sim_bus(sim);
2434 cpi->hba_misc = PIM_NOBUSRESET;
2436 * Because our loop ID can shift from time to time,
2437 * make our initiator ID out of range of our bus.
2439 cpi->initiator_id = cpi->max_target + 1;
2442 * Set base transfer capabilities for Fibre Channel.
2443 * Technically not correct because we don't know
2444 * what media we're running on top of- but we'll
2445 * look good if we always say 100MB/s.
2447 if (FCPARAM(isp)->isp_gbspeed == 2)
2448 cpi->base_transfer_speed = 200000;
2450 cpi->base_transfer_speed = 100000;
2451 cpi->hba_inquiry = PI_TAG_ABLE;
2452 cpi->transport = XPORT_FC;
2453 cpi->transport_version = 0; /* WHAT'S THIS FOR? */
2455 sdparam *sdp = isp->isp_param;
2456 sdp += cam_sim_bus(xpt_path_sim(cpi->ccb_h.path));
2457 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
2459 cpi->initiator_id = sdp->isp_initiator_id;
2460 cpi->base_transfer_speed = 3300;
2461 cpi->transport = XPORT_SPI;
2462 cpi->transport_version = 2; /* WHAT'S THIS FOR? */
2464 cpi->protocol = PROTO_SCSI;
2465 cpi->protocol_version = SCSI_REV_2;
2466 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
2467 strncpy(cpi->hba_vid, "Qlogic", HBA_IDLEN);
2468 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
2469 cpi->unit_number = cam_sim_unit(sim);
2470 cpi->ccb_h.status = CAM_REQ_CMP;
2475 ccb->ccb_h.status = CAM_REQ_INVALID;
2481 #define ISPDDB (CAM_DEBUG_INFO|CAM_DEBUG_TRACE|CAM_DEBUG_CDB)
2483 isp_done(struct ccb_scsiio *sccb)
2485 struct ispsoftc *isp = XS_ISP(sccb);
2488 XS_SETERR(sccb, CAM_REQ_CMP);
2490 if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
2491 (sccb->scsi_status != SCSI_STATUS_OK)) {
2492 sccb->ccb_h.status &= ~CAM_STATUS_MASK;
2493 if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) &&
2494 (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) {
2495 sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
2497 sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
2501 sccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2502 if ((sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2503 if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
2504 sccb->ccb_h.status |= CAM_DEV_QFRZN;
2505 xpt_freeze_devq(sccb->ccb_h.path, 1);
2506 isp_prt(isp, ISP_LOGDEBUG0,
2507 "freeze devq %d.%d cam sts %x scsi sts %x",
2508 sccb->ccb_h.target_id, sccb->ccb_h.target_lun,
2509 sccb->ccb_h.status, sccb->scsi_status);
2513 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) &&
2514 (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2515 xpt_print_path(sccb->ccb_h.path);
2516 isp_prt(isp, ISP_LOGINFO,
2517 "cam completion status 0x%x", sccb->ccb_h.status);
2520 XS_CMD_S_DONE(sccb);
2521 if (XS_CMD_WDOG_P(sccb) == 0) {
2522 callout_stop(&sccb->ccb_h.timeout_ch);
2523 if (XS_CMD_GRACE_P(sccb)) {
2524 isp_prt(isp, ISP_LOGDEBUG2,
2525 "finished command on borrowed time");
2527 XS_CMD_S_CLEAR(sccb);
2528 ISPLOCK_2_CAMLOCK(isp);
2529 xpt_done((union ccb *) sccb);
2530 CAMLOCK_2_ISPLOCK(isp);
2535 isp_async(struct ispsoftc *isp, ispasync_t cmd, void *arg)
2539 case ISPASYNC_NEW_TGT_PARAMS:
2541 struct ccb_trans_settings_scsi *scsi;
2542 struct ccb_trans_settings_spi *spi;
2544 sdparam *sdp = isp->isp_param;
2545 struct ccb_trans_settings cts;
2546 struct cam_path *tmppath;
2548 bzero(&cts, sizeof (struct ccb_trans_settings));
2550 tgt = *((int *)arg);
2551 bus = (tgt >> 16) & 0xffff;
2554 ISPLOCK_2_CAMLOCK(isp);
2555 if (xpt_create_path(&tmppath, NULL,
2556 cam_sim_path(bus? isp->isp_sim2 : isp->isp_sim),
2557 tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2558 CAMLOCK_2_ISPLOCK(isp);
2559 isp_prt(isp, ISP_LOGWARN,
2560 "isp_async cannot make temp path for %d.%d",
2565 CAMLOCK_2_ISPLOCK(isp);
2566 flags = sdp->isp_devparam[tgt].actv_flags;
2567 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2568 cts.protocol = PROTO_SCSI;
2569 cts.transport = XPORT_SPI;
2571 scsi = &cts.proto_specific.scsi;
2572 spi = &cts.xport_specific.spi;
2574 if (flags & DPARM_TQING) {
2575 scsi->valid |= CTS_SCSI_VALID_TQ;
2576 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
2579 if (flags & DPARM_DISC) {
2580 spi->valid |= CTS_SPI_VALID_DISC;
2581 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
2583 spi->flags |= CTS_SPI_VALID_BUS_WIDTH;
2584 if (flags & DPARM_WIDE) {
2585 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2587 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2589 if (flags & DPARM_SYNC) {
2590 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2591 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2592 spi->sync_period = sdp->isp_devparam[tgt].actv_period;
2593 spi->sync_offset = sdp->isp_devparam[tgt].actv_offset;
2595 isp_prt(isp, ISP_LOGDEBUG2,
2596 "NEW_TGT_PARAMS bus %d tgt %d period %x offset %x flags %x",
2597 bus, tgt, sdp->isp_devparam[tgt].actv_period,
2598 sdp->isp_devparam[tgt].actv_offset, flags);
2599 xpt_setup_ccb(&cts.ccb_h, tmppath, 1);
2600 ISPLOCK_2_CAMLOCK(isp);
2601 xpt_async(AC_TRANSFER_NEG, tmppath, &cts);
2602 xpt_free_path(tmppath);
2603 CAMLOCK_2_ISPLOCK(isp);
2606 case ISPASYNC_BUS_RESET:
2607 bus = *((int *)arg);
2608 isp_prt(isp, ISP_LOGINFO, "SCSI bus reset on bus %d detected",
2610 if (bus > 0 && isp->isp_path2) {
2611 ISPLOCK_2_CAMLOCK(isp);
2612 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
2613 CAMLOCK_2_ISPLOCK(isp);
2614 } else if (isp->isp_path) {
2615 ISPLOCK_2_CAMLOCK(isp);
2616 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
2617 CAMLOCK_2_ISPLOCK(isp);
2621 if (isp->isp_path) {
2622 isp_freeze_loopdown(isp, "ISPASYNC_LIP");
2624 isp_prt(isp, ISP_LOGINFO, "LIP Received");
2626 case ISPASYNC_LOOP_RESET:
2627 if (isp->isp_path) {
2628 isp_freeze_loopdown(isp, "ISPASYNC_LOOP_RESET");
2630 isp_prt(isp, ISP_LOGINFO, "Loop Reset Received");
2632 case ISPASYNC_LOOP_DOWN:
2633 if (isp->isp_path) {
2634 isp_freeze_loopdown(isp, "ISPASYNC_LOOP_DOWN");
2636 isp_prt(isp, ISP_LOGINFO, "Loop DOWN");
2638 case ISPASYNC_LOOP_UP:
2640 * Now we just note that Loop has come up. We don't
2641 * actually do anything because we're waiting for a
2642 * Change Notify before activating the FC cleanup
2643 * thread to look at the state of the loop again.
2645 isp_prt(isp, ISP_LOGINFO, "Loop UP");
2647 case ISPASYNC_PROMENADE:
2649 struct cam_path *tmppath;
2650 const char *fmt = "Target %d (Loop 0x%x) Port ID 0x%x "
2651 "(role %s) %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x";
2652 static const char *roles[4] = {
2653 "(none)", "Target", "Initiator", "Target/Initiator"
2655 fcparam *fcp = isp->isp_param;
2656 int tgt = *((int *) arg);
2657 struct lportdb *lp = &fcp->portdb[tgt];
2659 isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid,
2660 roles[lp->roles & 0x3],
2661 (lp->valid)? "Arrived" : "Departed",
2662 (u_int32_t) (lp->port_wwn >> 32),
2663 (u_int32_t) (lp->port_wwn & 0xffffffffLL),
2664 (u_int32_t) (lp->node_wwn >> 32),
2665 (u_int32_t) (lp->node_wwn & 0xffffffffLL));
2667 if (xpt_create_path(&tmppath, NULL, cam_sim_path(isp->isp_sim),
2668 (target_id_t)tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2671 if (lp->valid && (lp->roles &
2672 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT))) {
2673 ISPLOCK_2_CAMLOCK(isp);
2674 xpt_async(AC_FOUND_DEVICE, tmppath, NULL);
2676 ISPLOCK_2_CAMLOCK(isp);
2677 xpt_async(AC_LOST_DEVICE, tmppath, NULL);
2679 CAMLOCK_2_ISPLOCK(isp);
2680 xpt_free_path(tmppath);
2683 case ISPASYNC_CHANGE_NOTIFY:
2684 if (arg == ISPASYNC_CHANGE_PDB) {
2685 isp_prt(isp, ISP_LOGINFO,
2686 "Port Database Changed");
2687 } else if (arg == ISPASYNC_CHANGE_SNS) {
2688 isp_prt(isp, ISP_LOGINFO,
2689 "Name Server Database Changed");
2691 wakeup(&isp->isp_osinfo.kthread);
2693 case ISPASYNC_FABRIC_DEV:
2695 int target, base, lim;
2696 fcparam *fcp = isp->isp_param;
2697 struct lportdb *lp = NULL;
2698 struct lportdb *clp = (struct lportdb *) arg;
2701 switch (clp->port_type) {
2728 isp_prt(isp, ISP_LOGINFO,
2729 "%s Fabric Device @ PortID 0x%x", pt, clp->portid);
2732 * If we don't have an initiator role we bail.
2734 * We just use ISPASYNC_FABRIC_DEV for announcement purposes.
2737 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2742 * Is this entry for us? If so, we bail.
2745 if (fcp->isp_portid == clp->portid) {
2750 * Else, the default policy is to find room for it in
2751 * our local port database. Later, when we execute
2752 * the call to isp_pdb_sync either this newly arrived
2753 * or already logged in device will be (re)announced.
2756 if (fcp->isp_topo == TOPO_FL_PORT)
2761 if (fcp->isp_topo == TOPO_N_PORT)
2767 * Is it already in our list?
2769 for (target = base; target < lim; target++) {
2770 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2773 lp = &fcp->portdb[target];
2774 if (lp->port_wwn == clp->port_wwn &&
2775 lp->node_wwn == clp->node_wwn) {
2783 for (target = base; target < lim; target++) {
2784 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2787 lp = &fcp->portdb[target];
2788 if (lp->port_wwn == 0) {
2792 if (target == lim) {
2793 isp_prt(isp, ISP_LOGWARN,
2794 "out of space for fabric devices");
2797 lp->port_type = clp->port_type;
2798 lp->fc4_type = clp->fc4_type;
2799 lp->node_wwn = clp->node_wwn;
2800 lp->port_wwn = clp->port_wwn;
2801 lp->portid = clp->portid;
2805 #ifdef ISP_TARGET_MODE
2806 case ISPASYNC_TARGET_MESSAGE:
2808 tmd_msg_t *mp = arg;
2809 isp_prt(isp, ISP_LOGALL,
2810 "bus %d iid %d tgt %d lun %d ttype %x tval %x msg[0]=%x",
2811 mp->nt_bus, (int) mp->nt_iid, (int) mp->nt_tgt,
2812 (int) mp->nt_lun, mp->nt_tagtype, mp->nt_tagval,
2816 case ISPASYNC_TARGET_EVENT:
2818 tmd_event_t *ep = arg;
2819 isp_prt(isp, ISP_LOGALL,
2820 "bus %d event code 0x%x", ep->ev_bus, ep->ev_event);
2823 case ISPASYNC_TARGET_ACTION:
2824 switch (((isphdr_t *)arg)->rqs_entry_type) {
2826 isp_prt(isp, ISP_LOGWARN,
2827 "event 0x%x for unhandled target action",
2828 ((isphdr_t *)arg)->rqs_entry_type);
2830 case RQSTYPE_NOTIFY:
2832 rv = isp_handle_platform_notify_scsi(isp,
2833 (in_entry_t *) arg);
2835 rv = isp_handle_platform_notify_fc(isp,
2836 (in_fcentry_t *) arg);
2840 rv = isp_handle_platform_atio(isp, (at_entry_t *) arg);
2843 rv = isp_handle_platform_atio2(isp, (at2_entry_t *)arg);
2847 rv = isp_handle_platform_ctio(isp, arg);
2849 case RQSTYPE_ENABLE_LUN:
2850 case RQSTYPE_MODIFY_LUN:
2851 if (IS_DUALBUS(isp)) {
2853 GET_BUS_VAL(((lun_entry_t *)arg)->le_rsvd);
2857 isp_cv_signal_rqe(isp, bus,
2858 ((lun_entry_t *)arg)->le_status);
2863 case ISPASYNC_FW_CRASH:
2865 u_int16_t mbox1, mbox6;
2866 mbox1 = ISP_READ(isp, OUTMAILBOX1);
2867 if (IS_DUALBUS(isp)) {
2868 mbox6 = ISP_READ(isp, OUTMAILBOX6);
2872 isp_prt(isp, ISP_LOGERR,
2873 "Internal Firmware Error on bus %d @ RISC Address 0x%x",
2875 #ifdef ISP_FW_CRASH_DUMP
2877 * XXX: really need a thread to do this right.
2880 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
2881 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
2882 isp_freeze_loopdown(isp, "f/w crash");
2886 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
2890 case ISPASYNC_UNHANDLED_RESPONSE:
2893 isp_prt(isp, ISP_LOGERR, "unknown isp_async event %d", cmd);
2901 * Locks are held before coming here.
2904 isp_uninit(struct ispsoftc *isp)
2906 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
2911 isp_prt(struct ispsoftc *isp, int level, const char *fmt, ...)
2914 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
2917 kprintf("%s: ", device_get_nameunit(isp->isp_dev));
2918 __va_start(ap, fmt);