3 * Copyright (c) 1997-2006 by Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice immediately at the beginning of the file, without modification,
11 * this list of conditions, and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 #include <dev/isp/isp_freebsd.h>
34 #include <sys/unistd.h>
35 #include <sys/kthread.h>
36 #include <machine/stdarg.h> /* for use by isp_prt below */
38 #include <sys/module.h>
39 #include <sys/ioccom.h>
40 #include <dev/isp/isp_ioctl.h>
41 #if __FreeBSD_version >= 500000
42 #include <sys/sysctl.h>
44 #include <cam/cam_periph.h>
45 #include <cam/cam_xpt_periph.h>
47 #if !defined(CAM_NEW_TRAN_CODE) && __FreeBSD_version >= 700025
48 #define CAM_NEW_TRAN_CODE 1
52 MODULE_VERSION(isp, 1);
53 MODULE_DEPEND(isp, cam, 1, 1, 1);
54 int isp_announced = 0;
55 int isp_fabric_hysteresis = 5;
56 int isp_loop_down_limit = 300; /* default loop down limit */
57 int isp_change_is_bad = 0; /* "changed" devices are bad */
58 int isp_quickboot_time = 15; /* don't wait more than N secs for loop up */
59 int isp_gone_device_time = 30; /* grace time before reporting device lost */
60 static const char *roles[4] = {
61 "(none)", "Target", "Initiator", "Target/Initiator"
63 static const char prom3[] =
64 "PortID 0x%06x Departed from Target %u because of %s";
66 static void isp_freeze_loopdown(ispsoftc_t *, char *);
67 static d_ioctl_t ispioctl;
68 static void isp_intr_enable(void *);
69 static void isp_cam_async(void *, uint32_t, struct cam_path *, void *);
70 static void isp_poll(struct cam_sim *);
71 static timeout_t isp_watchdog;
72 static timeout_t isp_ldt;
73 static void isp_kthread(void *);
74 static void isp_action(struct cam_sim *, union ccb *);
76 #if __FreeBSD_version < 700000
77 ispfwfunc *isp_get_firmware_p = NULL;
80 #if __FreeBSD_version < 500000
81 #define ISP_CDEV_MAJOR 248
82 static struct cdevsw isp_cdevsw = {
84 /* close */ nullclose,
90 /* strategy */ nostrategy,
92 /* maj */ ISP_CDEV_MAJOR,
97 #define isp_sysctl_update(x) do { ; } while (0)
99 static struct cdevsw isp_cdevsw = {
100 .d_version = D_VERSION,
101 .d_flags = D_NEEDGIANT,
105 static void isp_sysctl_update(ispsoftc_t *);
108 static ispsoftc_t *isplist = NULL;
111 isp_attach(ispsoftc_t *isp)
113 int primary, secondary;
114 struct ccb_setasync csa;
115 struct cam_devq *devq;
117 struct cam_path *path;
120 * Establish (in case of 12X0) which bus is the primary.
127 * Create the device queue for our SIM(s).
129 devq = cam_simq_alloc(isp->isp_maxcmds);
135 * Construct our SIM entry.
137 ISPLOCK_2_CAMLOCK(isp);
138 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
139 device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq);
142 CAMLOCK_2_ISPLOCK(isp);
145 CAMLOCK_2_ISPLOCK(isp);
147 isp->isp_osinfo.ehook.ich_func = isp_intr_enable;
148 isp->isp_osinfo.ehook.ich_arg = isp;
149 ISPLOCK_2_CAMLOCK(isp);
150 if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) {
151 cam_sim_free(sim, TRUE);
152 CAMLOCK_2_ISPLOCK(isp);
153 isp_prt(isp, ISP_LOGERR,
154 "could not establish interrupt enable hook");
158 if (xpt_bus_register(sim, primary) != CAM_SUCCESS) {
159 cam_sim_free(sim, TRUE);
160 CAMLOCK_2_ISPLOCK(isp);
164 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
165 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
166 xpt_bus_deregister(cam_sim_path(sim));
167 cam_sim_free(sim, TRUE);
168 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
169 CAMLOCK_2_ISPLOCK(isp);
173 xpt_setup_ccb(&csa.ccb_h, path, 5);
174 csa.ccb_h.func_code = XPT_SASYNC_CB;
175 csa.event_enable = AC_LOST_DEVICE;
176 csa.callback = isp_cam_async;
177 csa.callback_arg = sim;
178 xpt_action((union ccb *)&csa);
179 CAMLOCK_2_ISPLOCK(isp);
181 isp->isp_path = path;
183 * Create a kernel thread for fibre channel instances. We
184 * don't have dual channel FC cards.
187 ISPLOCK_2_CAMLOCK(isp);
188 #if __FreeBSD_version >= 500000
189 cv_init(&isp->isp_osinfo.kthread_cv, "isp_kthread_cv");
190 if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kproc,
191 RFHIGHPID, 0, "%s: fc_thrd",
192 device_get_nameunit(isp->isp_dev)))
194 if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kproc,
195 "%s: fc_thrd", device_get_nameunit(isp->isp_dev)))
198 xpt_bus_deregister(cam_sim_path(sim));
199 cam_sim_free(sim, TRUE);
200 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
201 CAMLOCK_2_ISPLOCK(isp);
202 isp_prt(isp, ISP_LOGERR, "could not create kthread");
205 CAMLOCK_2_ISPLOCK(isp);
207 * We start by being "loop down" if we have an initiator role
209 if (isp->isp_role & ISP_ROLE_INITIATOR) {
210 isp_freeze_loopdown(isp, "isp_attach");
211 isp->isp_osinfo.ldt =
212 timeout(isp_ldt, isp, isp_quickboot_time * hz);
213 isp->isp_osinfo.ldt_running = 1;
214 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
215 "Starting Initial Loop Down Timer");
221 * If we have a second channel, construct SIM entry for that.
223 if (IS_DUALBUS(isp)) {
224 ISPLOCK_2_CAMLOCK(isp);
225 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
226 device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq);
228 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
229 xpt_free_path(isp->isp_path);
231 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
234 if (xpt_bus_register(sim, secondary) != CAM_SUCCESS) {
235 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
236 xpt_free_path(isp->isp_path);
237 cam_sim_free(sim, TRUE);
238 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
239 CAMLOCK_2_ISPLOCK(isp);
243 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
244 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
245 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
246 xpt_free_path(isp->isp_path);
247 xpt_bus_deregister(cam_sim_path(sim));
248 cam_sim_free(sim, TRUE);
249 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
250 CAMLOCK_2_ISPLOCK(isp);
254 xpt_setup_ccb(&csa.ccb_h, path, 5);
255 csa.ccb_h.func_code = XPT_SASYNC_CB;
256 csa.event_enable = AC_LOST_DEVICE;
257 csa.callback = isp_cam_async;
258 csa.callback_arg = sim;
259 xpt_action((union ccb *)&csa);
260 CAMLOCK_2_ISPLOCK(isp);
262 isp->isp_path2 = path;
266 * Create device nodes
268 (void) make_dev(&isp_cdevsw, device_get_unit(isp->isp_dev), UID_ROOT,
269 GID_OPERATOR, 0600, "%s", device_get_nameunit(isp->isp_dev));
271 if (isp->isp_role != ISP_ROLE_NONE) {
272 isp->isp_state = ISP_RUNSTATE;
273 ISP_ENABLE_INTS(isp);
275 if (isplist == NULL) {
278 ispsoftc_t *tmp = isplist;
279 while (tmp->isp_osinfo.next) {
280 tmp = tmp->isp_osinfo.next;
282 tmp->isp_osinfo.next = isp;
284 isp_sysctl_update(isp);
288 isp_freeze_loopdown(ispsoftc_t *isp, char *msg)
290 if (isp->isp_osinfo.simqfrozen == 0) {
291 isp_prt(isp, ISP_LOGDEBUG0, "%s: freeze simq (loopdown)", msg);
292 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
293 ISPLOCK_2_CAMLOCK(isp);
294 xpt_freeze_simq(isp->isp_sim, 1);
295 CAMLOCK_2_ISPLOCK(isp);
297 isp_prt(isp, ISP_LOGDEBUG0, "%s: mark frozen (loopdown)", msg);
298 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
303 #if __FreeBSD_version < 500000
305 #define _IOP struct proc
307 #define _IOP struct thread
308 #define _DEV struct cdev *
312 ispioctl(_DEV dev, u_long c, caddr_t addr, int flags, _IOP *td)
315 int nr, retval = ENOTTY;
319 if (minor(dev) == device_get_unit(isp->isp_dev)) {
322 isp = isp->isp_osinfo.next;
328 #ifdef ISP_FW_CRASH_DUMP
329 case ISP_GET_FW_CRASH_DUMP:
331 uint16_t *ptr = FCPARAM(isp)->isp_dump_data;
336 sz = QLA2200_RISC_IMAGE_DUMP_SIZE;
338 sz = QLA2300_RISC_IMAGE_DUMP_SIZE;
342 void *uaddr = *((void **) addr);
343 if (copyout(ptr, uaddr, sz)) {
354 case ISP_FORCE_CRASH_DUMP:
357 isp_freeze_loopdown(isp,
358 "ispioctl(ISP_FORCE_CRASH_DUMP)");
368 int olddblev = isp->isp_dblev;
369 isp->isp_dblev = *(int *)addr;
370 *(int *)addr = olddblev;
375 *(int *)addr = isp->isp_role;
380 if (nr & ~(ISP_ROLE_INITIATOR|ISP_ROLE_TARGET)) {
384 *(int *)addr = isp->isp_role;
396 if (isp_fc_runstate(isp, 5 * 1000000)) {
407 if (isp_control(isp, ISPCTL_SEND_LIP, 0)) {
415 case ISP_FC_GETDINFO:
417 struct isp_fc_device *ifc = (struct isp_fc_device *) addr;
423 if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) {
428 lp = &FCPARAM(isp)->portdb[ifc->loopid];
429 if (lp->state == FC_PORTDB_STATE_VALID) {
430 ifc->role = lp->roles;
431 ifc->loopid = lp->handle;
432 ifc->portid = lp->portid;
433 ifc->node_wwn = lp->node_wwn;
434 ifc->port_wwn = lp->port_wwn;
444 isp_stats_t *sp = (isp_stats_t *) addr;
446 MEMZERO(sp, sizeof (*sp));
447 sp->isp_stat_version = ISP_STATS_VERSION;
448 sp->isp_type = isp->isp_type;
449 sp->isp_revision = isp->isp_revision;
451 sp->isp_stats[ISP_INTCNT] = isp->isp_intcnt;
452 sp->isp_stats[ISP_INTBOGUS] = isp->isp_intbogus;
453 sp->isp_stats[ISP_INTMBOXC] = isp->isp_intmboxc;
454 sp->isp_stats[ISP_INGOASYNC] = isp->isp_intoasync;
455 sp->isp_stats[ISP_RSLTCCMPLT] = isp->isp_rsltccmplt;
456 sp->isp_stats[ISP_FPHCCMCPLT] = isp->isp_fphccmplt;
457 sp->isp_stats[ISP_RSCCHIWAT] = isp->isp_rscchiwater;
458 sp->isp_stats[ISP_FPCCHIWAT] = isp->isp_fpcchiwater;
466 isp->isp_intbogus = 0;
467 isp->isp_intmboxc = 0;
468 isp->isp_intoasync = 0;
469 isp->isp_rsltccmplt = 0;
470 isp->isp_fphccmplt = 0;
471 isp->isp_rscchiwater = 0;
472 isp->isp_fpcchiwater = 0;
476 case ISP_FC_GETHINFO:
478 struct isp_hba_device *hba = (struct isp_hba_device *) addr;
479 MEMZERO(hba, sizeof (*hba));
481 hba->fc_fw_major = ISP_FW_MAJORX(isp->isp_fwrev);
482 hba->fc_fw_minor = ISP_FW_MINORX(isp->isp_fwrev);
483 hba->fc_fw_micro = ISP_FW_MICROX(isp->isp_fwrev);
485 hba->fc_speed = FCPARAM(isp)->isp_gbspeed;
486 hba->fc_scsi_supported = 1;
487 hba->fc_topology = FCPARAM(isp)->isp_topo + 1;
488 hba->fc_loopid = FCPARAM(isp)->isp_loopid;
489 hba->nvram_node_wwn = FCPARAM(isp)->isp_wwnn_nvram;
490 hba->nvram_port_wwn = FCPARAM(isp)->isp_wwpn_nvram;
491 hba->active_node_wwn = ISP_NODEWWN(isp);
492 hba->active_port_wwn = ISP_PORTWWN(isp);
497 case ISP_GET_FC_PARAM:
499 struct isp_fc_param *f = (struct isp_fc_param *) addr;
505 if (strcmp(f->param_name, "framelength") == 0) {
506 f->parameter = FCPARAM(isp)->isp_maxfrmlen;
510 if (strcmp(f->param_name, "exec_throttle") == 0) {
511 f->parameter = FCPARAM(isp)->isp_execthrottle;
515 if (strcmp(f->param_name, "fullduplex") == 0) {
516 if (FCPARAM(isp)->isp_fwoptions & ICBOPT_FULL_DUPLEX)
521 if (strcmp(f->param_name, "loopid") == 0) {
522 f->parameter = FCPARAM(isp)->isp_loopid;
529 case ISP_SET_FC_PARAM:
531 struct isp_fc_param *f = (struct isp_fc_param *) addr;
532 uint32_t param = f->parameter;
538 if (strcmp(f->param_name, "framelength") == 0) {
539 if (param != 512 && param != 1024 && param != 1024) {
543 FCPARAM(isp)->isp_maxfrmlen = param;
547 if (strcmp(f->param_name, "exec_throttle") == 0) {
548 if (param < 16 || param > 255) {
552 FCPARAM(isp)->isp_execthrottle = param;
556 if (strcmp(f->param_name, "fullduplex") == 0) {
557 if (param != 0 && param != 1) {
562 FCPARAM(isp)->isp_fwoptions |=
565 FCPARAM(isp)->isp_fwoptions &=
571 if (strcmp(f->param_name, "loopid") == 0) {
572 if (param < 0 || param > 125) {
576 FCPARAM(isp)->isp_loopid = param;
586 struct isp_fc_tsk_mgmt *fct = (struct isp_fc_tsk_mgmt *) addr;
594 memset(&mbs, 0, sizeof (mbs));
595 needmarker = retval = 0;
596 loopid = fct->loopid;
597 if (FCPARAM(isp)->isp_2klogin == 0) {
600 switch (fct->action) {
602 mbs.param[0] = MBOX_CLEAR_ACA;
603 mbs.param[1] = loopid;
604 mbs.param[2] = fct->lun;
606 case IPT_TARGET_RESET:
607 mbs.param[0] = MBOX_TARGET_RESET;
608 mbs.param[1] = loopid;
612 mbs.param[0] = MBOX_LUN_RESET;
613 mbs.param[1] = loopid;
614 mbs.param[2] = fct->lun;
617 case IPT_CLEAR_TASK_SET:
618 mbs.param[0] = MBOX_CLEAR_TASK_SET;
619 mbs.param[1] = loopid;
620 mbs.param[2] = fct->lun;
623 case IPT_ABORT_TASK_SET:
624 mbs.param[0] = MBOX_ABORT_TASK_SET;
625 mbs.param[1] = loopid;
626 mbs.param[2] = fct->lun;
636 isp->isp_sendmarker |= 1;
638 retval = isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
651 #if __FreeBSD_version >= 500000
653 isp_sysctl_update(ispsoftc_t *isp)
655 struct sysctl_ctx_list *ctx =
656 device_get_sysctl_ctx(isp->isp_osinfo.dev);
657 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
663 snprintf(isp->isp_osinfo.sysctl_info.fc.wwnn,
664 sizeof (isp->isp_osinfo.sysctl_info.fc.wwnn), "0x%08x%08x",
665 (uint32_t) (ISP_NODEWWN(isp) >> 32), (uint32_t) ISP_NODEWWN(isp));
667 snprintf(isp->isp_osinfo.sysctl_info.fc.wwpn,
668 sizeof (isp->isp_osinfo.sysctl_info.fc.wwpn), "0x%08x%08x",
669 (uint32_t) (ISP_PORTWWN(isp) >> 32), (uint32_t) ISP_PORTWWN(isp));
671 SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
672 "wwnn", CTLFLAG_RD, isp->isp_osinfo.sysctl_info.fc.wwnn, 0,
673 "World Wide Node Name");
675 SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
676 "wwpn", CTLFLAG_RD, isp->isp_osinfo.sysctl_info.fc.wwpn, 0,
677 "World Wide Port Name");
679 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
681 CTLFLAG_RW, &isp->isp_osinfo.loop_down_limit, 0,
682 "How long to wait for loop to come back up");
684 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
686 CTLFLAG_RW, &isp->isp_osinfo.gone_device_time, 0,
687 "How long to wait for a device to reappear");
692 isp_intr_enable(void *arg)
694 ispsoftc_t *isp = arg;
695 if (isp->isp_role != ISP_ROLE_NONE) {
696 ISP_ENABLE_INTS(isp);
698 /* Release our hook so that the boot can continue. */
699 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
703 * Put the target mode functions here, because some are inlines
706 #ifdef ISP_TARGET_MODE
708 static __inline int is_lun_enabled(ispsoftc_t *, int, lun_id_t);
709 static __inline int are_any_luns_enabled(ispsoftc_t *, int);
710 static __inline tstate_t *get_lun_statep(ispsoftc_t *, int, lun_id_t);
711 static __inline void rls_lun_statep(ispsoftc_t *, tstate_t *);
712 static __inline atio_private_data_t *isp_get_atpd(ispsoftc_t *, int);
714 create_lun_state(ispsoftc_t *, int, struct cam_path *, tstate_t **);
715 static void destroy_lun_state(ispsoftc_t *, tstate_t *);
716 static int isp_en_lun(ispsoftc_t *, union ccb *);
717 static void isp_ledone(ispsoftc_t *, lun_entry_t *);
718 static cam_status isp_abort_tgt_ccb(ispsoftc_t *, union ccb *);
719 static timeout_t isp_refire_putback_atio;
720 static void isp_complete_ctio(union ccb *);
721 static void isp_target_putback_atio(union ccb *);
722 static void isp_target_start_ctio(ispsoftc_t *, union ccb *);
723 static int isp_handle_platform_atio(ispsoftc_t *, at_entry_t *);
724 static int isp_handle_platform_atio2(ispsoftc_t *, at2_entry_t *);
725 static int isp_handle_platform_ctio(ispsoftc_t *, void *);
726 static int isp_handle_platform_notify_scsi(ispsoftc_t *, in_entry_t *);
727 static int isp_handle_platform_notify_fc(ispsoftc_t *, in_fcentry_t *);
730 is_lun_enabled(ispsoftc_t *isp, int bus, lun_id_t lun)
733 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
738 if (tptr->lun == (lun_id_t) lun && tptr->bus == bus) {
741 } while ((tptr = tptr->next) != NULL);
746 are_any_luns_enabled(ispsoftc_t *isp, int port)
749 if (IS_DUALBUS(isp)) {
750 lo = (port * (LUN_HASH_SIZE >> 1));
751 hi = lo + (LUN_HASH_SIZE >> 1);
756 for (lo = 0; lo < hi; lo++) {
757 if (isp->isp_osinfo.lun_hash[lo]) {
764 static __inline tstate_t *
765 get_lun_statep(ispsoftc_t *isp, int bus, lun_id_t lun)
767 tstate_t *tptr = NULL;
769 if (lun == CAM_LUN_WILDCARD) {
770 if (isp->isp_osinfo.tmflags[bus] & TM_WILDCARD_ENABLED) {
771 tptr = &isp->isp_osinfo.tsdflt[bus];
777 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
784 if (tptr->lun == lun && tptr->bus == bus) {
788 } while ((tptr = tptr->next) != NULL);
793 rls_lun_statep(ispsoftc_t *isp, tstate_t *tptr)
799 static __inline atio_private_data_t *
800 isp_get_atpd(ispsoftc_t *isp, int tag)
802 atio_private_data_t *atp;
803 for (atp = isp->isp_osinfo.atpdp;
804 atp < &isp->isp_osinfo.atpdp[ATPDPSIZE]; atp++) {
812 create_lun_state(ispsoftc_t *isp, int bus,
813 struct cam_path *path, tstate_t **rslt)
818 tstate_t *tptr, *new;
820 lun = xpt_path_lun_id(path);
822 return (CAM_LUN_INVALID);
824 if (is_lun_enabled(isp, bus, lun)) {
825 return (CAM_LUN_ALRDY_ENA);
827 new = (tstate_t *) malloc(sizeof (tstate_t), M_DEVBUF, M_NOWAIT|M_ZERO);
829 return (CAM_RESRC_UNAVAIL);
832 status = xpt_create_path(&new->owner, NULL, xpt_path_path_id(path),
833 xpt_path_target_id(path), xpt_path_lun_id(path));
834 if (status != CAM_REQ_CMP) {
840 SLIST_INIT(&new->atios);
841 SLIST_INIT(&new->inots);
844 hfx = LUN_HASH_FUNC(isp, new->bus, new->lun);
845 tptr = isp->isp_osinfo.lun_hash[hfx];
847 isp->isp_osinfo.lun_hash[hfx] = new;
854 return (CAM_REQ_CMP);
858 destroy_lun_state(ispsoftc_t *isp, tstate_t *tptr)
866 hfx = LUN_HASH_FUNC(isp, tptr->bus, tptr->lun);
867 pw = isp->isp_osinfo.lun_hash[hfx];
870 } else if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
871 isp->isp_osinfo.lun_hash[hfx] = pw->next;
876 if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
887 free(tptr, M_DEVBUF);
894 isp_en_lun(ispsoftc_t *isp, union ccb *ccb)
896 struct ccb_en_lun *cel = &ccb->cel;
899 int bus, cmd, av, wildcard, tm_on;
903 bus = XS_CHANNEL(ccb);
905 xpt_print(ccb->ccb_h.path, "illegal bus %d\n", bus);
906 ccb->ccb_h.status = CAM_PATH_INVALID;
909 tgt = ccb->ccb_h.target_id;
910 lun = ccb->ccb_h.target_lun;
912 if (isp->isp_dblev & ISP_LOGTDEBUG0) {
913 xpt_print(ccb->ccb_h.path, "%sabling lun 0x%x on channel %d\n",
914 cel->enable? "en" : "dis", lun, bus);
917 if ((lun != CAM_LUN_WILDCARD) &&
918 (lun < 0 || lun >= (lun_id_t) isp->isp_maxluns)) {
919 ccb->ccb_h.status = CAM_LUN_INVALID;
924 sdparam *sdp = isp->isp_param;
926 if (tgt != CAM_TARGET_WILDCARD &&
927 tgt != sdp->isp_initiator_id) {
928 ccb->ccb_h.status = CAM_TID_INVALID;
933 * There's really no point in doing this yet w/o multi-tid
934 * capability. Even then, it's problematic.
937 if (tgt != CAM_TARGET_WILDCARD &&
938 tgt != FCPARAM(isp)->isp_iid) {
939 ccb->ccb_h.status = CAM_TID_INVALID;
944 * This is as a good a place as any to check f/w capabilities.
946 if (FCPARAM(isp)->isp_tmode == 0) {
947 xpt_print(ccb->ccb_h.path,
948 "firmware does not support target mode\n");
949 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
953 * XXX: We *could* handle non-SCCLUN f/w, but we'd have to
954 * XXX: dork with our already fragile enable/disable code.
956 if (FCPARAM(isp)->isp_sccfw == 0) {
957 xpt_print(ccb->ccb_h.path,
958 "firmware not SCCLUN capable\n");
959 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
964 if (tgt == CAM_TARGET_WILDCARD) {
965 if (lun == CAM_LUN_WILDCARD) {
968 ccb->ccb_h.status = CAM_LUN_INVALID;
975 tm_on = (isp->isp_osinfo.tmflags[bus] & TM_TMODE_ENABLED) != 0;
978 * Next check to see whether this is a target/lun wildcard action.
980 * If so, we know that we can accept commands for luns that haven't
981 * been enabled yet and send them upstream. Otherwise, we have to
982 * handle them locally (if we see them at all).
986 tptr = &isp->isp_osinfo.tsdflt[bus];
989 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
993 xpt_create_path(&tptr->owner, NULL,
994 xpt_path_path_id(ccb->ccb_h.path),
995 xpt_path_target_id(ccb->ccb_h.path),
996 xpt_path_lun_id(ccb->ccb_h.path));
997 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1000 SLIST_INIT(&tptr->atios);
1001 SLIST_INIT(&tptr->inots);
1002 isp->isp_osinfo.tmflags[bus] |= TM_WILDCARD_ENABLED;
1005 ccb->ccb_h.status = CAM_REQ_CMP;
1009 ccb->ccb_h.status = CAM_SCSI_BUSY;
1012 xpt_free_path(tptr->owner);
1013 isp->isp_osinfo.tmflags[bus] &= ~TM_WILDCARD_ENABLED;
1018 * Now check to see whether this bus needs to be
1019 * enabled/disabled with respect to target mode.
1022 if (cel->enable && tm_on == 0) {
1023 av |= ENABLE_TARGET_FLAG;
1024 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
1026 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1028 isp->isp_osinfo.tmflags[bus] &=
1029 ~TM_WILDCARD_ENABLED;
1030 xpt_free_path(tptr->owner);
1034 isp->isp_osinfo.tmflags[bus] |= TM_TMODE_ENABLED;
1035 xpt_print(ccb->ccb_h.path, "Target Mode Enabled\n");
1036 } else if (cel->enable == 0 && tm_on && wildcard) {
1037 if (are_any_luns_enabled(isp, bus)) {
1038 ccb->ccb_h.status = CAM_SCSI_BUSY;
1041 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
1043 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1046 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
1047 xpt_print(ccb->ccb_h.path, "Target Mode Disabled\n");
1051 ccb->ccb_h.status = CAM_REQ_CMP;
1056 * Find an empty slot
1058 for (seq = 0; seq < NLEACT; seq++) {
1059 if (isp->isp_osinfo.leact[seq] == 0) {
1063 if (seq >= NLEACT) {
1064 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1068 isp->isp_osinfo.leact[seq] = ccb;
1072 create_lun_state(isp, bus, ccb->ccb_h.path, &tptr);
1073 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1074 isp->isp_osinfo.leact[seq] = 0;
1078 tptr = get_lun_statep(isp, bus, lun);
1080 ccb->ccb_h.status = CAM_LUN_INVALID;
1086 int c, n, ulun = lun;
1088 cmd = RQSTYPE_ENABLE_LUN;
1091 if (IS_FC(isp) && lun != 0) {
1092 cmd = RQSTYPE_MODIFY_LUN;
1095 * For SCC firmware, we only deal with setting
1096 * (enabling or modifying) lun 0.
1100 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq+1) == 0) {
1101 rls_lun_statep(isp, tptr);
1102 ccb->ccb_h.status = CAM_REQ_INPROG;
1106 int c, n, ulun = lun;
1108 cmd = -RQSTYPE_MODIFY_LUN;
1111 if (IS_FC(isp) && lun != 0) {
1114 * For SCC firmware, we only deal with setting
1115 * (enabling or modifying) lun 0.
1119 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq+1) == 0) {
1120 rls_lun_statep(isp, tptr);
1121 ccb->ccb_h.status = CAM_REQ_INPROG;
1125 rls_lun_statep(isp, tptr);
1126 xpt_print(ccb->ccb_h.path, "isp_lun_cmd failed\n");
1127 isp->isp_osinfo.leact[seq] = 0;
1128 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1133 isp_ledone(ispsoftc_t *isp, lun_entry_t *lep)
1135 const char lfmt[] = "now %sabled for target mode";
1140 struct ccb_en_lun *cel;
1142 seq = lep->le_reserved - 1;
1143 if (seq >= NLEACT) {
1144 isp_prt(isp, ISP_LOGERR,
1145 "seq out of range (%u) in isp_ledone", seq);
1148 ccb = isp->isp_osinfo.leact[seq];
1150 isp_prt(isp, ISP_LOGERR,
1151 "no ccb for seq %u in isp_ledone", seq);
1155 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), XS_LUN(ccb));
1157 xpt_print(ccb->ccb_h.path, "null tptr in isp_ledone\n");
1158 isp->isp_osinfo.leact[seq] = 0;
1162 if (lep->le_status != LUN_OK) {
1163 xpt_print(ccb->ccb_h.path,
1164 "ENABLE/MODIFY LUN returned 0x%x\n", lep->le_status);
1166 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1167 rls_lun_statep(isp, tptr);
1168 isp->isp_osinfo.leact[seq] = 0;
1169 ISPLOCK_2_CAMLOCK(isp);
1171 CAMLOCK_2_ISPLOCK(isp);
1174 isp_prt(isp, ISP_LOGTDEBUG0,
1175 "isp_ledone: ENABLE/MODIFY done okay");
1180 ccb->ccb_h.status = CAM_REQ_CMP;
1181 xpt_print(ccb->ccb_h.path, lfmt, "en");
1182 rls_lun_statep(isp, tptr);
1183 isp->isp_osinfo.leact[seq] = 0;
1184 ISPLOCK_2_CAMLOCK(isp);
1186 CAMLOCK_2_ISPLOCK(isp);
1190 if (lep->le_header.rqs_entry_type == RQSTYPE_MODIFY_LUN) {
1191 if (isp_lun_cmd(isp, -RQSTYPE_ENABLE_LUN, XS_CHANNEL(ccb),
1192 XS_TGT(ccb), XS_LUN(ccb), 0, 0, seq+1)) {
1193 xpt_print(ccb->ccb_h.path,
1194 "isp_ledone: isp_lun_cmd failed\n");
1197 rls_lun_statep(isp, tptr);
1201 xpt_print(ccb->ccb_h.path, lfmt, "dis");
1202 rls_lun_statep(isp, tptr);
1203 destroy_lun_state(isp, tptr);
1204 ccb->ccb_h.status = CAM_REQ_CMP;
1205 isp->isp_osinfo.leact[seq] = 0;
1206 ISPLOCK_2_CAMLOCK(isp);
1208 CAMLOCK_2_ISPLOCK(isp);
1209 if (are_any_luns_enabled(isp, XS_CHANNEL(ccb)) == 0) {
1210 int bus = XS_CHANNEL(ccb);
1212 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
1214 isp_prt(isp, ISP_LOGWARN,
1215 "disable target mode on channel %d failed", bus);
1217 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
1223 isp_abort_tgt_ccb(ispsoftc_t *isp, union ccb *ccb)
1226 struct ccb_hdr_slist *lp;
1227 struct ccb_hdr *curelm;
1229 union ccb *accb = ccb->cab.abort_ccb;
1231 xpt_print(ccb->ccb_h.path, "aborting ccb %p\n", accb);
1232 if (accb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
1234 if (IS_FC(isp) && (accb->ccb_h.target_id !=
1235 ((fcparam *) isp->isp_param)->isp_loopid)) {
1237 } else if (IS_SCSI(isp) && (accb->ccb_h.target_id !=
1238 ((sdparam *) isp->isp_param)->isp_initiator_id)) {
1243 * Being restrictive about target ids is really about
1244 * making sure we're aborting for the right multi-tid
1245 * path. This doesn't really make much sense at present.
1248 return (CAM_PATH_INVALID);
1252 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), accb->ccb_h.target_lun);
1254 xpt_print(ccb->ccb_h.path, "can't get statep\n");
1255 return (CAM_PATH_INVALID);
1257 if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
1259 ctr = &tptr->atio_count;
1260 } else if (accb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
1262 ctr = &tptr->inot_count;
1264 rls_lun_statep(isp, tptr);
1265 xpt_print(ccb->ccb_h.path, "bad function code %d\n",
1266 accb->ccb_h.func_code);
1267 return (CAM_UA_ABORT);
1269 curelm = SLIST_FIRST(lp);
1271 if (curelm == &accb->ccb_h) {
1273 SLIST_REMOVE_HEAD(lp, sim_links.sle);
1275 while(curelm != NULL) {
1276 struct ccb_hdr *nextelm;
1278 nextelm = SLIST_NEXT(curelm, sim_links.sle);
1279 if (nextelm == &accb->ccb_h) {
1281 SLIST_NEXT(curelm, sim_links.sle) =
1282 SLIST_NEXT(nextelm, sim_links.sle);
1288 rls_lun_statep(isp, tptr);
1291 accb->ccb_h.status = CAM_REQ_ABORTED;
1293 return (CAM_REQ_CMP);
1295 xpt_print(ccb->ccb_h.path, "ccb %p not found\n", accb);
1296 return (CAM_PATH_INVALID);
1300 isp_target_start_ctio(ispsoftc_t *isp, union ccb *ccb)
1303 struct ccb_scsiio *cso = &ccb->csio;
1304 uint32_t nxti, optr, handle;
1305 uint8_t local[QENTRY_LEN];
1308 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1309 xpt_print(ccb->ccb_h.path,
1310 "Request Queue Overflow in isp_target_start_ctio\n");
1311 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1314 memset(local, 0, QENTRY_LEN);
1317 * We're either moving data or completing a command here.
1321 atio_private_data_t *atp;
1322 ct2_entry_t *cto = (ct2_entry_t *) local;
1324 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1325 cto->ct_header.rqs_entry_count = 1;
1326 if (FCPARAM(isp)->isp_2klogin) {
1327 ((ct2e_entry_t *)cto)->ct_iid = cso->init_id;
1329 cto->ct_iid = cso->init_id;
1330 if (FCPARAM(isp)->isp_sccfw == 0) {
1331 cto->ct_lun = ccb->ccb_h.target_lun;
1335 atp = isp_get_atpd(isp, cso->tag_id);
1337 xpt_print(ccb->ccb_h.path,
1338 "cannot find private data adjunct for tag %x\n",
1340 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
1344 cto->ct_rxid = cso->tag_id;
1345 if (cso->dxfer_len == 0) {
1346 cto->ct_flags |= CT2_FLAG_MODE1 | CT2_NO_DATA;
1347 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1348 cto->ct_flags |= CT2_SENDSTATUS;
1349 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1351 atp->orig_datalen - atp->bytes_xfered;
1352 if (cto->ct_resid < 0) {
1353 cto->rsp.m1.ct_scsi_status |=
1355 } else if (cto->ct_resid > 0) {
1356 cto->rsp.m1.ct_scsi_status |=
1360 if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) {
1361 int m = min(cso->sense_len, MAXRESPLEN);
1362 memcpy(cto->rsp.m1.ct_resp,
1363 &cso->sense_data, m);
1364 cto->rsp.m1.ct_senselen = m;
1365 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1368 cto->ct_flags |= CT2_FLAG_MODE0;
1369 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1370 cto->ct_flags |= CT2_DATA_IN;
1372 cto->ct_flags |= CT2_DATA_OUT;
1374 cto->ct_reloff = atp->bytes_xfered;
1375 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
1376 cto->ct_flags |= CT2_SENDSTATUS;
1377 cto->rsp.m0.ct_scsi_status = cso->scsi_status;
1380 (atp->bytes_xfered + cso->dxfer_len);
1381 if (cto->ct_resid < 0) {
1382 cto->rsp.m0.ct_scsi_status |=
1384 } else if (cto->ct_resid > 0) {
1385 cto->rsp.m0.ct_scsi_status |=
1389 atp->last_xframt = cso->dxfer_len;
1392 * If we're sending data and status back together,
1393 * we can't also send back sense data as well.
1395 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1398 if (cto->ct_flags & CT2_SENDSTATUS) {
1399 isp_prt(isp, ISP_LOGTDEBUG0,
1400 "CTIO2[%x] STATUS %x origd %u curd %u resid %u",
1401 cto->ct_rxid, cso->scsi_status, atp->orig_datalen,
1402 cso->dxfer_len, cto->ct_resid);
1403 cto->ct_flags |= CT2_CCINCR;
1404 atp->state = ATPD_STATE_LAST_CTIO;
1406 atp->state = ATPD_STATE_CTIO;
1408 cto->ct_timeout = 10;
1410 ct_entry_t *cto = (ct_entry_t *) local;
1412 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
1413 cto->ct_header.rqs_entry_count = 1;
1414 cto->ct_iid = cso->init_id;
1415 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
1416 cto->ct_tgt = ccb->ccb_h.target_id;
1417 cto->ct_lun = ccb->ccb_h.target_lun;
1418 cto->ct_fwhandle = AT_GET_HANDLE(cso->tag_id);
1419 if (AT_HAS_TAG(cso->tag_id)) {
1420 cto->ct_tag_val = (uint8_t) AT_GET_TAG(cso->tag_id);
1421 cto->ct_flags |= CT_TQAE;
1423 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
1424 cto->ct_flags |= CT_NODISC;
1426 if (cso->dxfer_len == 0) {
1427 cto->ct_flags |= CT_NO_DATA;
1428 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1429 cto->ct_flags |= CT_DATA_IN;
1431 cto->ct_flags |= CT_DATA_OUT;
1433 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1434 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
1435 cto->ct_scsi_status = cso->scsi_status;
1436 cto->ct_resid = cso->resid;
1437 isp_prt(isp, ISP_LOGTDEBUG0,
1438 "CTIO[%x] SCSI STATUS 0x%x resid %d tag_id %x",
1439 cto->ct_fwhandle, cso->scsi_status, cso->resid,
1442 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1443 cto->ct_timeout = 10;
1446 if (isp_save_xs_tgt(isp, ccb, &handle)) {
1447 xpt_print(ccb->ccb_h.path,
1448 "No XFLIST pointers for isp_target_start_ctio\n");
1449 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1455 * Call the dma setup routines for this entry (and any subsequent
1456 * CTIOs) if there's data to move, and then tell the f/w it's got
1457 * new things to play with. As with isp_start's usage of DMA setup,
1458 * any swizzling is done in the machine dependent layer. Because
1459 * of this, we put the request onto the queue area first in native
1464 ct2_entry_t *cto = (ct2_entry_t *) local;
1465 cto->ct_syshandle = handle;
1467 ct_entry_t *cto = (ct_entry_t *) local;
1468 cto->ct_syshandle = handle;
1471 switch (ISP_DMASETUP(isp, cso, (ispreq_t *) local, &nxti, optr)) {
1473 ISP_ADD_REQUEST(isp, nxti);
1474 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1478 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1484 isp_destroy_tgt_handle(isp, handle);
1487 ISPLOCK_2_CAMLOCK(isp);
1489 CAMLOCK_2_ISPLOCK(isp);
1493 isp_refire_putback_atio(void *arg)
1496 isp_target_putback_atio(arg);
1501 isp_target_putback_atio(union ccb *ccb)
1504 struct ccb_scsiio *cso;
1505 uint32_t nxti, optr;
1510 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1511 xpt_print(ccb->ccb_h.path,
1512 "isp_target_putback_atio: Request Queue Overflow\n");
1513 (void) timeout(isp_refire_putback_atio, ccb, 10);
1516 memset(qe, 0, QENTRY_LEN);
1519 at2_entry_t local, *at = &local;
1520 MEMZERO(at, sizeof (at2_entry_t));
1521 at->at_header.rqs_entry_type = RQSTYPE_ATIO2;
1522 at->at_header.rqs_entry_count = 1;
1523 if (FCPARAM(isp)->isp_sccfw) {
1524 at->at_scclun = (uint16_t) ccb->ccb_h.target_lun;
1526 at->at_lun = (uint8_t) ccb->ccb_h.target_lun;
1528 at->at_status = CT_OK;
1529 at->at_rxid = cso->tag_id;
1530 at->at_iid = cso->ccb_h.target_id;
1531 isp_put_atio2(isp, at, qe);
1533 at_entry_t local, *at = &local;
1534 MEMZERO(at, sizeof (at_entry_t));
1535 at->at_header.rqs_entry_type = RQSTYPE_ATIO;
1536 at->at_header.rqs_entry_count = 1;
1537 at->at_iid = cso->init_id;
1538 at->at_iid |= XS_CHANNEL(ccb) << 7;
1539 at->at_tgt = cso->ccb_h.target_id;
1540 at->at_lun = cso->ccb_h.target_lun;
1541 at->at_status = CT_OK;
1542 at->at_tag_val = AT_GET_TAG(cso->tag_id);
1543 at->at_handle = AT_GET_HANDLE(cso->tag_id);
1544 isp_put_atio(isp, at, qe);
1546 ISP_TDQE(isp, "isp_target_putback_atio", (int) optr, qe);
1547 ISP_ADD_REQUEST(isp, nxti);
1548 isp_complete_ctio(ccb);
1552 isp_complete_ctio(union ccb *ccb)
1554 ISPLOCK_2_CAMLOCK(isp);
1555 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1556 ccb->ccb_h.status |= CAM_REQ_CMP;
1558 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1560 CAMLOCK_2_ISPLOCK(isp);
1564 * Handle ATIO stuff that the generic code can't.
1565 * This means handling CDBs.
1569 isp_handle_platform_atio(ispsoftc_t *isp, at_entry_t *aep)
1572 int status, bus, iswildcard;
1573 struct ccb_accept_tio *atiop;
1576 * The firmware status (except for the QLTM_SVALID bit)
1577 * indicates why this ATIO was sent to us.
1579 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1581 * If the DISCONNECTS DISABLED bit is set in the flags field,
1582 * we're still connected on the SCSI bus.
1584 status = aep->at_status;
1585 if ((status & ~QLTM_SVALID) == AT_PHASE_ERROR) {
1587 * Bus Phase Sequence error. We should have sense data
1588 * suggested by the f/w. I'm not sure quite yet what
1589 * to do about this for CAM.
1591 isp_prt(isp, ISP_LOGWARN, "PHASE ERROR");
1592 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1595 if ((status & ~QLTM_SVALID) != AT_CDB) {
1596 isp_prt(isp, ISP_LOGWARN, "bad atio (0x%x) leaked to platform",
1598 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1602 bus = GET_BUS_VAL(aep->at_iid);
1603 tptr = get_lun_statep(isp, bus, aep->at_lun);
1605 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
1608 * Because we can't autofeed sense data back with
1609 * a command for parallel SCSI, we can't give back
1610 * a CHECK CONDITION. We'll give back a BUSY status
1611 * instead. This works out okay because the only
1612 * time we should, in fact, get this, is in the
1613 * case that somebody configured us without the
1614 * blackhole driver, so they get what they deserve.
1616 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1624 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1625 if (atiop == NULL) {
1627 * Because we can't autofeed sense data back with
1628 * a command for parallel SCSI, we can't give back
1629 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1630 * instead. This works out okay because the only time we
1631 * should, in fact, get this, is in the case that we've
1634 xpt_print(tptr->owner,
1635 "no ATIOS for lun %d from initiator %d on channel %d\n",
1636 aep->at_lun, GET_IID_VAL(aep->at_iid), bus);
1637 if (aep->at_flags & AT_TQAE)
1638 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1640 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1641 rls_lun_statep(isp, tptr);
1644 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1646 isp_prt(isp, ISP_LOGTDEBUG0, "Take FREE ATIO lun %d, count now %d",
1647 aep->at_lun, tptr->atio_count);
1649 atiop->ccb_h.target_id = aep->at_tgt;
1650 atiop->ccb_h.target_lun = aep->at_lun;
1652 if (aep->at_flags & AT_NODISC) {
1653 atiop->ccb_h.flags = CAM_DIS_DISCONNECT;
1655 atiop->ccb_h.flags = 0;
1658 if (status & QLTM_SVALID) {
1659 size_t amt = imin(QLTM_SENSELEN, sizeof (atiop->sense_data));
1660 atiop->sense_len = amt;
1661 MEMCPY(&atiop->sense_data, aep->at_sense, amt);
1663 atiop->sense_len = 0;
1666 atiop->init_id = GET_IID_VAL(aep->at_iid);
1667 atiop->cdb_len = aep->at_cdblen;
1668 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, aep->at_cdblen);
1669 atiop->ccb_h.status = CAM_CDB_RECVD;
1671 * Construct a tag 'id' based upon tag value (which may be 0..255)
1672 * and the handle (which we have to preserve).
1674 AT_MAKE_TAGID(atiop->tag_id, bus, device_get_unit(isp->isp_dev), aep);
1675 if (aep->at_flags & AT_TQAE) {
1676 atiop->tag_action = aep->at_tag_type;
1677 atiop->ccb_h.status |= CAM_TAG_ACTION_VALID;
1679 xpt_done((union ccb*)atiop);
1680 isp_prt(isp, ISP_LOGTDEBUG0,
1681 "ATIO[%x] CDB=0x%x bus %d iid%d->lun%d tag 0x%x ttype 0x%x %s",
1682 aep->at_handle, aep->at_cdb[0] & 0xff, GET_BUS_VAL(aep->at_iid),
1683 GET_IID_VAL(aep->at_iid), aep->at_lun, aep->at_tag_val & 0xff,
1684 aep->at_tag_type, (aep->at_flags & AT_NODISC)?
1685 "nondisc" : "disconnecting");
1686 rls_lun_statep(isp, tptr);
1691 isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1695 struct ccb_accept_tio *atiop;
1696 atio_private_data_t *atp;
1699 * The firmware status (except for the QLTM_SVALID bit)
1700 * indicates why this ATIO was sent to us.
1702 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1704 if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) {
1705 isp_prt(isp, ISP_LOGWARN,
1706 "bogus atio (0x%x) leaked to platform", aep->at_status);
1707 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1711 if (FCPARAM(isp)->isp_sccfw) {
1712 lun = aep->at_scclun;
1716 tptr = get_lun_statep(isp, 0, lun);
1718 isp_prt(isp, ISP_LOGTDEBUG0,
1719 "[0x%x] no state pointer for lun %d", aep->at_rxid, lun);
1720 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
1722 isp_endcmd(isp, aep,
1723 SCSI_STATUS_CHECK_COND | ECMD_SVALID |
1724 (0x5 << 12) | (0x25 << 16), 0);
1729 atp = isp_get_atpd(isp, 0);
1730 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1731 if (atiop == NULL || atp == NULL) {
1734 * Because we can't autofeed sense data back with
1735 * a command for parallel SCSI, we can't give back
1736 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1737 * instead. This works out okay because the only time we
1738 * should, in fact, get this, is in the case that we've
1741 xpt_print(tptr->owner,
1742 "no %s for lun %d from initiator %d\n",
1743 (atp == NULL && atiop == NULL)? "ATIO2s *or* ATPS" :
1744 ((atp == NULL)? "ATPs" : "ATIO2s"), lun, aep->at_iid);
1745 rls_lun_statep(isp, tptr);
1746 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1749 atp->state = ATPD_STATE_ATIO;
1750 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1752 isp_prt(isp, ISP_LOGTDEBUG0, "Take FREE ATIO lun %d, count now %d",
1753 lun, tptr->atio_count);
1755 if (tptr == &isp->isp_osinfo.tsdflt[0]) {
1756 atiop->ccb_h.target_id = FCPARAM(isp)->isp_loopid;
1757 atiop->ccb_h.target_lun = lun;
1760 * We don't get 'suggested' sense data as we do with SCSI cards.
1762 atiop->sense_len = 0;
1764 atiop->init_id = aep->at_iid;
1765 atiop->cdb_len = ATIO2_CDBLEN;
1766 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
1767 atiop->ccb_h.status = CAM_CDB_RECVD;
1768 atiop->tag_id = aep->at_rxid;
1769 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
1770 case ATIO2_TC_ATTR_SIMPLEQ:
1771 atiop->tag_action = MSG_SIMPLE_Q_TAG;
1773 case ATIO2_TC_ATTR_HEADOFQ:
1774 atiop->tag_action = MSG_HEAD_OF_Q_TAG;
1776 case ATIO2_TC_ATTR_ORDERED:
1777 atiop->tag_action = MSG_ORDERED_Q_TAG;
1779 case ATIO2_TC_ATTR_ACAQ: /* ?? */
1780 case ATIO2_TC_ATTR_UNTAGGED:
1782 atiop->tag_action = 0;
1785 atiop->ccb_h.flags = CAM_TAG_ACTION_VALID;
1787 atp->tag = atiop->tag_id;
1789 atp->orig_datalen = aep->at_datalen;
1790 atp->last_xframt = 0;
1791 atp->bytes_xfered = 0;
1792 atp->state = ATPD_STATE_CAM;
1793 ISPLOCK_2_CAMLOCK(siP);
1794 xpt_done((union ccb*)atiop);
1796 isp_prt(isp, ISP_LOGTDEBUG0,
1797 "ATIO2[%x] CDB=0x%x iid%d->lun%d tattr 0x%x datalen %u",
1798 aep->at_rxid, aep->at_cdb[0] & 0xff, aep->at_iid,
1799 lun, aep->at_taskflags, aep->at_datalen);
1800 rls_lun_statep(isp, tptr);
1805 isp_handle_platform_ctio(ispsoftc_t *isp, void *arg)
1808 int sentstatus, ok, notify_cam, resid = 0;
1812 * CTIO and CTIO2 are close enough....
1815 ccb = isp_find_xs_tgt(isp, ((ct_entry_t *)arg)->ct_syshandle);
1816 KASSERT((ccb != NULL), ("null ccb in isp_handle_platform_ctio"));
1817 isp_destroy_tgt_handle(isp, ((ct_entry_t *)arg)->ct_syshandle);
1820 ct2_entry_t *ct = arg;
1821 atio_private_data_t *atp = isp_get_atpd(isp, ct->ct_rxid);
1823 isp_prt(isp, ISP_LOGERR,
1824 "cannot find adjunct for %x after I/O",
1828 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
1829 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1830 if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
1831 ccb->ccb_h.status |= CAM_SENT_SENSE;
1833 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1834 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1835 resid = ct->ct_resid;
1836 atp->bytes_xfered += (atp->last_xframt - resid);
1837 atp->last_xframt = 0;
1839 if (sentstatus || !ok) {
1842 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN,
1843 "CTIO2[%x] sts 0x%x flg 0x%x sns %d resid %d %s",
1844 ct->ct_rxid, ct->ct_status, ct->ct_flags,
1845 (ccb->ccb_h.status & CAM_SENT_SENSE) != 0,
1846 resid, sentstatus? "FIN" : "MID");
1849 /* XXX: should really come after isp_complete_ctio */
1850 atp->state = ATPD_STATE_PDON;
1852 ct_entry_t *ct = arg;
1853 sentstatus = ct->ct_flags & CT_SENDSTATUS;
1854 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1856 * We *ought* to be able to get back to the original ATIO
1857 * here, but for some reason this gets lost. It's just as
1858 * well because it's squirrelled away as part of periph
1861 * We can live without it as long as we continue to use
1862 * the auto-replenish feature for CTIOs.
1864 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1865 if (ct->ct_status & QLTM_SVALID) {
1866 char *sp = (char *)ct;
1867 sp += CTIO_SENSE_OFFSET;
1868 ccb->csio.sense_len =
1869 min(sizeof (ccb->csio.sense_data), QLTM_SENSELEN);
1870 MEMCPY(&ccb->csio.sense_data, sp, ccb->csio.sense_len);
1871 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
1873 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1874 resid = ct->ct_resid;
1876 isp_prt(isp, ISP_LOGTDEBUG0,
1877 "CTIO[%x] tag %x iid %d lun %d sts %x flg %x resid %d %s",
1878 ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_lun,
1879 ct->ct_status, ct->ct_flags, resid,
1880 sentstatus? "FIN" : "MID");
1881 tval = ct->ct_fwhandle;
1883 ccb->csio.resid += resid;
1886 * We're here either because intermediate data transfers are done
1887 * and/or the final status CTIO (which may have joined with a
1888 * Data Transfer) is done.
1890 * In any case, for this platform, the upper layers figure out
1891 * what to do next, so all we do here is collect status and
1892 * pass information along. Any DMA handles have already been
1895 if (notify_cam == 0) {
1896 isp_prt(isp, ISP_LOGTDEBUG0, " INTER CTIO[0x%x] done", tval);
1900 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done",
1901 (sentstatus)? " FINAL " : "MIDTERM ", tval);
1904 isp_target_putback_atio(ccb);
1906 isp_complete_ctio(ccb);
1913 isp_handle_platform_notify_scsi(ispsoftc_t *isp, in_entry_t *inp)
1915 return (0); /* XXXX */
1919 isp_handle_platform_notify_fc(ispsoftc_t *isp, in_fcentry_t *inp)
1922 switch (inp->in_status) {
1923 case IN_PORT_LOGOUT:
1924 isp_prt(isp, ISP_LOGWARN, "port logout of iid %d",
1927 case IN_PORT_CHANGED:
1928 isp_prt(isp, ISP_LOGWARN, "port changed for iid %d",
1931 case IN_GLOBAL_LOGO:
1932 isp_prt(isp, ISP_LOGINFO, "all ports logged out");
1936 atio_private_data_t *atp = isp_get_atpd(isp, inp->in_seqid);
1937 struct ccb_immed_notify *inot = NULL;
1940 tstate_t *tptr = get_lun_statep(isp, 0, atp->lun);
1942 inot = (struct ccb_immed_notify *)
1943 SLIST_FIRST(&tptr->inots);
1946 SLIST_REMOVE_HEAD(&tptr->inots,
1948 isp_prt(isp, ISP_LOGTDEBUG0,
1949 "Take FREE INOT count now %d",
1953 isp_prt(isp, ISP_LOGWARN,
1954 "abort task RX_ID %x IID %d state %d",
1955 inp->in_seqid, inp->in_iid, atp->state);
1957 isp_prt(isp, ISP_LOGWARN,
1958 "abort task RX_ID %x from iid %d, state unknown",
1959 inp->in_seqid, inp->in_iid);
1962 inot->initiator_id = inp->in_iid;
1963 inot->sense_len = 0;
1964 inot->message_args[0] = MSG_ABORT_TAG;
1965 inot->message_args[1] = inp->in_seqid & 0xff;
1966 inot->message_args[2] = (inp->in_seqid >> 8) & 0xff;
1967 inot->ccb_h.status = CAM_MESSAGE_RECV;
1968 xpt_done((union ccb *)inot);
1980 isp_cam_async(void *cbarg, uint32_t code, struct cam_path *path, void *arg)
1982 struct cam_sim *sim;
1985 sim = (struct cam_sim *)cbarg;
1986 isp = (ispsoftc_t *) cam_sim_softc(sim);
1988 case AC_LOST_DEVICE:
1990 uint16_t oflags, nflags;
1991 sdparam *sdp = isp->isp_param;
1994 tgt = xpt_path_target_id(path);
1996 sdp += cam_sim_bus(sim);
1998 nflags = sdp->isp_devparam[tgt].nvrm_flags;
1999 #ifndef ISP_TARGET_MODE
2000 nflags &= DPARM_SAFE_DFLT;
2001 if (isp->isp_loaded_fw) {
2002 nflags |= DPARM_NARROW | DPARM_ASYNC;
2005 nflags = DPARM_DEFAULT;
2007 oflags = sdp->isp_devparam[tgt].goal_flags;
2008 sdp->isp_devparam[tgt].goal_flags = nflags;
2009 sdp->isp_devparam[tgt].dev_update = 1;
2010 isp->isp_update |= (1 << cam_sim_bus(sim));
2011 (void) isp_control(isp,
2012 ISPCTL_UPDATE_PARAMS, NULL);
2013 sdp->isp_devparam[tgt].goal_flags = oflags;
2019 isp_prt(isp, ISP_LOGWARN, "isp_cam_async: Code 0x%x", code);
2025 isp_poll(struct cam_sim *sim)
2027 ispsoftc_t *isp = cam_sim_softc(sim);
2029 uint16_t sema, mbox;
2032 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2033 isp_intr(isp, isr, sema, mbox);
2039 static int isp_watchdog_work(ispsoftc_t *, XS_T *);
2042 isp_watchdog_work(ispsoftc_t *isp, XS_T *xs)
2047 * We've decided this command is dead. Make sure we're not trying
2048 * to kill a command that's already dead by getting it's handle and
2049 * and seeing whether it's still alive.
2052 handle = isp_find_handle(isp, xs);
2055 uint16_t sema, mbox;
2057 if (XS_CMD_DONE_P(xs)) {
2058 isp_prt(isp, ISP_LOGDEBUG1,
2059 "watchdog found done cmd (handle 0x%x)", handle);
2064 if (XS_CMD_WDOG_P(xs)) {
2065 isp_prt(isp, ISP_LOGDEBUG2,
2066 "recursive watchdog (handle 0x%x)", handle);
2072 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2073 isp_intr(isp, isr, sema, mbox);
2075 if (XS_CMD_DONE_P(xs)) {
2076 isp_prt(isp, ISP_LOGDEBUG2,
2077 "watchdog cleanup for handle 0x%x", handle);
2078 ISPLOCK_2_CAMLOCK(isp);
2079 xpt_done((union ccb *) xs);
2080 CAMLOCK_2_ISPLOCK(isp);
2081 } else if (XS_CMD_GRACE_P(xs)) {
2083 * Make sure the command is *really* dead before we
2084 * release the handle (and DMA resources) for reuse.
2086 (void) isp_control(isp, ISPCTL_ABORT_CMD, xs);
2089 * After this point, the comamnd is really dead.
2091 if (XS_XFRLEN(xs)) {
2092 ISP_DMAFREE(isp, xs, handle);
2094 isp_destroy_handle(isp, handle);
2095 xpt_print(xs->ccb_h.path,
2096 "watchdog timeout for handle 0x%x\n", handle);
2097 XS_SETERR(xs, CAM_CMD_TIMEOUT);
2099 ISPLOCK_2_CAMLOCK(isp);
2101 CAMLOCK_2_ISPLOCK(isp);
2104 xs->ccb_h.timeout_ch = timeout(isp_watchdog, xs, hz);
2106 isp->isp_sendmarker |= 1 << XS_CHANNEL(xs);
2116 isp_watchdog(void *arg)
2120 for (isp = isplist; isp != NULL; isp = isp->isp_osinfo.next) {
2121 if (isp_watchdog_work(isp, xs)) {
2126 printf("isp_watchdog: nobody had %p active\n", arg);
2131 #if __FreeBSD_version >= 500000
2132 #define isp_make_here(isp, tgt) isp_announce(isp, tgt, AC_FOUND_DEVICE)
2133 #define isp_make_gone(isp, tgt) isp_announce(isp, tgt, AC_LOST_DEVICE)
2136 * Support function for Announcement
2139 isp_announce(ispsoftc_t *isp, int tgt, int action)
2141 struct cam_path *tmppath;
2142 ISPLOCK_2_CAMLOCK(isp);
2143 if (xpt_create_path(&tmppath, NULL, cam_sim_path(isp->isp_sim), tgt,
2144 CAM_LUN_WILDCARD) == CAM_REQ_CMP) {
2145 xpt_async(action, tmppath, NULL);
2146 xpt_free_path(tmppath);
2148 CAMLOCK_2_ISPLOCK(isp);
2151 #define isp_make_here(isp, tgt) do { ; } while (0)
2152 #define isp_make_gone(isp, tgt) do { ; } while (0)
2157 * Gone Device Timer Function- when we have decided that a device has gone
2158 * away, we wait a specific period of time prior to telling the OS it has
2161 * This timer function fires once a second and then scans the port database
2162 * for devices that are marked dead but still have a virtual target assigned.
2163 * We decrement a counter for that port database entry, and when it hits zero,
2164 * we tell the OS the device has gone away.
2169 ispsoftc_t *isp = arg;
2171 int dbidx, tgt, more_to_do = 0;
2173 isp_prt(isp, ISP_LOGDEBUG0, "GDT timer expired");
2175 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2176 lp = &FCPARAM(isp)->portdb[dbidx];
2178 if (lp->state != FC_PORTDB_STATE_ZOMBIE) {
2181 if (lp->ini_map_idx == 0) {
2184 if (lp->new_reserved == 0) {
2187 lp->new_reserved -= 1;
2188 if (lp->new_reserved != 0) {
2192 tgt = lp->ini_map_idx - 1;
2193 FCPARAM(isp)->isp_ini_map[tgt] = 0;
2194 lp->ini_map_idx = 0;
2195 lp->state = FC_PORTDB_STATE_NIL;
2196 isp_prt(isp, ISP_LOGCONFIG, prom3, lp->portid, tgt,
2197 "Gone Device Timeout");
2198 isp_make_gone(isp, tgt);
2201 isp->isp_osinfo.gdt = timeout(isp_gdt, isp, hz);
2203 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2204 "stopping Gone Device Timer");
2205 isp->isp_osinfo.gdt_running = 0;
2211 * Loop Down Timer Function- when loop goes down, a timer is started and
2212 * and after it expires we come here and take all probational devices that
2213 * the OS knows about and the tell the OS that they've gone away.
2215 * We don't clear the devices out of our port database because, when loop
2216 * come back up, we have to do some actual cleanup with the chip at that
2217 * point (implicit PLOGO, e.g., to get the chip's port database state right).
2222 ispsoftc_t *isp = arg;
2226 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Loop Down Timer expired");
2230 * Notify to the OS all targets who we now consider have departed.
2232 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2233 lp = &FCPARAM(isp)->portdb[dbidx];
2235 if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
2238 if (lp->ini_map_idx == 0) {
2243 * XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
2247 * Mark that we've announced that this device is gone....
2252 * but *don't* change the state of the entry. Just clear
2253 * any target id stuff and announce to CAM that the
2254 * device is gone. This way any necessary PLOGO stuff
2255 * will happen when loop comes back up.
2258 tgt = lp->ini_map_idx - 1;
2259 FCPARAM(isp)->isp_ini_map[tgt] = 0;
2260 lp->ini_map_idx = 0;
2261 isp_prt(isp, ISP_LOGCONFIG, prom3, lp->portid, tgt,
2262 "Loop Down Timeout");
2263 isp_make_gone(isp, tgt);
2267 * The loop down timer has expired. Wake up the kthread
2268 * to notice that fact (or make it false).
2270 isp->isp_osinfo.loop_down_time = isp->isp_osinfo.loop_down_limit+1;
2271 #if __FreeBSD_version < 500000
2272 wakeup(&isp->isp_osinfo.kproc);
2275 cv_signal(&isp->isp_osinfo.kthread_cv);
2277 wakeup(&isp->isp_osinfo.kthread_cv);
2284 isp_kthread(void *arg)
2286 ispsoftc_t *isp = arg;
2288 #if __FreeBSD_version < 500000
2294 mtx_lock(&isp->isp_lock);
2300 * The first loop is for our usage where we have yet to have
2301 * gotten good fibre channel state.
2304 int wasfrozen, lb, lim;
2306 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2307 "isp_kthread: checking FC state");
2308 isp->isp_osinfo.mbox_sleep_ok = 1;
2309 lb = isp_fc_runstate(isp, 250000);
2310 isp->isp_osinfo.mbox_sleep_ok = 0;
2313 * Increment loop down time by the last sleep interval
2315 isp->isp_osinfo.loop_down_time += slp;
2318 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2319 "kthread: FC loop not up (down count %d)",
2320 isp->isp_osinfo.loop_down_time);
2322 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2323 "kthread: FC got to %d (down count %d)",
2324 lb, isp->isp_osinfo.loop_down_time);
2329 * If we've never seen loop up and we've waited longer
2330 * than quickboot time, or we've seen loop up but we've
2331 * waited longer than loop_down_limit, give up and go
2332 * to sleep until loop comes up.
2334 if (FCPARAM(isp)->loop_seen_once == 0) {
2335 lim = isp_quickboot_time;
2337 lim = isp->isp_osinfo.loop_down_limit;
2339 if (isp->isp_osinfo.loop_down_time >= lim) {
2340 isp_freeze_loopdown(isp, "loop limit hit");
2342 } else if (isp->isp_osinfo.loop_down_time < 10) {
2344 } else if (isp->isp_osinfo.loop_down_time < 30) {
2346 } else if (isp->isp_osinfo.loop_down_time < 60) {
2348 } else if (isp->isp_osinfo.loop_down_time < 120) {
2355 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2356 "isp_kthread: FC state OK");
2357 isp->isp_osinfo.loop_down_time = 0;
2362 * If we'd frozen the simq, unfreeze it now so that CAM
2363 * can start sending us commands. If the FC state isn't
2364 * okay yet, they'll hit that in isp_start which will
2365 * freeze the queue again.
2367 wasfrozen = isp->isp_osinfo.simqfrozen & SIMQFRZ_LOOPDOWN;
2368 isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_LOOPDOWN;
2369 if (wasfrozen && isp->isp_osinfo.simqfrozen == 0) {
2370 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2371 "isp_kthread: releasing simq");
2372 ISPLOCK_2_CAMLOCK(isp);
2373 xpt_release_simq(isp->isp_sim, 1);
2374 CAMLOCK_2_ISPLOCK(isp);
2376 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2377 "isp_kthread: sleep time %d", slp);
2378 #if __FreeBSD_version < 500000
2379 tsleep(&isp->isp_osinfo.kproc, PRIBIO, "ispf",
2383 cv_timed_wait(&isp->isp_osinfo.kthread_cv, &isp->isp_lock,
2386 (void) tsleep(&isp->isp_osinfo.kthread_cv, PRIBIO, "ispf",
2391 * If slp is zero, we're waking up for the first time after
2392 * things have been okay. In this case, we set a deferral state
2393 * for all commands and delay hysteresis seconds before starting
2394 * the FC state evaluation. This gives the loop/fabric a chance
2397 if (slp == 0 && isp->isp_osinfo.hysteresis) {
2398 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2399 "isp_kthread: sleep hysteresis tick time %d",
2400 isp->isp_osinfo.hysteresis * hz);
2401 (void) tsleep(&isp_fabric_hysteresis, PRIBIO, "ispT",
2402 (isp->isp_osinfo.hysteresis * hz));
2408 isp_action(struct cam_sim *sim, union ccb *ccb)
2410 int bus, tgt, error, lim;
2412 struct ccb_trans_settings *cts;
2414 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
2416 isp = (ispsoftc_t *)cam_sim_softc(sim);
2417 ccb->ccb_h.sim_priv.entries[0].field = 0;
2418 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
2419 if (isp->isp_state != ISP_RUNSTATE &&
2420 ccb->ccb_h.func_code == XPT_SCSI_IO) {
2421 CAMLOCK_2_ISPLOCK(isp);
2423 if (isp->isp_state != ISP_INITSTATE) {
2426 * Lie. Say it was a selection timeout.
2428 ccb->ccb_h.status = CAM_SEL_TIMEOUT | CAM_DEV_QFRZN;
2429 xpt_freeze_devq(ccb->ccb_h.path, 1);
2433 isp->isp_state = ISP_RUNSTATE;
2434 ISPLOCK_2_CAMLOCK(isp);
2436 isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
2439 switch (ccb->ccb_h.func_code) {
2440 case XPT_SCSI_IO: /* Execute the requested I/O operation */
2442 * Do a couple of preliminary checks...
2444 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
2445 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
2446 ccb->ccb_h.status = CAM_REQ_INVALID;
2452 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
2453 xpt_print(ccb->ccb_h.path, "invalid target\n");
2454 ccb->ccb_h.status = CAM_PATH_INVALID;
2455 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
2456 xpt_print(ccb->ccb_h.path, "invalid lun\n");
2457 ccb->ccb_h.status = CAM_PATH_INVALID;
2459 if (ccb->ccb_h.status == CAM_PATH_INVALID) {
2464 ((struct ccb_scsiio *) ccb)->scsi_status = SCSI_STATUS_OK;
2465 CAMLOCK_2_ISPLOCK(isp);
2466 error = isp_start((XS_T *) ccb);
2469 XS_CMD_S_CLEAR(ccb);
2470 ISPLOCK_2_CAMLOCK(isp);
2471 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2472 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
2473 int ms = ccb->ccb_h.timeout;
2474 if (ms == CAM_TIME_DEFAULT) {
2477 ccb->ccb_h.timeout_ch =
2478 timeout(isp_watchdog, ccb, isp_mstohz(ms));
2480 callout_handle_init(&ccb->ccb_h.timeout_ch);
2485 * This can only happen for Fibre Channel
2487 KASSERT((IS_FC(isp)), ("CMD_RQLATER for FC only"));
2490 * Handle initial and subsequent loop down cases
2492 if (FCPARAM(isp)->loop_seen_once == 0) {
2493 lim = isp_quickboot_time;
2495 lim = isp->isp_osinfo.loop_down_limit;
2497 if (isp->isp_osinfo.loop_down_time >= lim) {
2498 isp_prt(isp, ISP_LOGDEBUG0,
2499 "%d.%d downtime (%d) > lim (%d)",
2500 XS_TGT(ccb), XS_LUN(ccb),
2501 isp->isp_osinfo.loop_down_time, lim);
2503 CAM_SEL_TIMEOUT|CAM_DEV_QFRZN;
2504 xpt_freeze_devq(ccb->ccb_h.path, 1);
2505 ISPLOCK_2_CAMLOCK(isp);
2509 isp_prt(isp, ISP_LOGDEBUG0,
2510 "%d.%d retry later", XS_TGT(ccb), XS_LUN(ccb));
2512 * Otherwise, retry in a while.
2514 ISPLOCK_2_CAMLOCK(isp);
2515 cam_freeze_devq(ccb->ccb_h.path);
2516 cam_release_devq(ccb->ccb_h.path,
2517 RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
2518 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2522 ISPLOCK_2_CAMLOCK(isp);
2523 cam_freeze_devq(ccb->ccb_h.path);
2524 cam_release_devq(ccb->ccb_h.path,
2525 RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
2529 isp_done((struct ccb_scsiio *) ccb);
2530 ISPLOCK_2_CAMLOCK(isp);
2533 ISPLOCK_2_CAMLOCK(isp);
2534 isp_prt(isp, ISP_LOGERR,
2535 "What's this? 0x%x at %d in file %s",
2536 error, __LINE__, __FILE__);
2537 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
2542 #ifdef ISP_TARGET_MODE
2543 case XPT_EN_LUN: /* Enable LUN as a target */
2546 CAMLOCK_2_ISPLOCK(isp);
2547 seq = isp_en_lun(isp, ccb);
2549 ISPLOCK_2_CAMLOCK(isp);
2553 for (i = 0; isp->isp_osinfo.leact[seq] && i < 30 * 1000; i++) {
2555 uint16_t sema, mbox;
2556 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2557 isp_intr(isp, isr, sema, mbox);
2561 ISPLOCK_2_CAMLOCK(isp);
2564 case XPT_NOTIFY_ACK: /* recycle notify ack */
2565 case XPT_IMMED_NOTIFY: /* Add Immediate Notify Resource */
2566 case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
2569 get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun);
2571 ccb->ccb_h.status = CAM_LUN_INVALID;
2575 ccb->ccb_h.sim_priv.entries[0].field = 0;
2576 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
2577 ccb->ccb_h.flags = 0;
2579 CAMLOCK_2_ISPLOCK(isp);
2580 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
2582 * Note that the command itself may not be done-
2583 * it may not even have had the first CTIO sent.
2586 isp_prt(isp, ISP_LOGTDEBUG0,
2587 "Put FREE ATIO, lun %d, count now %d",
2588 ccb->ccb_h.target_lun, tptr->atio_count);
2589 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h,
2591 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
2593 isp_prt(isp, ISP_LOGTDEBUG0,
2594 "Put FREE INOT, lun %d, count now %d",
2595 ccb->ccb_h.target_lun, tptr->inot_count);
2596 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h,
2599 isp_prt(isp, ISP_LOGWARN, "Got Notify ACK");;
2601 rls_lun_statep(isp, tptr);
2602 ccb->ccb_h.status = CAM_REQ_INPROG;
2603 ISPLOCK_2_CAMLOCK(isp);
2606 case XPT_CONT_TARGET_IO:
2608 CAMLOCK_2_ISPLOCK(isp);
2609 isp_target_start_ctio(isp, ccb);
2610 ISPLOCK_2_CAMLOCK(isp);
2614 case XPT_RESET_DEV: /* BDR the specified SCSI device */
2616 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
2617 tgt = ccb->ccb_h.target_id;
2620 CAMLOCK_2_ISPLOCK(isp);
2621 error = isp_control(isp, ISPCTL_RESET_DEV, &tgt);
2622 ISPLOCK_2_CAMLOCK(isp);
2624 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2626 ccb->ccb_h.status = CAM_REQ_CMP;
2630 case XPT_ABORT: /* Abort the specified CCB */
2632 union ccb *accb = ccb->cab.abort_ccb;
2633 CAMLOCK_2_ISPLOCK(isp);
2634 switch (accb->ccb_h.func_code) {
2635 #ifdef ISP_TARGET_MODE
2636 case XPT_ACCEPT_TARGET_IO:
2637 case XPT_IMMED_NOTIFY:
2638 ccb->ccb_h.status = isp_abort_tgt_ccb(isp, ccb);
2640 case XPT_CONT_TARGET_IO:
2641 isp_prt(isp, ISP_LOGERR, "cannot abort CTIOs yet");
2642 ccb->ccb_h.status = CAM_UA_ABORT;
2646 error = isp_control(isp, ISPCTL_ABORT_CMD, ccb);
2648 ccb->ccb_h.status = CAM_UA_ABORT;
2650 ccb->ccb_h.status = CAM_REQ_CMP;
2654 ccb->ccb_h.status = CAM_REQ_INVALID;
2657 ISPLOCK_2_CAMLOCK(isp);
2661 #ifdef CAM_NEW_TRAN_CODE
2662 #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
2664 #define IS_CURRENT_SETTINGS(c) (c->flags & CCB_TRANS_CURRENT_SETTINGS)
2666 case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */
2668 if (!IS_CURRENT_SETTINGS(cts)) {
2669 ccb->ccb_h.status = CAM_REQ_INVALID;
2673 tgt = cts->ccb_h.target_id;
2674 CAMLOCK_2_ISPLOCK(isp);
2676 #ifndef CAM_NEW_TRAN_CODE
2677 sdparam *sdp = isp->isp_param;
2680 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2684 * We always update (internally) from goal_flags
2685 * so any request to change settings just gets
2686 * vectored to that location.
2688 dptr = &sdp->isp_devparam[tgt].goal_flags;
2691 * Note that these operations affect the
2692 * the goal flags (goal_flags)- not
2693 * the current state flags. Then we mark
2694 * things so that the next operation to
2695 * this HBA will cause the update to occur.
2697 if (cts->valid & CCB_TRANS_DISC_VALID) {
2698 if ((cts->flags & CCB_TRANS_DISC_ENB) != 0) {
2699 *dptr |= DPARM_DISC;
2701 *dptr &= ~DPARM_DISC;
2704 if (cts->valid & CCB_TRANS_TQ_VALID) {
2705 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0) {
2706 *dptr |= DPARM_TQING;
2708 *dptr &= ~DPARM_TQING;
2711 if (cts->valid & CCB_TRANS_BUS_WIDTH_VALID) {
2712 switch (cts->bus_width) {
2713 case MSG_EXT_WDTR_BUS_16_BIT:
2714 *dptr |= DPARM_WIDE;
2717 *dptr &= ~DPARM_WIDE;
2721 * Any SYNC RATE of nonzero and SYNC_OFFSET
2722 * of nonzero will cause us to go to the
2723 * selected (from NVRAM) maximum value for
2724 * this device. At a later point, we'll
2725 * allow finer control.
2727 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) &&
2728 (cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) &&
2729 (cts->sync_offset > 0)) {
2730 *dptr |= DPARM_SYNC;
2732 *dptr &= ~DPARM_SYNC;
2734 *dptr |= DPARM_SAFE_DFLT;
2736 struct ccb_trans_settings_scsi *scsi =
2737 &cts->proto_specific.scsi;
2738 struct ccb_trans_settings_spi *spi =
2739 &cts->xport_specific.spi;
2740 sdparam *sdp = isp->isp_param;
2743 if (spi->valid == 0 && scsi->valid == 0) {
2744 ISPLOCK_2_CAMLOCK(isp);
2745 ccb->ccb_h.status = CAM_REQ_CMP;
2750 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2753 * We always update (internally) from goal_flags
2754 * so any request to change settings just gets
2755 * vectored to that location.
2757 dptr = &sdp->isp_devparam[tgt].goal_flags;
2759 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
2760 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
2761 *dptr |= DPARM_DISC;
2763 *dptr &= ~DPARM_DISC;
2766 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2767 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
2768 *dptr |= DPARM_TQING;
2770 *dptr &= ~DPARM_TQING;
2773 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
2774 if (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT)
2775 *dptr |= DPARM_WIDE;
2777 *dptr &= ~DPARM_WIDE;
2783 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) &&
2784 (spi->valid & CTS_SPI_VALID_SYNC_RATE) &&
2785 (spi->sync_period && spi->sync_offset)) {
2786 *dptr |= DPARM_SYNC;
2788 * XXX: CHECK FOR LEGALITY
2790 sdp->isp_devparam[tgt].goal_period =
2792 sdp->isp_devparam[tgt].goal_offset =
2795 *dptr &= ~DPARM_SYNC;
2798 isp_prt(isp, ISP_LOGDEBUG0,
2799 "SET (%d.%d.%d) to flags %x off %x per %x",
2800 bus, tgt, cts->ccb_h.target_lun,
2801 sdp->isp_devparam[tgt].goal_flags,
2802 sdp->isp_devparam[tgt].goal_offset,
2803 sdp->isp_devparam[tgt].goal_period);
2804 sdp->isp_devparam[tgt].dev_update = 1;
2805 isp->isp_update |= (1 << bus);
2807 ISPLOCK_2_CAMLOCK(isp);
2808 ccb->ccb_h.status = CAM_REQ_CMP;
2811 case XPT_GET_TRAN_SETTINGS:
2813 tgt = cts->ccb_h.target_id;
2814 CAMLOCK_2_ISPLOCK(isp);
2816 #ifndef CAM_NEW_TRAN_CODE
2818 * a lot of normal SCSI things don't make sense.
2820 cts->flags = CCB_TRANS_TAG_ENB | CCB_TRANS_DISC_ENB;
2821 cts->valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
2823 * How do you measure the width of a high
2824 * speed serial bus? Well, in bytes.
2826 * Offset and period make no sense, though, so we set
2827 * (above) a 'base' transfer speed to be gigabit.
2829 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2831 fcparam *fcp = isp->isp_param;
2832 struct ccb_trans_settings_scsi *scsi =
2833 &cts->proto_specific.scsi;
2834 struct ccb_trans_settings_fc *fc =
2835 &cts->xport_specific.fc;
2837 cts->protocol = PROTO_SCSI;
2838 cts->protocol_version = SCSI_REV_2;
2839 cts->transport = XPORT_FC;
2840 cts->transport_version = 0;
2842 scsi->valid = CTS_SCSI_VALID_TQ;
2843 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
2844 fc->valid = CTS_FC_VALID_SPEED;
2845 if (fcp->isp_gbspeed == 2) {
2846 fc->bitrate = 200000;
2848 fc->bitrate = 100000;
2850 if (tgt > 0 && tgt < MAX_FC_TARG) {
2851 fcportdb_t *lp = &fcp->portdb[tgt];
2852 fc->wwnn = lp->node_wwn;
2853 fc->wwpn = lp->port_wwn;
2854 fc->port = lp->portid;
2855 fc->valid |= CTS_FC_VALID_WWNN |
2856 CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT;
2860 #ifdef CAM_NEW_TRAN_CODE
2861 struct ccb_trans_settings_scsi *scsi =
2862 &cts->proto_specific.scsi;
2863 struct ccb_trans_settings_spi *spi =
2864 &cts->xport_specific.spi;
2866 sdparam *sdp = isp->isp_param;
2867 int bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2868 uint16_t dval, pval, oval;
2872 if (IS_CURRENT_SETTINGS(cts)) {
2873 sdp->isp_devparam[tgt].dev_refresh = 1;
2874 isp->isp_update |= (1 << bus);
2875 (void) isp_control(isp, ISPCTL_UPDATE_PARAMS,
2877 dval = sdp->isp_devparam[tgt].actv_flags;
2878 oval = sdp->isp_devparam[tgt].actv_offset;
2879 pval = sdp->isp_devparam[tgt].actv_period;
2881 dval = sdp->isp_devparam[tgt].nvrm_flags;
2882 oval = sdp->isp_devparam[tgt].nvrm_offset;
2883 pval = sdp->isp_devparam[tgt].nvrm_period;
2886 #ifndef CAM_NEW_TRAN_CODE
2887 cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB);
2889 if (dval & DPARM_DISC) {
2890 cts->flags |= CCB_TRANS_DISC_ENB;
2892 if (dval & DPARM_TQING) {
2893 cts->flags |= CCB_TRANS_TAG_ENB;
2895 if (dval & DPARM_WIDE) {
2896 cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2898 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2900 cts->valid = CCB_TRANS_BUS_WIDTH_VALID |
2901 CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
2903 if ((dval & DPARM_SYNC) && oval != 0) {
2904 cts->sync_period = pval;
2905 cts->sync_offset = oval;
2907 CCB_TRANS_SYNC_RATE_VALID |
2908 CCB_TRANS_SYNC_OFFSET_VALID;
2911 cts->protocol = PROTO_SCSI;
2912 cts->protocol_version = SCSI_REV_2;
2913 cts->transport = XPORT_SPI;
2914 cts->transport_version = 2;
2920 if (dval & DPARM_DISC) {
2921 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
2923 if ((dval & DPARM_SYNC) && oval && pval) {
2924 spi->sync_offset = oval;
2925 spi->sync_period = pval;
2927 spi->sync_offset = 0;
2928 spi->sync_period = 0;
2930 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2931 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2932 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
2933 if (dval & DPARM_WIDE) {
2934 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2936 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2938 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
2939 scsi->valid = CTS_SCSI_VALID_TQ;
2940 if (dval & DPARM_TQING) {
2941 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
2943 spi->valid |= CTS_SPI_VALID_DISC;
2946 isp_prt(isp, ISP_LOGDEBUG0,
2947 "GET %s (%d.%d.%d) to flags %x off %x per %x",
2948 IS_CURRENT_SETTINGS(cts)? "ACTIVE" : "NVRAM",
2949 bus, tgt, cts->ccb_h.target_lun, dval, oval, pval);
2951 ISPLOCK_2_CAMLOCK(isp);
2952 ccb->ccb_h.status = CAM_REQ_CMP;
2956 case XPT_CALC_GEOMETRY:
2957 #if __FreeBSD_version < 500000
2959 struct ccb_calc_geometry *ccg;
2960 u_int32_t secs_per_cylinder;
2964 if (ccg->block_size == 0) {
2965 ccb->ccb_h.status = CAM_REQ_INVALID;
2969 size_mb = ccg->volume_size /((1024L * 1024L) / ccg->block_size);
2970 if (size_mb > 1024) {
2972 ccg->secs_per_track = 63;
2975 ccg->secs_per_track = 32;
2977 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
2978 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
2979 ccb->ccb_h.status = CAM_REQ_CMP;
2985 cam_calc_geometry(&ccb->ccg, /*extended*/1);
2990 case XPT_RESET_BUS: /* Reset the specified bus */
2991 bus = cam_sim_bus(sim);
2992 CAMLOCK_2_ISPLOCK(isp);
2993 error = isp_control(isp, ISPCTL_RESET_BUS, &bus);
2994 ISPLOCK_2_CAMLOCK(isp);
2996 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2998 if (cam_sim_bus(sim) && isp->isp_path2 != NULL)
2999 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
3000 else if (isp->isp_path != NULL)
3001 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
3002 ccb->ccb_h.status = CAM_REQ_CMP;
3007 case XPT_TERM_IO: /* Terminate the I/O process */
3008 ccb->ccb_h.status = CAM_REQ_INVALID;
3012 case XPT_PATH_INQ: /* Path routing inquiry */
3014 struct ccb_pathinq *cpi = &ccb->cpi;
3016 cpi->version_num = 1;
3017 #ifdef ISP_TARGET_MODE
3018 cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
3020 cpi->target_sprt = 0;
3022 cpi->hba_eng_cnt = 0;
3023 cpi->max_target = ISP_MAX_TARGETS(isp) - 1;
3024 cpi->max_lun = ISP_MAX_LUNS(isp) - 1;
3025 cpi->bus_id = cam_sim_bus(sim);
3027 cpi->hba_misc = PIM_NOBUSRESET;
3029 * Because our loop ID can shift from time to time,
3030 * make our initiator ID out of range of our bus.
3032 cpi->initiator_id = cpi->max_target + 1;
3035 * Set base transfer capabilities for Fibre Channel.
3036 * Technically not correct because we don't know
3037 * what media we're running on top of- but we'll
3038 * look good if we always say 100MB/s.
3040 if (FCPARAM(isp)->isp_gbspeed == 2)
3041 cpi->base_transfer_speed = 200000;
3043 cpi->base_transfer_speed = 100000;
3044 cpi->hba_inquiry = PI_TAG_ABLE;
3045 #ifdef CAM_NEW_TRAN_CODE
3046 cpi->transport = XPORT_FC;
3047 cpi->transport_version = 0;
3050 sdparam *sdp = isp->isp_param;
3051 sdp += cam_sim_bus(xpt_path_sim(cpi->ccb_h.path));
3052 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
3054 cpi->initiator_id = sdp->isp_initiator_id;
3055 cpi->base_transfer_speed = 3300;
3056 #ifdef CAM_NEW_TRAN_CODE
3057 cpi->transport = XPORT_SPI;
3058 cpi->transport_version = 2;
3061 #ifdef CAM_NEW_TRAN_CODE
3062 cpi->protocol = PROTO_SCSI;
3063 cpi->protocol_version = SCSI_REV_2;
3065 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
3066 strncpy(cpi->hba_vid, "Qlogic", HBA_IDLEN);
3067 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
3068 cpi->unit_number = cam_sim_unit(sim);
3069 cpi->ccb_h.status = CAM_REQ_CMP;
3074 ccb->ccb_h.status = CAM_REQ_INVALID;
3080 #define ISPDDB (CAM_DEBUG_INFO|CAM_DEBUG_TRACE|CAM_DEBUG_CDB)
3083 isp_done(struct ccb_scsiio *sccb)
3085 ispsoftc_t *isp = XS_ISP(sccb);
3088 XS_SETERR(sccb, CAM_REQ_CMP);
3090 if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
3091 (sccb->scsi_status != SCSI_STATUS_OK)) {
3092 sccb->ccb_h.status &= ~CAM_STATUS_MASK;
3093 if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) &&
3094 (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) {
3095 sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
3097 sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
3101 sccb->ccb_h.status &= ~CAM_SIM_QUEUED;
3102 if ((sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3103 isp_prt(isp, ISP_LOGDEBUG0,
3104 "target %d lun %d CAM status 0x%x SCSI status 0x%x",
3105 XS_TGT(sccb), XS_LUN(sccb), sccb->ccb_h.status,
3107 if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
3108 sccb->ccb_h.status |= CAM_DEV_QFRZN;
3109 xpt_freeze_devq(sccb->ccb_h.path, 1);
3113 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) &&
3114 (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3115 xpt_print(sccb->ccb_h.path,
3116 "cam completion status 0x%x\n", sccb->ccb_h.status);
3119 XS_CMD_S_DONE(sccb);
3120 if (XS_CMD_WDOG_P(sccb) == 0) {
3121 untimeout(isp_watchdog, sccb, sccb->ccb_h.timeout_ch);
3122 if (XS_CMD_GRACE_P(sccb)) {
3123 isp_prt(isp, ISP_LOGDEBUG2,
3124 "finished command on borrowed time");
3126 XS_CMD_S_CLEAR(sccb);
3127 ISPLOCK_2_CAMLOCK(isp);
3128 xpt_done((union ccb *) sccb);
3129 CAMLOCK_2_ISPLOCK(isp);
3134 isp_async(ispsoftc_t *isp, ispasync_t cmd, void *arg)
3137 static const char prom[] =
3138 "PortID 0x%06x handle 0x%x role %s %s\n"
3139 " WWNN 0x%08x%08x WWPN 0x%08x%08x";
3140 static const char prom2[] =
3141 "PortID 0x%06x handle 0x%x role %s %s tgt %u\n"
3142 " WWNN 0x%08x%08x WWPN 0x%08x%08x";
3146 struct cam_path *tmppath;
3149 case ISPASYNC_NEW_TGT_PARAMS:
3151 #ifdef CAM_NEW_TRAN_CODE
3152 struct ccb_trans_settings_scsi *scsi;
3153 struct ccb_trans_settings_spi *spi;
3156 sdparam *sdp = isp->isp_param;
3157 struct ccb_trans_settings cts;
3159 memset(&cts, 0, sizeof (struct ccb_trans_settings));
3161 tgt = *((int *)arg);
3162 bus = (tgt >> 16) & 0xffff;
3165 ISPLOCK_2_CAMLOCK(isp);
3166 if (xpt_create_path(&tmppath, NULL,
3167 cam_sim_path(bus? isp->isp_sim2 : isp->isp_sim),
3168 tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
3169 CAMLOCK_2_ISPLOCK(isp);
3170 isp_prt(isp, ISP_LOGWARN,
3171 "isp_async cannot make temp path for %d.%d",
3176 CAMLOCK_2_ISPLOCK(isp);
3177 flags = sdp->isp_devparam[tgt].actv_flags;
3178 #ifdef CAM_NEW_TRAN_CODE
3179 cts.type = CTS_TYPE_CURRENT_SETTINGS;
3180 cts.protocol = PROTO_SCSI;
3181 cts.transport = XPORT_SPI;
3183 scsi = &cts.proto_specific.scsi;
3184 spi = &cts.xport_specific.spi;
3186 if (flags & DPARM_TQING) {
3187 scsi->valid |= CTS_SCSI_VALID_TQ;
3188 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
3191 if (flags & DPARM_DISC) {
3192 spi->valid |= CTS_SPI_VALID_DISC;
3193 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
3195 spi->flags |= CTS_SPI_VALID_BUS_WIDTH;
3196 if (flags & DPARM_WIDE) {
3197 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
3199 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
3201 if (flags & DPARM_SYNC) {
3202 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
3203 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
3204 spi->sync_period = sdp->isp_devparam[tgt].actv_period;
3205 spi->sync_offset = sdp->isp_devparam[tgt].actv_offset;
3208 cts.flags = CCB_TRANS_CURRENT_SETTINGS;
3209 cts.valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
3210 if (flags & DPARM_DISC) {
3211 cts.flags |= CCB_TRANS_DISC_ENB;
3213 if (flags & DPARM_TQING) {
3214 cts.flags |= CCB_TRANS_TAG_ENB;
3216 cts.valid |= CCB_TRANS_BUS_WIDTH_VALID;
3217 cts.bus_width = (flags & DPARM_WIDE)?
3218 MSG_EXT_WDTR_BUS_8_BIT : MSG_EXT_WDTR_BUS_16_BIT;
3219 cts.sync_period = sdp->isp_devparam[tgt].actv_period;
3220 cts.sync_offset = sdp->isp_devparam[tgt].actv_offset;
3221 if (flags & DPARM_SYNC) {
3223 CCB_TRANS_SYNC_RATE_VALID |
3224 CCB_TRANS_SYNC_OFFSET_VALID;
3227 isp_prt(isp, ISP_LOGDEBUG2,
3228 "NEW_TGT_PARAMS bus %d tgt %d period %x offset %x flags %x",
3229 bus, tgt, sdp->isp_devparam[tgt].actv_period,
3230 sdp->isp_devparam[tgt].actv_offset, flags);
3231 xpt_setup_ccb(&cts.ccb_h, tmppath, 1);
3232 ISPLOCK_2_CAMLOCK(isp);
3233 xpt_async(AC_TRANSFER_NEG, tmppath, &cts);
3234 xpt_free_path(tmppath);
3235 CAMLOCK_2_ISPLOCK(isp);
3238 case ISPASYNC_BUS_RESET:
3239 bus = *((int *)arg);
3240 isp_prt(isp, ISP_LOGINFO, "SCSI bus reset on bus %d detected",
3242 if (bus > 0 && isp->isp_path2) {
3243 ISPLOCK_2_CAMLOCK(isp);
3244 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
3245 CAMLOCK_2_ISPLOCK(isp);
3246 } else if (isp->isp_path) {
3247 ISPLOCK_2_CAMLOCK(isp);
3248 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
3249 CAMLOCK_2_ISPLOCK(isp);
3254 msg = "LIP Received";
3257 case ISPASYNC_LOOP_RESET:
3262 case ISPASYNC_LOOP_DOWN:
3266 if (isp->isp_path) {
3267 isp_freeze_loopdown(isp, msg);
3269 if (isp->isp_osinfo.ldt_running == 0) {
3270 isp->isp_osinfo.ldt = timeout(isp_ldt, isp,
3271 isp->isp_osinfo.loop_down_limit * hz);
3272 isp->isp_osinfo.ldt_running = 1;
3273 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3274 "starting Loop Down Timer");
3276 isp_prt(isp, ISP_LOGINFO, msg);
3278 case ISPASYNC_LOOP_UP:
3280 * Now we just note that Loop has come up. We don't
3281 * actually do anything because we're waiting for a
3282 * Change Notify before activating the FC cleanup
3283 * thread to look at the state of the loop again.
3285 isp_prt(isp, ISP_LOGINFO, "Loop UP");
3287 case ISPASYNC_DEV_ARRIVED:
3290 if ((isp->isp_role & ISP_ROLE_INITIATOR) &&
3291 (lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT))) {
3292 int dbidx = lp - FCPARAM(isp)->portdb;
3295 for (i = 0; i < MAX_FC_TARG; i++) {
3296 if (i >= FL_ID && i <= SNS_ID) {
3299 if (FCPARAM(isp)->isp_ini_map[i] == 0) {
3303 if (i < MAX_FC_TARG) {
3304 FCPARAM(isp)->isp_ini_map[i] = dbidx + 1;
3305 lp->ini_map_idx = i + 1;
3307 isp_prt(isp, ISP_LOGWARN, "out of target ids");
3308 isp_dump_portdb(isp);
3311 if (lp->ini_map_idx) {
3312 tgt = lp->ini_map_idx - 1;
3313 isp_prt(isp, ISP_LOGCONFIG, prom2,
3314 lp->portid, lp->handle,
3315 roles[lp->roles], "arrived at", tgt,
3316 (uint32_t) (lp->node_wwn >> 32),
3317 (uint32_t) lp->node_wwn,
3318 (uint32_t) (lp->port_wwn >> 32),
3319 (uint32_t) lp->port_wwn);
3320 isp_make_here(isp, tgt);
3322 isp_prt(isp, ISP_LOGCONFIG, prom,
3323 lp->portid, lp->handle,
3324 roles[lp->roles], "arrived",
3325 (uint32_t) (lp->node_wwn >> 32),
3326 (uint32_t) lp->node_wwn,
3327 (uint32_t) (lp->port_wwn >> 32),
3328 (uint32_t) lp->port_wwn);
3331 case ISPASYNC_DEV_CHANGED:
3333 if (isp_change_is_bad) {
3334 lp->state = FC_PORTDB_STATE_NIL;
3335 if (lp->ini_map_idx) {
3336 tgt = lp->ini_map_idx - 1;
3337 FCPARAM(isp)->isp_ini_map[tgt] = 0;
3338 lp->ini_map_idx = 0;
3339 isp_prt(isp, ISP_LOGCONFIG, prom3,
3340 lp->portid, tgt, "change is bad");
3341 isp_make_gone(isp, tgt);
3343 isp_prt(isp, ISP_LOGCONFIG, prom,
3344 lp->portid, lp->handle,
3346 "changed and departed",
3347 (uint32_t) (lp->node_wwn >> 32),
3348 (uint32_t) lp->node_wwn,
3349 (uint32_t) (lp->port_wwn >> 32),
3350 (uint32_t) lp->port_wwn);
3353 lp->portid = lp->new_portid;
3354 lp->roles = lp->new_roles;
3355 if (lp->ini_map_idx) {
3356 int t = lp->ini_map_idx - 1;
3357 FCPARAM(isp)->isp_ini_map[t] =
3358 (lp - FCPARAM(isp)->portdb) + 1;
3359 tgt = lp->ini_map_idx - 1;
3360 isp_prt(isp, ISP_LOGCONFIG, prom2,
3361 lp->portid, lp->handle,
3362 roles[lp->roles], "changed at", tgt,
3363 (uint32_t) (lp->node_wwn >> 32),
3364 (uint32_t) lp->node_wwn,
3365 (uint32_t) (lp->port_wwn >> 32),
3366 (uint32_t) lp->port_wwn);
3368 isp_prt(isp, ISP_LOGCONFIG, prom,
3369 lp->portid, lp->handle,
3370 roles[lp->roles], "changed",
3371 (uint32_t) (lp->node_wwn >> 32),
3372 (uint32_t) lp->node_wwn,
3373 (uint32_t) (lp->port_wwn >> 32),
3374 (uint32_t) lp->port_wwn);
3378 case ISPASYNC_DEV_STAYED:
3380 if (lp->ini_map_idx) {
3381 tgt = lp->ini_map_idx - 1;
3382 isp_prt(isp, ISP_LOGCONFIG, prom2,
3383 lp->portid, lp->handle,
3384 roles[lp->roles], "stayed at", tgt,
3385 (uint32_t) (lp->node_wwn >> 32),
3386 (uint32_t) lp->node_wwn,
3387 (uint32_t) (lp->port_wwn >> 32),
3388 (uint32_t) lp->port_wwn);
3390 isp_prt(isp, ISP_LOGCONFIG, prom,
3391 lp->portid, lp->handle,
3392 roles[lp->roles], "stayed",
3393 (uint32_t) (lp->node_wwn >> 32),
3394 (uint32_t) lp->node_wwn,
3395 (uint32_t) (lp->port_wwn >> 32),
3396 (uint32_t) lp->port_wwn);
3399 case ISPASYNC_DEV_GONE:
3402 * If this has a virtual target and we haven't marked it
3403 * that we're going to have isp_gdt tell the OS it's gone,
3404 * set the isp_gdt timer running on it.
3406 * If it isn't marked that isp_gdt is going to get rid of it,
3407 * announce that it's gone.
3409 if (lp->ini_map_idx && lp->reserved == 0) {
3411 lp->new_reserved = isp->isp_osinfo.gone_device_time;
3412 lp->state = FC_PORTDB_STATE_ZOMBIE;
3413 if (isp->isp_osinfo.gdt_running == 0) {
3414 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3415 "starting Gone Device Timer");
3416 isp->isp_osinfo.gdt = timeout(isp_gdt, isp, hz);
3417 isp->isp_osinfo.gdt_running = 1;
3419 tgt = lp->ini_map_idx - 1;
3420 isp_prt(isp, ISP_LOGCONFIG, prom2,
3421 lp->portid, lp->handle,
3422 roles[lp->roles], "gone zombie at", tgt,
3423 (uint32_t) (lp->node_wwn >> 32),
3424 (uint32_t) lp->node_wwn,
3425 (uint32_t) (lp->port_wwn >> 32),
3426 (uint32_t) lp->port_wwn);
3427 } else if (lp->reserved == 0) {
3428 isp_prt(isp, ISP_LOGCONFIG, prom,
3429 lp->portid, lp->handle,
3430 roles[lp->roles], "departed",
3431 (uint32_t) (lp->node_wwn >> 32),
3432 (uint32_t) lp->node_wwn,
3433 (uint32_t) (lp->port_wwn >> 32),
3434 (uint32_t) lp->port_wwn);
3437 case ISPASYNC_CHANGE_NOTIFY:
3440 if (arg == ISPASYNC_CHANGE_PDB) {
3441 msg = "Port Database Changed";
3442 } else if (arg == ISPASYNC_CHANGE_SNS) {
3443 msg = "Name Server Database Changed";
3445 msg = "Other Change Notify";
3448 * If the loop down timer is running, cancel it.
3450 if (isp->isp_osinfo.ldt_running) {
3451 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3452 "Stopping Loop Down Timer");
3453 isp->isp_osinfo.ldt_running = 0;
3454 untimeout(isp_ldt, isp, isp->isp_osinfo.ldt);
3455 callout_handle_init(&isp->isp_osinfo.ldt);
3457 isp_prt(isp, ISP_LOGINFO, msg);
3458 isp_freeze_loopdown(isp, msg);
3459 #if __FreeBSD_version < 500000
3460 wakeup(&isp->isp_osinfo.kproc);
3463 cv_signal(&isp->isp_osinfo.kthread_cv);
3465 wakeup(&isp->isp_osinfo.kthread_cv);
3470 #ifdef ISP_TARGET_MODE
3471 case ISPASYNC_TARGET_NOTIFY:
3473 tmd_notify_t *nt = arg;
3474 isp_prt(isp, ISP_LOGALL,
3475 "target notify code 0x%x", nt->nt_ncode);
3478 case ISPASYNC_TARGET_ACTION:
3479 switch (((isphdr_t *)arg)->rqs_entry_type) {
3481 isp_prt(isp, ISP_LOGWARN,
3482 "event 0x%x for unhandled target action",
3483 ((isphdr_t *)arg)->rqs_entry_type);
3485 case RQSTYPE_NOTIFY:
3487 rv = isp_handle_platform_notify_scsi(isp,
3488 (in_entry_t *) arg);
3490 rv = isp_handle_platform_notify_fc(isp,
3491 (in_fcentry_t *) arg);
3495 rv = isp_handle_platform_atio(isp, (at_entry_t *) arg);
3498 rv = isp_handle_platform_atio2(isp, (at2_entry_t *)arg);
3503 rv = isp_handle_platform_ctio(isp, arg);
3505 case RQSTYPE_ENABLE_LUN:
3506 case RQSTYPE_MODIFY_LUN:
3507 isp_ledone(isp, (lun_entry_t *) arg);
3512 case ISPASYNC_FW_CRASH:
3514 uint16_t mbox1, mbox6;
3515 mbox1 = ISP_READ(isp, OUTMAILBOX1);
3516 if (IS_DUALBUS(isp)) {
3517 mbox6 = ISP_READ(isp, OUTMAILBOX6);
3521 isp_prt(isp, ISP_LOGERR,
3522 "Internal Firmware Error on bus %d @ RISC Address 0x%x",
3524 #ifdef ISP_FW_CRASH_DUMP
3526 * XXX: really need a thread to do this right.
3529 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3530 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
3531 isp_freeze_loopdown(isp, "f/w crash");
3535 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3539 case ISPASYNC_UNHANDLED_RESPONSE:
3542 isp_prt(isp, ISP_LOGERR, "unknown isp_async event %d", cmd);
3550 * Locks are held before coming here.
3553 isp_uninit(ispsoftc_t *isp)
3556 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
3558 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
3560 ISP_DISABLE_INTS(isp);
3564 isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
3567 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
3570 printf("%s: ", device_get_nameunit(isp->isp_dev));
3578 isp_nanotime_sub(struct timespec *b, struct timespec *a)
3581 struct timespec x = *b;
3583 elapsed = GET_NANOSEC(&x);
3590 isp_mbox_acquire(ispsoftc_t *isp)
3592 if (isp->isp_osinfo.mboxbsy) {
3595 isp->isp_osinfo.mboxcmd_done = 0;
3596 isp->isp_osinfo.mboxbsy = 1;
3602 isp_mbox_wait_complete(ispsoftc_t *isp, mbreg_t *mbp)
3604 unsigned int usecs = mbp->timeout;
3605 unsigned int max, olim, ilim;
3608 usecs = MBCMD_DEFAULT_TIMEOUT;
3610 max = isp->isp_mbxwrk0 + 1;
3612 if (isp->isp_osinfo.mbox_sleep_ok) {
3613 unsigned int ms = (usecs + 999) / 1000;
3615 isp->isp_osinfo.mbox_sleep_ok = 0;
3616 isp->isp_osinfo.mbox_sleeping = 1;
3617 for (olim = 0; olim < max; olim++) {
3618 #if __FreeBSD_version < 500000 || !defined(ISP_SMPLOCK)
3619 tsleep(&isp->isp_mbxworkp, PRIBIO, "ispmbx_sleep",
3622 msleep(&isp->isp_mbxworkp, &isp->isp_mtx, PRIBIO,
3623 "ispmbx_sleep", isp_mstohz(ms));
3625 if (isp->isp_osinfo.mboxcmd_done) {
3629 isp->isp_osinfo.mbox_sleep_ok = 1;
3630 isp->isp_osinfo.mbox_sleeping = 0;
3632 for (olim = 0; olim < max; olim++) {
3633 for (ilim = 0; ilim < usecs; ilim += 100) {
3635 uint16_t sema, mbox;
3636 if (isp->isp_osinfo.mboxcmd_done) {
3639 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
3640 isp_intr(isp, isr, sema, mbox);
3641 if (isp->isp_osinfo.mboxcmd_done) {
3647 if (isp->isp_osinfo.mboxcmd_done) {
3652 if (isp->isp_osinfo.mboxcmd_done == 0) {
3653 isp_prt(isp, ISP_LOGWARN,
3654 "%s Mailbox Command (0x%x) Timeout",
3655 isp->isp_osinfo.mbox_sleep_ok? "Interrupting" : "Polled",
3656 isp->isp_lastmbxcmd);
3657 mbp->param[0] = MBOX_TIMEOUT;
3658 isp->isp_osinfo.mboxcmd_done = 1;
3663 isp_mbox_notify_done(ispsoftc_t *isp)
3665 if (isp->isp_osinfo.mbox_sleeping) {
3666 wakeup(&isp->isp_mbxworkp);
3668 isp->isp_osinfo.mboxcmd_done = 1;
3672 isp_mbox_release(ispsoftc_t *isp)
3674 isp->isp_osinfo.mboxbsy = 0;
3682 t.tv_sec = ms / 1000;
3683 t.tv_usec = (ms % 1000) * 1000;