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>
46 MODULE_VERSION(isp, 1);
47 MODULE_DEPEND(isp, cam, 1, 1, 1);
48 int isp_announced = 0;
50 static d_ioctl_t ispioctl;
51 static void isp_intr_enable(void *);
52 static void isp_cam_async(void *, uint32_t, struct cam_path *, void *);
53 static void isp_poll(struct cam_sim *);
54 static timeout_t isp_watchdog;
55 static void isp_kthread(void *);
56 static void isp_action(struct cam_sim *, union ccb *);
58 #if __FreeBSD_version < 700000
59 ispfwfunc *isp_get_firmware_p = NULL;
62 #if __FreeBSD_version < 500000
63 #define ISP_CDEV_MAJOR 248
64 static struct cdevsw isp_cdevsw = {
66 /* close */ nullclose,
72 /* strategy */ nostrategy,
74 /* maj */ ISP_CDEV_MAJOR,
79 #define isp_sysctl_update(x) do { ; } while (0)
81 static struct cdevsw isp_cdevsw = {
82 .d_version = D_VERSION,
83 .d_flags = D_NEEDGIANT,
87 static void isp_sysctl_update(ispsoftc_t *);
90 static ispsoftc_t *isplist = NULL;
93 isp_attach(ispsoftc_t *isp)
95 int primary, secondary;
96 struct ccb_setasync csa;
97 struct cam_devq *devq;
99 struct cam_path *path;
102 * Establish (in case of 12X0) which bus is the primary.
109 * Create the device queue for our SIM(s).
111 devq = cam_simq_alloc(isp->isp_maxcmds);
117 * Construct our SIM entry.
119 ISPLOCK_2_CAMLOCK(isp);
120 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
121 device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq);
124 CAMLOCK_2_ISPLOCK(isp);
127 CAMLOCK_2_ISPLOCK(isp);
129 isp->isp_osinfo.ehook.ich_func = isp_intr_enable;
130 isp->isp_osinfo.ehook.ich_arg = isp;
131 ISPLOCK_2_CAMLOCK(isp);
132 if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) {
133 cam_sim_free(sim, TRUE);
134 CAMLOCK_2_ISPLOCK(isp);
135 isp_prt(isp, ISP_LOGERR,
136 "could not establish interrupt enable hook");
140 if (xpt_bus_register(sim, primary) != CAM_SUCCESS) {
141 cam_sim_free(sim, TRUE);
142 CAMLOCK_2_ISPLOCK(isp);
146 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
147 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
148 xpt_bus_deregister(cam_sim_path(sim));
149 cam_sim_free(sim, TRUE);
150 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
151 CAMLOCK_2_ISPLOCK(isp);
155 xpt_setup_ccb(&csa.ccb_h, path, 5);
156 csa.ccb_h.func_code = XPT_SASYNC_CB;
157 csa.event_enable = AC_LOST_DEVICE;
158 csa.callback = isp_cam_async;
159 csa.callback_arg = sim;
160 xpt_action((union ccb *)&csa);
161 CAMLOCK_2_ISPLOCK(isp);
163 isp->isp_path = path;
165 * Create a kernel thread for fibre channel instances. We
166 * don't have dual channel FC cards.
169 ISPLOCK_2_CAMLOCK(isp);
170 #if __FreeBSD_version >= 500000
171 /* XXX: LOCK VIOLATION */
172 cv_init(&isp->isp_osinfo.kthread_cv, "isp_kthread_cv");
173 if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kproc,
174 RFHIGHPID, 0, "%s: fc_thrd",
175 device_get_nameunit(isp->isp_dev)))
177 if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kproc,
178 "%s: fc_thrd", device_get_nameunit(isp->isp_dev)))
181 xpt_bus_deregister(cam_sim_path(sim));
182 cam_sim_free(sim, TRUE);
183 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
184 CAMLOCK_2_ISPLOCK(isp);
185 isp_prt(isp, ISP_LOGERR, "could not create kthread");
188 CAMLOCK_2_ISPLOCK(isp);
193 * If we have a second channel, construct SIM entry for that.
195 if (IS_DUALBUS(isp)) {
196 ISPLOCK_2_CAMLOCK(isp);
197 sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
198 device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq);
200 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
201 xpt_free_path(isp->isp_path);
203 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
206 if (xpt_bus_register(sim, secondary) != CAM_SUCCESS) {
207 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
208 xpt_free_path(isp->isp_path);
209 cam_sim_free(sim, TRUE);
210 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
211 CAMLOCK_2_ISPLOCK(isp);
215 if (xpt_create_path(&path, NULL, cam_sim_path(sim),
216 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
217 xpt_bus_deregister(cam_sim_path(isp->isp_sim));
218 xpt_free_path(isp->isp_path);
219 xpt_bus_deregister(cam_sim_path(sim));
220 cam_sim_free(sim, TRUE);
221 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
222 CAMLOCK_2_ISPLOCK(isp);
226 xpt_setup_ccb(&csa.ccb_h, path, 5);
227 csa.ccb_h.func_code = XPT_SASYNC_CB;
228 csa.event_enable = AC_LOST_DEVICE;
229 csa.callback = isp_cam_async;
230 csa.callback_arg = sim;
231 xpt_action((union ccb *)&csa);
232 CAMLOCK_2_ISPLOCK(isp);
234 isp->isp_path2 = path;
238 * Create device nodes
240 (void) make_dev(&isp_cdevsw, device_get_unit(isp->isp_dev), UID_ROOT,
241 GID_OPERATOR, 0600, "%s", device_get_nameunit(isp->isp_dev));
243 if (isp->isp_role != ISP_ROLE_NONE) {
244 isp->isp_state = ISP_RUNSTATE;
247 if (isplist == NULL) {
250 ispsoftc_t *tmp = isplist;
251 while (tmp->isp_osinfo.next) {
252 tmp = tmp->isp_osinfo.next;
254 tmp->isp_osinfo.next = isp;
256 isp_sysctl_update(isp);
260 isp_freeze_loopdown(ispsoftc_t *isp, char *msg)
262 if (isp->isp_osinfo.simqfrozen == 0) {
263 isp_prt(isp, ISP_LOGDEBUG0, "%s: freeze simq (loopdown)", msg);
264 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
265 ISPLOCK_2_CAMLOCK(isp);
266 xpt_freeze_simq(isp->isp_sim, 1);
267 CAMLOCK_2_ISPLOCK(isp);
269 isp_prt(isp, ISP_LOGDEBUG0, "%s: mark frozen (loopdown)", msg);
270 isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN;
275 #if __FreeBSD_version < 500000
277 #define _IOP struct proc
279 #define _IOP struct thread
280 #define _DEV struct cdev *
284 ispioctl(_DEV dev, u_long c, caddr_t addr, int flags, _IOP *td)
287 int nr, retval = ENOTTY;
291 if (minor(dev) == device_get_unit(isp->isp_dev)) {
294 isp = isp->isp_osinfo.next;
300 #ifdef ISP_FW_CRASH_DUMP
301 case ISP_GET_FW_CRASH_DUMP:
303 uint16_t *ptr = FCPARAM(isp)->isp_dump_data;
308 sz = QLA2200_RISC_IMAGE_DUMP_SIZE;
310 sz = QLA2300_RISC_IMAGE_DUMP_SIZE;
314 void *uaddr = *((void **) addr);
315 if (copyout(ptr, uaddr, sz)) {
326 case ISP_FORCE_CRASH_DUMP:
329 isp_freeze_loopdown(isp,
330 "ispioctl(ISP_FORCE_CRASH_DUMP)");
340 int olddblev = isp->isp_dblev;
341 isp->isp_dblev = *(int *)addr;
342 *(int *)addr = olddblev;
347 *(int *)addr = isp->isp_role;
352 if (nr & ~(ISP_ROLE_INITIATOR|ISP_ROLE_TARGET)) {
356 *(int *)addr = isp->isp_role;
368 if (isp_fc_runstate(isp, 5 * 1000000)) {
379 if (isp_control(isp, ISPCTL_SEND_LIP, 0)) {
387 case ISP_FC_GETDINFO:
389 struct isp_fc_device *ifc = (struct isp_fc_device *) addr;
395 if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) {
400 lp = &FCPARAM(isp)->portdb[ifc->loopid];
402 ifc->role = lp->roles;
403 ifc->loopid = lp->loopid;
404 ifc->portid = lp->portid;
405 ifc->node_wwn = lp->node_wwn;
406 ifc->port_wwn = lp->port_wwn;
416 isp_stats_t *sp = (isp_stats_t *) addr;
418 MEMZERO(sp, sizeof (*sp));
419 sp->isp_stat_version = ISP_STATS_VERSION;
420 sp->isp_type = isp->isp_type;
421 sp->isp_revision = isp->isp_revision;
423 sp->isp_stats[ISP_INTCNT] = isp->isp_intcnt;
424 sp->isp_stats[ISP_INTBOGUS] = isp->isp_intbogus;
425 sp->isp_stats[ISP_INTMBOXC] = isp->isp_intmboxc;
426 sp->isp_stats[ISP_INGOASYNC] = isp->isp_intoasync;
427 sp->isp_stats[ISP_RSLTCCMPLT] = isp->isp_rsltccmplt;
428 sp->isp_stats[ISP_FPHCCMCPLT] = isp->isp_fphccmplt;
429 sp->isp_stats[ISP_RSCCHIWAT] = isp->isp_rscchiwater;
430 sp->isp_stats[ISP_FPCCHIWAT] = isp->isp_fpcchiwater;
438 isp->isp_intbogus = 0;
439 isp->isp_intmboxc = 0;
440 isp->isp_intoasync = 0;
441 isp->isp_rsltccmplt = 0;
442 isp->isp_fphccmplt = 0;
443 isp->isp_rscchiwater = 0;
444 isp->isp_fpcchiwater = 0;
448 case ISP_FC_GETHINFO:
450 struct isp_hba_device *hba = (struct isp_hba_device *) addr;
451 MEMZERO(hba, sizeof (*hba));
453 hba->fc_fw_major = ISP_FW_MAJORX(isp->isp_fwrev);
454 hba->fc_fw_minor = ISP_FW_MINORX(isp->isp_fwrev);
455 hba->fc_fw_micro = ISP_FW_MICROX(isp->isp_fwrev);
457 hba->fc_speed = FCPARAM(isp)->isp_gbspeed;
458 hba->fc_scsi_supported = 1;
459 hba->fc_topology = FCPARAM(isp)->isp_topo + 1;
460 hba->fc_loopid = FCPARAM(isp)->isp_loopid;
461 hba->nvram_node_wwn = FCPARAM(isp)->isp_nodewwn;
462 hba->nvram_port_wwn = FCPARAM(isp)->isp_portwwn;
463 hba->active_node_wwn = ISP_NODEWWN(isp);
464 hba->active_port_wwn = ISP_PORTWWN(isp);
469 case ISP_GET_FC_PARAM:
471 struct isp_fc_param *f = (struct isp_fc_param *) addr;
477 if (strcmp(f->param_name, "framelength") == 0) {
478 f->parameter = FCPARAM(isp)->isp_maxfrmlen;
482 if (strcmp(f->param_name, "exec_throttle") == 0) {
483 f->parameter = FCPARAM(isp)->isp_execthrottle;
487 if (strcmp(f->param_name, "fullduplex") == 0) {
488 if (FCPARAM(isp)->isp_fwoptions & ICBOPT_FULL_DUPLEX)
493 if (strcmp(f->param_name, "loopid") == 0) {
494 f->parameter = FCPARAM(isp)->isp_loopid;
501 case ISP_SET_FC_PARAM:
503 struct isp_fc_param *f = (struct isp_fc_param *) addr;
504 uint32_t param = f->parameter;
510 if (strcmp(f->param_name, "framelength") == 0) {
511 if (param != 512 && param != 1024 && param != 1024) {
515 FCPARAM(isp)->isp_maxfrmlen = param;
519 if (strcmp(f->param_name, "exec_throttle") == 0) {
520 if (param < 16 || param > 255) {
524 FCPARAM(isp)->isp_execthrottle = param;
528 if (strcmp(f->param_name, "fullduplex") == 0) {
529 if (param != 0 && param != 1) {
534 FCPARAM(isp)->isp_fwoptions |=
537 FCPARAM(isp)->isp_fwoptions &=
543 if (strcmp(f->param_name, "loopid") == 0) {
544 if (param < 0 || param > 125) {
548 FCPARAM(isp)->isp_loopid = param;
558 struct isp_fc_tsk_mgmt *fct = (struct isp_fc_tsk_mgmt *) addr;
566 memset(&mbs, 0, sizeof (mbs));
567 needmarker = retval = 0;
568 loopid = fct->loopid;
569 if (IS_2KLOGIN(isp) == 0) {
572 switch (fct->action) {
574 mbs.param[0] = MBOX_CLEAR_ACA;
575 mbs.param[1] = loopid;
576 mbs.param[2] = fct->lun;
578 case IPT_TARGET_RESET:
579 mbs.param[0] = MBOX_TARGET_RESET;
580 mbs.param[1] = loopid;
584 mbs.param[0] = MBOX_LUN_RESET;
585 mbs.param[1] = loopid;
586 mbs.param[2] = fct->lun;
589 case IPT_CLEAR_TASK_SET:
590 mbs.param[0] = MBOX_CLEAR_TASK_SET;
591 mbs.param[1] = loopid;
592 mbs.param[2] = fct->lun;
595 case IPT_ABORT_TASK_SET:
596 mbs.param[0] = MBOX_ABORT_TASK_SET;
597 mbs.param[1] = loopid;
598 mbs.param[2] = fct->lun;
608 isp->isp_sendmarker |= 1;
610 retval = isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
623 #if __FreeBSD_version >= 500000
625 isp_sysctl_update(ispsoftc_t *isp)
627 struct sysctl_ctx_list *ctx =
628 device_get_sysctl_ctx(isp->isp_osinfo.dev);
629 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
632 isp->isp_osinfo.sysctl_info.spi.iid = DEFAULT_IID(isp);
633 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "iid",
634 CTLFLAG_RD, &isp->isp_osinfo.sysctl_info.spi.iid, 0,
638 snprintf(isp->isp_osinfo.sysctl_info.fc.wwnn,
639 sizeof (isp->isp_osinfo.sysctl_info.fc.wwnn), "0x%08x%08x",
640 (uint32_t) (ISP_NODEWWN(isp) >> 32), (uint32_t) ISP_NODEWWN(isp));
642 snprintf(isp->isp_osinfo.sysctl_info.fc.wwpn,
643 sizeof (isp->isp_osinfo.sysctl_info.fc.wwpn), "0x%08x%08x",
644 (uint32_t) (ISP_PORTWWN(isp) >> 32), (uint32_t) ISP_PORTWWN(isp));
646 SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
647 "wwnn", CTLFLAG_RD, isp->isp_osinfo.sysctl_info.fc.wwnn, 0,
648 "World Wide Node Name");
649 SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
650 "wwpn", CTLFLAG_RD, isp->isp_osinfo.sysctl_info.fc.wwpn, 0,
651 "World Wide Port Name");
656 isp_intr_enable(void *arg)
658 ispsoftc_t *isp = arg;
659 if (isp->isp_role != ISP_ROLE_NONE) {
662 isp->isp_osinfo.intsok = 1;
665 /* Release our hook so that the boot can continue. */
666 config_intrhook_disestablish(&isp->isp_osinfo.ehook);
670 * Put the target mode functions here, because some are inlines
673 #ifdef ISP_TARGET_MODE
675 static __inline int is_lun_enabled(ispsoftc_t *, int, lun_id_t);
676 static __inline int are_any_luns_enabled(ispsoftc_t *, int);
677 static __inline tstate_t *get_lun_statep(ispsoftc_t *, int, lun_id_t);
678 static __inline void rls_lun_statep(ispsoftc_t *, tstate_t *);
679 static __inline atio_private_data_t *isp_get_atpd(ispsoftc_t *, int);
681 create_lun_state(ispsoftc_t *, int, struct cam_path *, tstate_t **);
682 static void destroy_lun_state(ispsoftc_t *, tstate_t *);
683 static int isp_en_lun(ispsoftc_t *, union ccb *);
684 static void isp_ledone(ispsoftc_t *, lun_entry_t *);
685 static cam_status isp_abort_tgt_ccb(ispsoftc_t *, union ccb *);
686 static timeout_t isp_refire_putback_atio;
687 static void isp_complete_ctio(union ccb *);
688 static void isp_target_putback_atio(union ccb *);
689 static void isp_target_start_ctio(ispsoftc_t *, union ccb *);
690 static int isp_handle_platform_atio(ispsoftc_t *, at_entry_t *);
691 static int isp_handle_platform_atio2(ispsoftc_t *, at2_entry_t *);
692 static int isp_handle_platform_ctio(ispsoftc_t *, void *);
693 static int isp_handle_platform_notify_scsi(ispsoftc_t *, in_entry_t *);
694 static int isp_handle_platform_notify_fc(ispsoftc_t *, in_fcentry_t *);
697 is_lun_enabled(ispsoftc_t *isp, int bus, lun_id_t lun)
700 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
705 if (tptr->lun == (lun_id_t) lun && tptr->bus == bus) {
708 } while ((tptr = tptr->next) != NULL);
713 are_any_luns_enabled(ispsoftc_t *isp, int port)
716 if (IS_DUALBUS(isp)) {
717 lo = (port * (LUN_HASH_SIZE >> 1));
718 hi = lo + (LUN_HASH_SIZE >> 1);
723 for (lo = 0; lo < hi; lo++) {
724 if (isp->isp_osinfo.lun_hash[lo]) {
731 static __inline tstate_t *
732 get_lun_statep(ispsoftc_t *isp, int bus, lun_id_t lun)
734 tstate_t *tptr = NULL;
736 if (lun == CAM_LUN_WILDCARD) {
737 if (isp->isp_osinfo.tmflags[bus] & TM_WILDCARD_ENABLED) {
738 tptr = &isp->isp_osinfo.tsdflt[bus];
744 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)];
751 if (tptr->lun == lun && tptr->bus == bus) {
755 } while ((tptr = tptr->next) != NULL);
760 rls_lun_statep(ispsoftc_t *isp, tstate_t *tptr)
766 static __inline atio_private_data_t *
767 isp_get_atpd(ispsoftc_t *isp, int tag)
769 atio_private_data_t *atp;
770 for (atp = isp->isp_osinfo.atpdp;
771 atp < &isp->isp_osinfo.atpdp[ATPDPSIZE]; atp++) {
779 create_lun_state(ispsoftc_t *isp, int bus,
780 struct cam_path *path, tstate_t **rslt)
785 tstate_t *tptr, *new;
787 lun = xpt_path_lun_id(path);
789 return (CAM_LUN_INVALID);
791 if (is_lun_enabled(isp, bus, lun)) {
792 return (CAM_LUN_ALRDY_ENA);
794 new = (tstate_t *) malloc(sizeof (tstate_t), M_DEVBUF, M_NOWAIT|M_ZERO);
796 return (CAM_RESRC_UNAVAIL);
799 status = xpt_create_path(&new->owner, NULL, xpt_path_path_id(path),
800 xpt_path_target_id(path), xpt_path_lun_id(path));
801 if (status != CAM_REQ_CMP) {
807 SLIST_INIT(&new->atios);
808 SLIST_INIT(&new->inots);
811 hfx = LUN_HASH_FUNC(isp, new->bus, new->lun);
812 tptr = isp->isp_osinfo.lun_hash[hfx];
814 isp->isp_osinfo.lun_hash[hfx] = new;
821 return (CAM_REQ_CMP);
825 destroy_lun_state(ispsoftc_t *isp, tstate_t *tptr)
833 hfx = LUN_HASH_FUNC(isp, tptr->bus, tptr->lun);
834 pw = isp->isp_osinfo.lun_hash[hfx];
837 } else if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
838 isp->isp_osinfo.lun_hash[hfx] = pw->next;
843 if (pw->lun == tptr->lun && pw->bus == tptr->bus) {
854 free(tptr, M_DEVBUF);
861 isp_en_lun(ispsoftc_t *isp, union ccb *ccb)
863 struct ccb_en_lun *cel = &ccb->cel;
866 int bus, cmd, av, wildcard, tm_on;
870 bus = XS_CHANNEL(ccb);
872 xpt_print_path(ccb->ccb_h.path);
873 printf("illegal bus %d\n", bus);
874 ccb->ccb_h.status = CAM_PATH_INVALID;
877 tgt = ccb->ccb_h.target_id;
878 lun = ccb->ccb_h.target_lun;
880 isp_prt(isp, ISP_LOGTDEBUG0,
881 "isp_en_lun: %sabling lun 0x%x on channel %d",
882 cel->enable? "en" : "dis", lun, bus);
885 if ((lun != CAM_LUN_WILDCARD) &&
886 (lun < 0 || lun >= (lun_id_t) isp->isp_maxluns)) {
887 ccb->ccb_h.status = CAM_LUN_INVALID;
892 sdparam *sdp = isp->isp_param;
894 if (tgt != CAM_TARGET_WILDCARD &&
895 tgt != sdp->isp_initiator_id) {
896 ccb->ccb_h.status = CAM_TID_INVALID;
901 * There's really no point in doing this yet w/o multi-tid
902 * capability. Even then, it's problematic.
905 if (tgt != CAM_TARGET_WILDCARD &&
906 tgt != FCPARAM(isp)->isp_iid) {
907 ccb->ccb_h.status = CAM_TID_INVALID;
912 * This is as a good a place as any to check f/w capabilities.
914 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_TMODE) == 0) {
915 isp_prt(isp, ISP_LOGERR,
916 "firmware does not support target mode");
917 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
921 * XXX: We *could* handle non-SCCLUN f/w, but we'd have to
922 * XXX: dorks with our already fragile enable/disable code.
924 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
925 isp_prt(isp, ISP_LOGERR,
926 "firmware not SCCLUN capable");
927 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
932 if (tgt == CAM_TARGET_WILDCARD) {
933 if (lun == CAM_LUN_WILDCARD) {
936 ccb->ccb_h.status = CAM_LUN_INVALID;
943 tm_on = (isp->isp_osinfo.tmflags[bus] & TM_TMODE_ENABLED) != 0;
946 * Next check to see whether this is a target/lun wildcard action.
948 * If so, we know that we can accept commands for luns that haven't
949 * been enabled yet and send them upstream. Otherwise, we have to
950 * handle them locally (if we see them at all).
954 tptr = &isp->isp_osinfo.tsdflt[bus];
957 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
961 xpt_create_path(&tptr->owner, NULL,
962 xpt_path_path_id(ccb->ccb_h.path),
963 xpt_path_target_id(ccb->ccb_h.path),
964 xpt_path_lun_id(ccb->ccb_h.path));
965 if (ccb->ccb_h.status != CAM_REQ_CMP) {
968 SLIST_INIT(&tptr->atios);
969 SLIST_INIT(&tptr->inots);
970 isp->isp_osinfo.tmflags[bus] |= TM_WILDCARD_ENABLED;
973 ccb->ccb_h.status = CAM_REQ_CMP;
977 ccb->ccb_h.status = CAM_SCSI_BUSY;
980 xpt_free_path(tptr->owner);
981 isp->isp_osinfo.tmflags[bus] &= ~TM_WILDCARD_ENABLED;
986 * Now check to see whether this bus needs to be
987 * enabled/disabled with respect to target mode.
990 if (cel->enable && tm_on == 0) {
991 av |= ENABLE_TARGET_FLAG;
992 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
994 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
996 isp->isp_osinfo.tmflags[bus] &=
997 ~TM_WILDCARD_ENABLED;
998 xpt_free_path(tptr->owner);
1002 isp->isp_osinfo.tmflags[bus] |= TM_TMODE_ENABLED;
1003 isp_prt(isp, ISP_LOGINFO,
1004 "Target Mode enabled on channel %d", bus);
1005 } else if (cel->enable == 0 && tm_on && wildcard) {
1006 if (are_any_luns_enabled(isp, bus)) {
1007 ccb->ccb_h.status = CAM_SCSI_BUSY;
1010 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
1012 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
1015 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
1016 isp_prt(isp, ISP_LOGINFO,
1017 "Target Mode disabled on channel %d", bus);
1021 ccb->ccb_h.status = CAM_REQ_CMP;
1026 * Find an empty slot
1028 for (seq = 0; seq < NLEACT; seq++) {
1029 if (isp->isp_osinfo.leact[seq] == 0) {
1033 if (seq >= NLEACT) {
1034 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1038 isp->isp_osinfo.leact[seq] = ccb;
1042 create_lun_state(isp, bus, ccb->ccb_h.path, &tptr);
1043 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1044 isp->isp_osinfo.leact[seq] = 0;
1048 tptr = get_lun_statep(isp, bus, lun);
1050 ccb->ccb_h.status = CAM_LUN_INVALID;
1056 int c, n, ulun = lun;
1058 cmd = RQSTYPE_ENABLE_LUN;
1061 if (IS_FC(isp) && lun != 0) {
1062 cmd = RQSTYPE_MODIFY_LUN;
1065 * For SCC firmware, we only deal with setting
1066 * (enabling or modifying) lun 0.
1070 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq+1) == 0) {
1071 rls_lun_statep(isp, tptr);
1072 ccb->ccb_h.status = CAM_REQ_INPROG;
1076 int c, n, ulun = lun;
1078 cmd = -RQSTYPE_MODIFY_LUN;
1081 if (IS_FC(isp) && lun != 0) {
1084 * For SCC firmware, we only deal with setting
1085 * (enabling or modifying) lun 0.
1089 if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq+1) == 0) {
1090 rls_lun_statep(isp, tptr);
1091 ccb->ccb_h.status = CAM_REQ_INPROG;
1095 rls_lun_statep(isp, tptr);
1096 xpt_print_path(ccb->ccb_h.path);
1097 printf("isp_lun_cmd failed\n");
1098 isp->isp_osinfo.leact[seq] = 0;
1099 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1104 isp_ledone(ispsoftc_t *isp, lun_entry_t *lep)
1106 const char lfmt[] = "lun %d now %sabled for target mode on channel %d";
1111 struct ccb_en_lun *cel;
1113 seq = lep->le_reserved - 1;
1114 if (seq >= NLEACT) {
1115 isp_prt(isp, ISP_LOGERR,
1116 "seq out of range (%u) in isp_ledone", seq);
1119 ccb = isp->isp_osinfo.leact[seq];
1121 isp_prt(isp, ISP_LOGERR,
1122 "no ccb for seq %u in isp_ledone", seq);
1126 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), XS_LUN(ccb));
1128 xpt_print_path(ccb->ccb_h.path);
1129 printf("null tptr in isp_ledone\n");
1130 isp->isp_osinfo.leact[seq] = 0;
1134 if (lep->le_status != LUN_OK) {
1135 xpt_print_path(ccb->ccb_h.path);
1136 printf("ENABLE/MODIFY LUN returned 0x%x\n", lep->le_status);
1138 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1139 xpt_print_path(ccb->ccb_h.path);
1140 rls_lun_statep(isp, tptr);
1141 isp->isp_osinfo.leact[seq] = 0;
1142 ISPLOCK_2_CAMLOCK(isp);
1144 CAMLOCK_2_ISPLOCK(isp);
1147 isp_prt(isp, ISP_LOGTDEBUG0,
1148 "isp_ledone: ENABLE/MODIFY done okay");
1153 ccb->ccb_h.status = CAM_REQ_CMP;
1154 isp_prt(isp, ISP_LOGINFO, lfmt,
1155 XS_LUN(ccb), "en", XS_CHANNEL(ccb));
1156 rls_lun_statep(isp, tptr);
1157 isp->isp_osinfo.leact[seq] = 0;
1158 ISPLOCK_2_CAMLOCK(isp);
1160 CAMLOCK_2_ISPLOCK(isp);
1164 if (lep->le_header.rqs_entry_type == RQSTYPE_MODIFY_LUN) {
1165 if (isp_lun_cmd(isp, -RQSTYPE_ENABLE_LUN, XS_CHANNEL(ccb),
1166 XS_TGT(ccb), XS_LUN(ccb), 0, 0, seq+1)) {
1167 xpt_print_path(ccb->ccb_h.path);
1168 printf("isp_ledone: isp_lun_cmd failed\n");
1171 rls_lun_statep(isp, tptr);
1175 isp_prt(isp, ISP_LOGINFO, lfmt, XS_LUN(ccb), "dis", XS_CHANNEL(ccb));
1176 rls_lun_statep(isp, tptr);
1177 destroy_lun_state(isp, tptr);
1178 ccb->ccb_h.status = CAM_REQ_CMP;
1179 isp->isp_osinfo.leact[seq] = 0;
1180 ISPLOCK_2_CAMLOCK(isp);
1182 CAMLOCK_2_ISPLOCK(isp);
1183 if (are_any_luns_enabled(isp, XS_CHANNEL(ccb)) == 0) {
1184 int bus = XS_CHANNEL(ccb);
1186 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av);
1188 isp_prt(isp, ISP_LOGWARN,
1189 "disable target mode on channel %d failed", bus);
1191 isp_prt(isp, ISP_LOGINFO,
1192 "Target Mode disabled on channel %d", bus);
1194 isp->isp_osinfo.tmflags[bus] &= ~TM_TMODE_ENABLED;
1200 isp_abort_tgt_ccb(ispsoftc_t *isp, union ccb *ccb)
1203 struct ccb_hdr_slist *lp;
1204 struct ccb_hdr *curelm;
1206 union ccb *accb = ccb->cab.abort_ccb;
1208 isp_prt(isp, ISP_LOGTDEBUG0, "aborting ccb %p", accb);
1209 if (accb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
1211 if (IS_FC(isp) && (accb->ccb_h.target_id !=
1212 ((fcparam *) isp->isp_param)->isp_loopid)) {
1214 } else if (IS_SCSI(isp) && (accb->ccb_h.target_id !=
1215 ((sdparam *) isp->isp_param)->isp_initiator_id)) {
1220 * Being restrictive about target ids is really about
1221 * making sure we're aborting for the right multi-tid
1222 * path. This doesn't really make much sense at present.
1225 return (CAM_PATH_INVALID);
1229 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), accb->ccb_h.target_lun);
1231 isp_prt(isp, ISP_LOGTDEBUG0,
1232 "isp_abort_tgt_ccb: can't get statep");
1233 return (CAM_PATH_INVALID);
1235 if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
1237 ctr = &tptr->atio_count;
1238 } else if (accb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
1240 ctr = &tptr->inot_count;
1242 rls_lun_statep(isp, tptr);
1243 isp_prt(isp, ISP_LOGTDEBUG0,
1244 "isp_abort_tgt_ccb: bad func %d\n", accb->ccb_h.func_code);
1245 return (CAM_UA_ABORT);
1247 curelm = SLIST_FIRST(lp);
1249 if (curelm == &accb->ccb_h) {
1251 SLIST_REMOVE_HEAD(lp, sim_links.sle);
1253 while(curelm != NULL) {
1254 struct ccb_hdr *nextelm;
1256 nextelm = SLIST_NEXT(curelm, sim_links.sle);
1257 if (nextelm == &accb->ccb_h) {
1259 SLIST_NEXT(curelm, sim_links.sle) =
1260 SLIST_NEXT(nextelm, sim_links.sle);
1266 rls_lun_statep(isp, tptr);
1269 accb->ccb_h.status = CAM_REQ_ABORTED;
1271 return (CAM_REQ_CMP);
1273 isp_prt(isp, ISP_LOGTDEBUG0,
1274 "isp_abort_tgt_ccb: CCB %p not found\n", ccb);
1275 return (CAM_PATH_INVALID);
1279 isp_target_start_ctio(ispsoftc_t *isp, union ccb *ccb)
1282 struct ccb_scsiio *cso = &ccb->csio;
1283 uint16_t *hp, save_handle;
1284 uint16_t nxti, optr;
1285 uint8_t local[QENTRY_LEN];
1288 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1289 xpt_print_path(ccb->ccb_h.path);
1290 printf("Request Queue Overflow in isp_target_start_ctio\n");
1291 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1294 memset(local, 0, QENTRY_LEN);
1297 * We're either moving data or completing a command here.
1301 atio_private_data_t *atp;
1302 ct2_entry_t *cto = (ct2_entry_t *) local;
1304 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1305 cto->ct_header.rqs_entry_count = 1;
1306 if (IS_2KLOGIN(isp)) {
1307 ((ct2e_entry_t *)cto)->ct_iid = cso->init_id;
1309 cto->ct_iid = cso->init_id;
1310 if (!(FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)) {
1311 cto->ct_lun = ccb->ccb_h.target_lun;
1315 atp = isp_get_atpd(isp, cso->tag_id);
1317 isp_prt(isp, ISP_LOGERR,
1318 "cannot find private data adjunct for tag %x",
1320 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
1324 cto->ct_rxid = cso->tag_id;
1325 if (cso->dxfer_len == 0) {
1326 cto->ct_flags |= CT2_FLAG_MODE1 | CT2_NO_DATA;
1327 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1328 cto->ct_flags |= CT2_SENDSTATUS;
1329 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1331 atp->orig_datalen - atp->bytes_xfered;
1332 if (cto->ct_resid < 0) {
1333 cto->rsp.m1.ct_scsi_status |=
1335 } else if (cto->ct_resid > 0) {
1336 cto->rsp.m1.ct_scsi_status |=
1340 if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) {
1341 int m = min(cso->sense_len, MAXRESPLEN);
1342 memcpy(cto->rsp.m1.ct_resp,
1343 &cso->sense_data, m);
1344 cto->rsp.m1.ct_senselen = m;
1345 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1348 cto->ct_flags |= CT2_FLAG_MODE0;
1349 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1350 cto->ct_flags |= CT2_DATA_IN;
1352 cto->ct_flags |= CT2_DATA_OUT;
1354 cto->ct_reloff = atp->bytes_xfered;
1355 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
1356 cto->ct_flags |= CT2_SENDSTATUS;
1357 cto->rsp.m0.ct_scsi_status = cso->scsi_status;
1360 (atp->bytes_xfered + cso->dxfer_len);
1361 if (cto->ct_resid < 0) {
1362 cto->rsp.m0.ct_scsi_status |=
1364 } else if (cto->ct_resid > 0) {
1365 cto->rsp.m0.ct_scsi_status |=
1369 atp->last_xframt = cso->dxfer_len;
1372 * If we're sending data and status back together,
1373 * we can't also send back sense data as well.
1375 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1378 if (cto->ct_flags & CT2_SENDSTATUS) {
1379 isp_prt(isp, ISP_LOGTDEBUG0,
1380 "CTIO2[%x] STATUS %x origd %u curd %u resid %u",
1381 cto->ct_rxid, cso->scsi_status, atp->orig_datalen,
1382 cso->dxfer_len, cto->ct_resid);
1383 cto->ct_flags |= CT2_CCINCR;
1384 atp->state = ATPD_STATE_LAST_CTIO;
1386 atp->state = ATPD_STATE_CTIO;
1388 cto->ct_timeout = 10;
1389 hp = &cto->ct_syshandle;
1391 ct_entry_t *cto = (ct_entry_t *) local;
1393 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
1394 cto->ct_header.rqs_entry_count = 1;
1395 cto->ct_iid = cso->init_id;
1396 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
1397 cto->ct_tgt = ccb->ccb_h.target_id;
1398 cto->ct_lun = ccb->ccb_h.target_lun;
1399 cto->ct_fwhandle = AT_GET_HANDLE(cso->tag_id);
1400 if (AT_HAS_TAG(cso->tag_id)) {
1401 cto->ct_tag_val = (uint8_t) AT_GET_TAG(cso->tag_id);
1402 cto->ct_flags |= CT_TQAE;
1404 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
1405 cto->ct_flags |= CT_NODISC;
1407 if (cso->dxfer_len == 0) {
1408 cto->ct_flags |= CT_NO_DATA;
1409 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1410 cto->ct_flags |= CT_DATA_IN;
1412 cto->ct_flags |= CT_DATA_OUT;
1414 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1415 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
1416 cto->ct_scsi_status = cso->scsi_status;
1417 cto->ct_resid = cso->resid;
1418 isp_prt(isp, ISP_LOGTDEBUG0,
1419 "CTIO[%x] SCSI STATUS 0x%x resid %d tag_id %x",
1420 cto->ct_fwhandle, cso->scsi_status, cso->resid,
1423 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1424 cto->ct_timeout = 10;
1425 hp = &cto->ct_syshandle;
1428 if (isp_save_xs_tgt(isp, ccb, hp)) {
1429 xpt_print_path(ccb->ccb_h.path);
1430 printf("No XFLIST pointers for isp_target_start_ctio\n");
1431 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1437 * Call the dma setup routines for this entry (and any subsequent
1438 * CTIOs) if there's data to move, and then tell the f/w it's got
1439 * new things to play with. As with isp_start's usage of DMA setup,
1440 * any swizzling is done in the machine dependent layer. Because
1441 * of this, we put the request onto the queue area first in native
1447 switch (ISP_DMASETUP(isp, cso, (ispreq_t *) local, &nxti, optr)) {
1449 ISP_ADD_REQUEST(isp, nxti);
1450 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1454 XS_SETERR(ccb, CAM_REQUEUE_REQ);
1460 isp_destroy_tgt_handle(isp, save_handle);
1463 ISPLOCK_2_CAMLOCK(isp);
1465 CAMLOCK_2_ISPLOCK(isp);
1469 isp_refire_putback_atio(void *arg)
1472 isp_target_putback_atio(arg);
1477 isp_target_putback_atio(union ccb *ccb)
1480 struct ccb_scsiio *cso;
1481 uint16_t nxti, optr;
1486 if (isp_getrqentry(isp, &nxti, &optr, &qe)) {
1487 (void) timeout(isp_refire_putback_atio, ccb, 10);
1488 isp_prt(isp, ISP_LOGWARN,
1489 "isp_target_putback_atio: Request Queue Overflow");
1492 memset(qe, 0, QENTRY_LEN);
1495 at2_entry_t local, *at = &local;
1496 MEMZERO(at, sizeof (at2_entry_t));
1497 at->at_header.rqs_entry_type = RQSTYPE_ATIO2;
1498 at->at_header.rqs_entry_count = 1;
1499 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) != 0) {
1500 at->at_scclun = (uint16_t) ccb->ccb_h.target_lun;
1502 at->at_lun = (uint8_t) ccb->ccb_h.target_lun;
1504 at->at_status = CT_OK;
1505 at->at_rxid = cso->tag_id;
1506 at->at_iid = cso->ccb_h.target_id;
1507 isp_put_atio2(isp, at, qe);
1509 at_entry_t local, *at = &local;
1510 MEMZERO(at, sizeof (at_entry_t));
1511 at->at_header.rqs_entry_type = RQSTYPE_ATIO;
1512 at->at_header.rqs_entry_count = 1;
1513 at->at_iid = cso->init_id;
1514 at->at_iid |= XS_CHANNEL(ccb) << 7;
1515 at->at_tgt = cso->ccb_h.target_id;
1516 at->at_lun = cso->ccb_h.target_lun;
1517 at->at_status = CT_OK;
1518 at->at_tag_val = AT_GET_TAG(cso->tag_id);
1519 at->at_handle = AT_GET_HANDLE(cso->tag_id);
1520 isp_put_atio(isp, at, qe);
1522 ISP_TDQE(isp, "isp_target_putback_atio", (int) optr, qe);
1523 ISP_ADD_REQUEST(isp, nxti);
1524 isp_complete_ctio(ccb);
1528 isp_complete_ctio(union ccb *ccb)
1530 ISPLOCK_2_CAMLOCK(isp);
1531 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1532 ccb->ccb_h.status |= CAM_REQ_CMP;
1534 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1536 CAMLOCK_2_ISPLOCK(isp);
1540 * Handle ATIO stuff that the generic code can't.
1541 * This means handling CDBs.
1545 isp_handle_platform_atio(ispsoftc_t *isp, at_entry_t *aep)
1548 int status, bus, iswildcard;
1549 struct ccb_accept_tio *atiop;
1552 * The firmware status (except for the QLTM_SVALID bit)
1553 * indicates why this ATIO was sent to us.
1555 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1557 * If the DISCONNECTS DISABLED bit is set in the flags field,
1558 * we're still connected on the SCSI bus.
1560 status = aep->at_status;
1561 if ((status & ~QLTM_SVALID) == AT_PHASE_ERROR) {
1563 * Bus Phase Sequence error. We should have sense data
1564 * suggested by the f/w. I'm not sure quite yet what
1565 * to do about this for CAM.
1567 isp_prt(isp, ISP_LOGWARN, "PHASE ERROR");
1568 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1571 if ((status & ~QLTM_SVALID) != AT_CDB) {
1572 isp_prt(isp, ISP_LOGWARN, "bad atio (0x%x) leaked to platform",
1574 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1578 bus = GET_BUS_VAL(aep->at_iid);
1579 tptr = get_lun_statep(isp, bus, aep->at_lun);
1581 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
1584 * Because we can't autofeed sense data back with
1585 * a command for parallel SCSI, we can't give back
1586 * a CHECK CONDITION. We'll give back a BUSY status
1587 * instead. This works out okay because the only
1588 * time we should, in fact, get this, is in the
1589 * case that somebody configured us without the
1590 * blackhole driver, so they get what they deserve.
1592 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1600 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1601 if (atiop == NULL) {
1603 * Because we can't autofeed sense data back with
1604 * a command for parallel SCSI, we can't give back
1605 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1606 * instead. This works out okay because the only time we
1607 * should, in fact, get this, is in the case that we've
1610 xpt_print_path(tptr->owner);
1611 isp_prt(isp, ISP_LOGWARN,
1612 "no ATIOS for lun %d from initiator %d on channel %d",
1613 aep->at_lun, GET_IID_VAL(aep->at_iid), bus);
1614 if (aep->at_flags & AT_TQAE)
1615 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1617 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1618 rls_lun_statep(isp, tptr);
1621 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1623 isp_prt(isp, ISP_LOGTDEBUG0, "Take FREE ATIO lun %d, count now %d",
1624 aep->at_lun, tptr->atio_count);
1626 atiop->ccb_h.target_id = aep->at_tgt;
1627 atiop->ccb_h.target_lun = aep->at_lun;
1629 if (aep->at_flags & AT_NODISC) {
1630 atiop->ccb_h.flags = CAM_DIS_DISCONNECT;
1632 atiop->ccb_h.flags = 0;
1635 if (status & QLTM_SVALID) {
1636 size_t amt = imin(QLTM_SENSELEN, sizeof (atiop->sense_data));
1637 atiop->sense_len = amt;
1638 MEMCPY(&atiop->sense_data, aep->at_sense, amt);
1640 atiop->sense_len = 0;
1643 atiop->init_id = GET_IID_VAL(aep->at_iid);
1644 atiop->cdb_len = aep->at_cdblen;
1645 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, aep->at_cdblen);
1646 atiop->ccb_h.status = CAM_CDB_RECVD;
1648 * Construct a tag 'id' based upon tag value (which may be 0..255)
1649 * and the handle (which we have to preserve).
1651 AT_MAKE_TAGID(atiop->tag_id, device_get_unit(isp->isp_dev), aep);
1652 if (aep->at_flags & AT_TQAE) {
1653 atiop->tag_action = aep->at_tag_type;
1654 atiop->ccb_h.status |= CAM_TAG_ACTION_VALID;
1656 xpt_done((union ccb*)atiop);
1657 isp_prt(isp, ISP_LOGTDEBUG0,
1658 "ATIO[%x] CDB=0x%x bus %d iid%d->lun%d tag 0x%x ttype 0x%x %s",
1659 aep->at_handle, aep->at_cdb[0] & 0xff, GET_BUS_VAL(aep->at_iid),
1660 GET_IID_VAL(aep->at_iid), aep->at_lun, aep->at_tag_val & 0xff,
1661 aep->at_tag_type, (aep->at_flags & AT_NODISC)?
1662 "nondisc" : "disconnecting");
1663 rls_lun_statep(isp, tptr);
1668 isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1672 struct ccb_accept_tio *atiop;
1673 atio_private_data_t *atp;
1676 * The firmware status (except for the QLTM_SVALID bit)
1677 * indicates why this ATIO was sent to us.
1679 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1681 if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) {
1682 isp_prt(isp, ISP_LOGWARN,
1683 "bogus atio (0x%x) leaked to platform", aep->at_status);
1684 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1688 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) != 0) {
1689 lun = aep->at_scclun;
1693 tptr = get_lun_statep(isp, 0, lun);
1695 isp_prt(isp, ISP_LOGTDEBUG0,
1696 "[0x%x] no state pointer for lun %d", aep->at_rxid, lun);
1697 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
1699 isp_endcmd(isp, aep,
1700 SCSI_STATUS_CHECK_COND | ECMD_SVALID |
1701 (0x5 << 12) | (0x25 << 16), 0);
1706 atp = isp_get_atpd(isp, 0);
1707 atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios);
1708 if (atiop == NULL || atp == NULL) {
1711 * Because we can't autofeed sense data back with
1712 * a command for parallel SCSI, we can't give back
1713 * a CHECK CONDITION. We'll give back a QUEUE FULL status
1714 * instead. This works out okay because the only time we
1715 * should, in fact, get this, is in the case that we've
1718 xpt_print_path(tptr->owner);
1719 isp_prt(isp, ISP_LOGWARN,
1720 "no %s for lun %d from initiator %d",
1721 (atp == NULL && atiop == NULL)? "ATIO2s *or* ATPS" :
1722 ((atp == NULL)? "ATPs" : "ATIO2s"), lun, aep->at_iid);
1723 rls_lun_statep(isp, tptr);
1724 isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0);
1727 atp->state = ATPD_STATE_ATIO;
1728 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1730 isp_prt(isp, ISP_LOGTDEBUG0, "Take FREE ATIO lun %d, count now %d",
1731 lun, tptr->atio_count);
1733 if (tptr == &isp->isp_osinfo.tsdflt[0]) {
1734 atiop->ccb_h.target_id =
1735 ((fcparam *)isp->isp_param)->isp_loopid;
1736 atiop->ccb_h.target_lun = lun;
1739 * We don't get 'suggested' sense data as we do with SCSI cards.
1741 atiop->sense_len = 0;
1743 atiop->init_id = aep->at_iid;
1744 atiop->cdb_len = ATIO2_CDBLEN;
1745 MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
1746 atiop->ccb_h.status = CAM_CDB_RECVD;
1747 atiop->tag_id = aep->at_rxid;
1748 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
1749 case ATIO2_TC_ATTR_SIMPLEQ:
1750 atiop->tag_action = MSG_SIMPLE_Q_TAG;
1752 case ATIO2_TC_ATTR_HEADOFQ:
1753 atiop->tag_action = MSG_HEAD_OF_Q_TAG;
1755 case ATIO2_TC_ATTR_ORDERED:
1756 atiop->tag_action = MSG_ORDERED_Q_TAG;
1758 case ATIO2_TC_ATTR_ACAQ: /* ?? */
1759 case ATIO2_TC_ATTR_UNTAGGED:
1761 atiop->tag_action = 0;
1764 atiop->ccb_h.flags = CAM_TAG_ACTION_VALID;
1766 atp->tag = atiop->tag_id;
1768 atp->orig_datalen = aep->at_datalen;
1769 atp->last_xframt = 0;
1770 atp->bytes_xfered = 0;
1771 atp->state = ATPD_STATE_CAM;
1772 ISPLOCK_2_CAMLOCK(siP);
1773 xpt_done((union ccb*)atiop);
1775 isp_prt(isp, ISP_LOGTDEBUG0,
1776 "ATIO2[%x] CDB=0x%x iid%d->lun%d tattr 0x%x datalen %u",
1777 aep->at_rxid, aep->at_cdb[0] & 0xff, aep->at_iid,
1778 lun, aep->at_taskflags, aep->at_datalen);
1779 rls_lun_statep(isp, tptr);
1784 isp_handle_platform_ctio(ispsoftc_t *isp, void *arg)
1787 int sentstatus, ok, notify_cam, resid = 0;
1791 * CTIO and CTIO2 are close enough....
1794 ccb = isp_find_xs_tgt(isp, ((ct_entry_t *)arg)->ct_syshandle);
1795 KASSERT((ccb != NULL), ("null ccb in isp_handle_platform_ctio"));
1796 isp_destroy_tgt_handle(isp, ((ct_entry_t *)arg)->ct_syshandle);
1799 ct2_entry_t *ct = arg;
1800 atio_private_data_t *atp = isp_get_atpd(isp, ct->ct_rxid);
1802 isp_prt(isp, ISP_LOGERR,
1803 "cannot find adjunct for %x after I/O",
1807 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
1808 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1809 if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
1810 ccb->ccb_h.status |= CAM_SENT_SENSE;
1812 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1813 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1814 resid = ct->ct_resid;
1815 atp->bytes_xfered += (atp->last_xframt - resid);
1816 atp->last_xframt = 0;
1818 if (sentstatus || !ok) {
1821 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN,
1822 "CTIO2[%x] sts 0x%x flg 0x%x sns %d resid %d %s",
1823 ct->ct_rxid, ct->ct_status, ct->ct_flags,
1824 (ccb->ccb_h.status & CAM_SENT_SENSE) != 0,
1825 resid, sentstatus? "FIN" : "MID");
1828 /* XXX: should really come after isp_complete_ctio */
1829 atp->state = ATPD_STATE_PDON;
1831 ct_entry_t *ct = arg;
1832 sentstatus = ct->ct_flags & CT_SENDSTATUS;
1833 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
1835 * We *ought* to be able to get back to the original ATIO
1836 * here, but for some reason this gets lost. It's just as
1837 * well because it's squirrelled away as part of periph
1840 * We can live without it as long as we continue to use
1841 * the auto-replenish feature for CTIOs.
1843 notify_cam = ct->ct_header.rqs_seqno & 0x1;
1844 if (ct->ct_status & QLTM_SVALID) {
1845 char *sp = (char *)ct;
1846 sp += CTIO_SENSE_OFFSET;
1847 ccb->csio.sense_len =
1848 min(sizeof (ccb->csio.sense_data), QLTM_SENSELEN);
1849 MEMCPY(&ccb->csio.sense_data, sp, ccb->csio.sense_len);
1850 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
1852 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1853 resid = ct->ct_resid;
1855 isp_prt(isp, ISP_LOGTDEBUG0,
1856 "CTIO[%x] tag %x iid %d lun %d sts %x flg %x resid %d %s",
1857 ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_lun,
1858 ct->ct_status, ct->ct_flags, resid,
1859 sentstatus? "FIN" : "MID");
1860 tval = ct->ct_fwhandle;
1862 ccb->csio.resid += resid;
1865 * We're here either because intermediate data transfers are done
1866 * and/or the final status CTIO (which may have joined with a
1867 * Data Transfer) is done.
1869 * In any case, for this platform, the upper layers figure out
1870 * what to do next, so all we do here is collect status and
1871 * pass information along. Any DMA handles have already been
1874 if (notify_cam == 0) {
1875 isp_prt(isp, ISP_LOGTDEBUG0, " INTER CTIO[0x%x] done", tval);
1879 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done",
1880 (sentstatus)? " FINAL " : "MIDTERM ", tval);
1883 isp_target_putback_atio(ccb);
1885 isp_complete_ctio(ccb);
1892 isp_handle_platform_notify_scsi(ispsoftc_t *isp, in_entry_t *inp)
1894 return (0); /* XXXX */
1898 isp_handle_platform_notify_fc(ispsoftc_t *isp, in_fcentry_t *inp)
1901 switch (inp->in_status) {
1902 case IN_PORT_LOGOUT:
1903 isp_prt(isp, ISP_LOGWARN, "port logout of iid %d",
1906 case IN_PORT_CHANGED:
1907 isp_prt(isp, ISP_LOGWARN, "port changed for iid %d",
1910 case IN_GLOBAL_LOGO:
1911 isp_prt(isp, ISP_LOGINFO, "all ports logged out");
1915 atio_private_data_t *atp = isp_get_atpd(isp, inp->in_seqid);
1916 struct ccb_immed_notify *inot = NULL;
1919 tstate_t *tptr = get_lun_statep(isp, 0, atp->lun);
1921 inot = (struct ccb_immed_notify *)
1922 SLIST_FIRST(&tptr->inots);
1925 SLIST_REMOVE_HEAD(&tptr->inots,
1927 isp_prt(isp, ISP_LOGTDEBUG0,
1928 "Take FREE INOT count now %d",
1932 isp_prt(isp, ISP_LOGWARN,
1933 "abort task RX_ID %x IID %d state %d",
1934 inp->in_seqid, inp->in_iid, atp->state);
1936 isp_prt(isp, ISP_LOGWARN,
1937 "abort task RX_ID %x from iid %d, state unknown",
1938 inp->in_seqid, inp->in_iid);
1941 inot->initiator_id = inp->in_iid;
1942 inot->sense_len = 0;
1943 inot->message_args[0] = MSG_ABORT_TAG;
1944 inot->message_args[1] = inp->in_seqid & 0xff;
1945 inot->message_args[2] = (inp->in_seqid >> 8) & 0xff;
1946 inot->ccb_h.status = CAM_MESSAGE_RECV;
1947 xpt_done((union ccb *)inot);
1959 isp_cam_async(void *cbarg, uint32_t code, struct cam_path *path, void *arg)
1961 struct cam_sim *sim;
1964 sim = (struct cam_sim *)cbarg;
1965 isp = (ispsoftc_t *) cam_sim_softc(sim);
1967 case AC_LOST_DEVICE:
1969 uint16_t oflags, nflags;
1970 sdparam *sdp = isp->isp_param;
1973 tgt = xpt_path_target_id(path);
1975 sdp += cam_sim_bus(sim);
1977 nflags = sdp->isp_devparam[tgt].nvrm_flags;
1978 #ifndef ISP_TARGET_MODE
1979 nflags &= DPARM_SAFE_DFLT;
1980 if (isp->isp_loaded_fw) {
1981 nflags |= DPARM_NARROW | DPARM_ASYNC;
1984 nflags = DPARM_DEFAULT;
1986 oflags = sdp->isp_devparam[tgt].goal_flags;
1987 sdp->isp_devparam[tgt].goal_flags = nflags;
1988 sdp->isp_devparam[tgt].dev_update = 1;
1989 isp->isp_update |= (1 << cam_sim_bus(sim));
1990 (void) isp_control(isp,
1991 ISPCTL_UPDATE_PARAMS, NULL);
1992 sdp->isp_devparam[tgt].goal_flags = oflags;
1998 isp_prt(isp, ISP_LOGWARN, "isp_cam_async: Code 0x%x", code);
2004 isp_poll(struct cam_sim *sim)
2006 ispsoftc_t *isp = cam_sim_softc(sim);
2007 uint16_t isr, sema, mbox;
2010 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2011 isp_intr(isp, isr, sema, mbox);
2018 isp_watchdog(void *arg)
2021 ispsoftc_t *isp = XS_ISP(xs);
2026 * We've decided this command is dead. Make sure we're not trying
2027 * to kill a command that's already dead by getting it's handle and
2028 * and seeing whether it's still alive.
2031 iok = isp->isp_osinfo.intsok;
2032 isp->isp_osinfo.intsok = 0;
2033 handle = isp_find_handle(isp, xs);
2035 uint16_t isr, sema, mbox;
2037 if (XS_CMD_DONE_P(xs)) {
2038 isp_prt(isp, ISP_LOGDEBUG1,
2039 "watchdog found done cmd (handle 0x%x)", handle);
2044 if (XS_CMD_WDOG_P(xs)) {
2045 isp_prt(isp, ISP_LOGDEBUG2,
2046 "recursive watchdog (handle 0x%x)", handle);
2052 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2053 isp_intr(isp, isr, sema, mbox);
2055 if (XS_CMD_DONE_P(xs)) {
2056 isp_prt(isp, ISP_LOGDEBUG2,
2057 "watchdog cleanup for handle 0x%x", handle);
2058 xpt_done((union ccb *) xs);
2059 } else if (XS_CMD_GRACE_P(xs)) {
2061 * Make sure the command is *really* dead before we
2062 * release the handle (and DMA resources) for reuse.
2064 (void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
2067 * After this point, the comamnd is really dead.
2069 if (XS_XFRLEN(xs)) {
2070 ISP_DMAFREE(isp, xs, handle);
2072 isp_destroy_handle(isp, handle);
2073 xpt_print_path(xs->ccb_h.path);
2074 isp_prt(isp, ISP_LOGWARN,
2075 "watchdog timeout for handle 0x%x", handle);
2076 XS_SETERR(xs, CAM_CMD_TIMEOUT);
2080 uint16_t nxti, optr;
2081 ispreq_t local, *mp= &local, *qe;
2084 xs->ccb_h.timeout_ch = timeout(isp_watchdog, xs, hz);
2085 if (isp_getrqentry(isp, &nxti, &optr, (void **) &qe)) {
2090 MEMZERO((void *) mp, sizeof (*mp));
2091 mp->req_header.rqs_entry_count = 1;
2092 mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
2093 mp->req_modifier = SYNC_ALL;
2094 mp->req_target = XS_CHANNEL(xs) << 7;
2095 isp_put_request(isp, mp, qe);
2096 ISP_ADD_REQUEST(isp, nxti);
2099 isp_prt(isp, ISP_LOGDEBUG2, "watchdog with no command");
2101 isp->isp_osinfo.intsok = iok;
2106 isp_kthread(void *arg)
2108 ispsoftc_t *isp = arg;
2111 #if __FreeBSD_version < 500000
2115 isp->isp_osinfo.intsok = 1;
2118 mtx_lock(&isp->isp_lock);
2124 * The first loop is for our usage where we have yet to have
2125 * gotten good fibre channel state.
2130 isp_prt(isp, ISP_LOGDEBUG0, "kthread: checking FC state");
2131 while (isp_fc_runstate(isp, 2 * 1000000) != 0) {
2132 isp_prt(isp, ISP_LOGDEBUG0, "kthread: FC state ungood");
2133 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2134 FCPARAM(isp)->isp_loopstate < LOOP_PDB_RCVD) {
2135 if (FCPARAM(isp)->loop_seen_once == 0 ||
2136 isp->isp_osinfo.ktmature == 0) {
2141 msleep(isp_kthread, &isp->isp_lock,
2142 PRIBIO, "isp_fcthrd", hz);
2144 (void) tsleep(isp_kthread, PRIBIO, "isp_fcthrd", hz);
2149 * Even if we didn't get good loop state we may be
2150 * unfreezing the SIMQ so that we can kill off
2151 * commands (if we've never seen loop before, for example).
2153 isp->isp_osinfo.ktmature = 1;
2154 wasfrozen = isp->isp_osinfo.simqfrozen & SIMQFRZ_LOOPDOWN;
2155 isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_LOOPDOWN;
2156 if (wasfrozen && isp->isp_osinfo.simqfrozen == 0) {
2157 isp_prt(isp, ISP_LOGDEBUG0, "kthread: releasing simq");
2158 ISPLOCK_2_CAMLOCK(isp);
2159 xpt_release_simq(isp->isp_sim, 1);
2160 CAMLOCK_2_ISPLOCK(isp);
2162 isp_prt(isp, ISP_LOGDEBUG0, "kthread: waiting until called");
2163 #if __FreeBSD_version < 500000
2164 tsleep(&isp->isp_osinfo.kproc, PRIBIO, "isp_fc_worker", 0);
2167 cv_wait(&isp->isp_osinfo.kthread_cv, &isp->isp_lock);
2169 (void) tsleep(&isp->isp_osinfo.kthread_cv, PRIBIO, "fc_cv", 0);
2176 isp_action(struct cam_sim *sim, union ccb *ccb)
2178 int bus, tgt, error;
2180 struct ccb_trans_settings *cts;
2182 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
2184 isp = (ispsoftc_t *)cam_sim_softc(sim);
2185 ccb->ccb_h.sim_priv.entries[0].field = 0;
2186 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
2187 if (isp->isp_state != ISP_RUNSTATE &&
2188 ccb->ccb_h.func_code == XPT_SCSI_IO) {
2189 CAMLOCK_2_ISPLOCK(isp);
2191 if (isp->isp_state != ISP_INITSTATE) {
2194 * Lie. Say it was a selection timeout.
2196 ccb->ccb_h.status = CAM_SEL_TIMEOUT | CAM_DEV_QFRZN;
2197 xpt_freeze_devq(ccb->ccb_h.path, 1);
2201 isp->isp_state = ISP_RUNSTATE;
2202 ISPLOCK_2_CAMLOCK(isp);
2204 isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
2207 switch (ccb->ccb_h.func_code) {
2208 case XPT_SCSI_IO: /* Execute the requested I/O operation */
2210 * Do a couple of preliminary checks...
2212 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
2213 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
2214 ccb->ccb_h.status = CAM_REQ_INVALID;
2220 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
2221 ccb->ccb_h.status = CAM_PATH_INVALID;
2222 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
2223 ccb->ccb_h.status = CAM_PATH_INVALID;
2225 if (ccb->ccb_h.status == CAM_PATH_INVALID) {
2226 isp_prt(isp, ISP_LOGERR,
2227 "invalid tgt/lun (%d.%d) in XPT_SCSI_IO",
2228 ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
2233 ((struct ccb_scsiio *) ccb)->scsi_status = SCSI_STATUS_OK;
2234 CAMLOCK_2_ISPLOCK(isp);
2235 error = isp_start((XS_T *) ccb);
2238 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2239 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
2240 uint64_t ticks = (uint64_t) hz;
2241 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT)
2242 ticks = 60 * 1000 * ticks;
2244 ticks = ccb->ccb_h.timeout * hz;
2245 ticks = ((ticks + 999) / 1000) + hz + hz;
2246 if (ticks >= 0x80000000) {
2247 isp_prt(isp, ISP_LOGERR,
2248 "timeout overflow");
2251 ccb->ccb_h.timeout_ch = timeout(isp_watchdog,
2252 (caddr_t)ccb, (int)ticks);
2254 callout_handle_init(&ccb->ccb_h.timeout_ch);
2256 ISPLOCK_2_CAMLOCK(isp);
2260 * This can only happen for Fibre Channel
2262 KASSERT((IS_FC(isp)), ("CMD_RQLATER for FC only"));
2263 if (FCPARAM(isp)->loop_seen_once == 0 &&
2264 isp->isp_osinfo.ktmature) {
2265 ISPLOCK_2_CAMLOCK(isp);
2266 XS_SETERR(ccb, CAM_SEL_TIMEOUT);
2270 #if __FreeBSD_version < 500000
2271 wakeup(&isp->isp_osinfo.kproc);
2274 cv_signal(&isp->isp_osinfo.kthread_cv);
2276 wakeup(&isp->isp_osinfo.kthread_cv);
2279 isp_freeze_loopdown(isp, "isp_action(RQLATER)");
2280 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2281 ISPLOCK_2_CAMLOCK(isp);
2285 XS_SETERR(ccb, CAM_REQUEUE_REQ);
2286 ISPLOCK_2_CAMLOCK(isp);
2290 isp_done((struct ccb_scsiio *) ccb);
2291 ISPLOCK_2_CAMLOCK(isp);
2294 isp_prt(isp, ISP_LOGERR,
2295 "What's this? 0x%x at %d in file %s",
2296 error, __LINE__, __FILE__);
2297 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
2299 ISPLOCK_2_CAMLOCK(isp);
2303 #ifdef ISP_TARGET_MODE
2304 case XPT_EN_LUN: /* Enable LUN as a target */
2307 CAMLOCK_2_ISPLOCK(isp);
2308 iok = isp->isp_osinfo.intsok;
2309 isp->isp_osinfo.intsok = 0;
2310 seq = isp_en_lun(isp, ccb);
2312 isp->isp_osinfo.intsok = iok;
2313 ISPLOCK_2_CAMLOCK(isp);
2317 for (i = 0; isp->isp_osinfo.leact[seq] && i < 30 * 1000; i++) {
2318 uint16_t isr, sema, mbox;
2319 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
2320 isp_intr(isp, isr, sema, mbox);
2324 isp->isp_osinfo.intsok = iok;
2325 ISPLOCK_2_CAMLOCK(isp);
2328 case XPT_NOTIFY_ACK: /* recycle notify ack */
2329 case XPT_IMMED_NOTIFY: /* Add Immediate Notify Resource */
2330 case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */
2333 get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun);
2335 ccb->ccb_h.status = CAM_LUN_INVALID;
2339 ccb->ccb_h.sim_priv.entries[0].field = 0;
2340 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
2341 ccb->ccb_h.flags = 0;
2343 CAMLOCK_2_ISPLOCK(isp);
2344 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
2346 * Note that the command itself may not be done-
2347 * it may not even have had the first CTIO sent.
2350 isp_prt(isp, ISP_LOGTDEBUG0,
2351 "Put FREE ATIO, lun %d, count now %d",
2352 ccb->ccb_h.target_lun, tptr->atio_count);
2353 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h,
2355 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
2357 isp_prt(isp, ISP_LOGTDEBUG0,
2358 "Put FREE INOT, lun %d, count now %d",
2359 ccb->ccb_h.target_lun, tptr->inot_count);
2360 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h,
2363 isp_prt(isp, ISP_LOGWARN, "Got Notify ACK");;
2365 rls_lun_statep(isp, tptr);
2366 ccb->ccb_h.status = CAM_REQ_INPROG;
2367 ISPLOCK_2_CAMLOCK(isp);
2370 case XPT_CONT_TARGET_IO:
2372 CAMLOCK_2_ISPLOCK(isp);
2373 isp_target_start_ctio(isp, ccb);
2374 ISPLOCK_2_CAMLOCK(isp);
2378 case XPT_RESET_DEV: /* BDR the specified SCSI device */
2380 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
2381 tgt = ccb->ccb_h.target_id;
2384 CAMLOCK_2_ISPLOCK(isp);
2385 error = isp_control(isp, ISPCTL_RESET_DEV, &tgt);
2386 ISPLOCK_2_CAMLOCK(isp);
2388 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2390 ccb->ccb_h.status = CAM_REQ_CMP;
2394 case XPT_ABORT: /* Abort the specified CCB */
2396 union ccb *accb = ccb->cab.abort_ccb;
2397 CAMLOCK_2_ISPLOCK(isp);
2398 switch (accb->ccb_h.func_code) {
2399 #ifdef ISP_TARGET_MODE
2400 case XPT_ACCEPT_TARGET_IO:
2401 case XPT_IMMED_NOTIFY:
2402 ccb->ccb_h.status = isp_abort_tgt_ccb(isp, ccb);
2404 case XPT_CONT_TARGET_IO:
2405 isp_prt(isp, ISP_LOGERR, "cannot abort CTIOs yet");
2406 ccb->ccb_h.status = CAM_UA_ABORT;
2410 error = isp_control(isp, ISPCTL_ABORT_CMD, ccb);
2412 ccb->ccb_h.status = CAM_UA_ABORT;
2414 ccb->ccb_h.status = CAM_REQ_CMP;
2418 ccb->ccb_h.status = CAM_REQ_INVALID;
2421 ISPLOCK_2_CAMLOCK(isp);
2425 #ifdef CAM_NEW_TRAN_CODE
2426 #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
2428 #define IS_CURRENT_SETTINGS(c) (c->flags & CCB_TRANS_CURRENT_SETTINGS)
2430 case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */
2432 if (!IS_CURRENT_SETTINGS(cts)) {
2433 ccb->ccb_h.status = CAM_REQ_INVALID;
2437 tgt = cts->ccb_h.target_id;
2438 CAMLOCK_2_ISPLOCK(isp);
2440 #ifndef CAM_NEW_TRAN_CODE
2441 sdparam *sdp = isp->isp_param;
2444 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2448 * We always update (internally) from goal_flags
2449 * so any request to change settings just gets
2450 * vectored to that location.
2452 dptr = &sdp->isp_devparam[tgt].goal_flags;
2455 * Note that these operations affect the
2456 * the goal flags (goal_flags)- not
2457 * the current state flags. Then we mark
2458 * things so that the next operation to
2459 * this HBA will cause the update to occur.
2461 if (cts->valid & CCB_TRANS_DISC_VALID) {
2462 if ((cts->flags & CCB_TRANS_DISC_ENB) != 0) {
2463 *dptr |= DPARM_DISC;
2465 *dptr &= ~DPARM_DISC;
2468 if (cts->valid & CCB_TRANS_TQ_VALID) {
2469 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0) {
2470 *dptr |= DPARM_TQING;
2472 *dptr &= ~DPARM_TQING;
2475 if (cts->valid & CCB_TRANS_BUS_WIDTH_VALID) {
2476 switch (cts->bus_width) {
2477 case MSG_EXT_WDTR_BUS_16_BIT:
2478 *dptr |= DPARM_WIDE;
2481 *dptr &= ~DPARM_WIDE;
2485 * Any SYNC RATE of nonzero and SYNC_OFFSET
2486 * of nonzero will cause us to go to the
2487 * selected (from NVRAM) maximum value for
2488 * this device. At a later point, we'll
2489 * allow finer control.
2491 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) &&
2492 (cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) &&
2493 (cts->sync_offset > 0)) {
2494 *dptr |= DPARM_SYNC;
2496 *dptr &= ~DPARM_SYNC;
2498 *dptr |= DPARM_SAFE_DFLT;
2500 struct ccb_trans_settings_scsi *scsi =
2501 &cts->proto_specific.scsi;
2502 struct ccb_trans_settings_spi *spi =
2503 &cts->xport_specific.spi;
2504 sdparam *sdp = isp->isp_param;
2507 bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2510 * We always update (internally) from goal_flags
2511 * so any request to change settings just gets
2512 * vectored to that location.
2514 dptr = &sdp->isp_devparam[tgt].goal_flags;
2516 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
2517 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
2518 *dptr |= DPARM_DISC;
2520 *dptr &= ~DPARM_DISC;
2523 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
2524 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
2525 *dptr |= DPARM_TQING;
2527 *dptr &= ~DPARM_TQING;
2530 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
2531 if (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT)
2532 *dptr |= DPARM_WIDE;
2534 *dptr &= ~DPARM_WIDE;
2540 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) &&
2541 (spi->valid & CTS_SPI_VALID_SYNC_RATE) &&
2542 (spi->sync_period && spi->sync_offset)) {
2543 *dptr |= DPARM_SYNC;
2545 * XXX: CHECK FOR LEGALITY
2547 sdp->isp_devparam[tgt].goal_period =
2549 sdp->isp_devparam[tgt].goal_offset =
2552 *dptr &= ~DPARM_SYNC;
2555 isp_prt(isp, ISP_LOGDEBUG0,
2556 "SET bus %d targ %d to flags %x off %x per %x",
2557 bus, tgt, sdp->isp_devparam[tgt].goal_flags,
2558 sdp->isp_devparam[tgt].goal_offset,
2559 sdp->isp_devparam[tgt].goal_period);
2560 sdp->isp_devparam[tgt].dev_update = 1;
2561 isp->isp_update |= (1 << bus);
2563 ISPLOCK_2_CAMLOCK(isp);
2564 ccb->ccb_h.status = CAM_REQ_CMP;
2567 case XPT_GET_TRAN_SETTINGS:
2569 tgt = cts->ccb_h.target_id;
2570 CAMLOCK_2_ISPLOCK(isp);
2572 #ifndef CAM_NEW_TRAN_CODE
2574 * a lot of normal SCSI things don't make sense.
2576 cts->flags = CCB_TRANS_TAG_ENB | CCB_TRANS_DISC_ENB;
2577 cts->valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
2579 * How do you measure the width of a high
2580 * speed serial bus? Well, in bytes.
2582 * Offset and period make no sense, though, so we set
2583 * (above) a 'base' transfer speed to be gigabit.
2585 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2587 fcparam *fcp = isp->isp_param;
2588 struct ccb_trans_settings_fc *fc =
2589 &cts->xport_specific.fc;
2591 cts->protocol = PROTO_SCSI;
2592 cts->protocol_version = SCSI_REV_2;
2593 cts->transport = XPORT_FC;
2594 cts->transport_version = 0;
2596 fc->valid = CTS_FC_VALID_SPEED;
2597 if (fcp->isp_gbspeed == 2)
2598 fc->bitrate = 200000;
2600 fc->bitrate = 100000;
2601 if (tgt > 0 && tgt < MAX_FC_TARG) {
2602 struct lportdb *lp = &fcp->portdb[tgt];
2603 fc->wwnn = lp->node_wwn;
2604 fc->wwpn = lp->port_wwn;
2605 fc->port = lp->portid;
2606 fc->valid |= CTS_FC_VALID_WWNN |
2607 CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT;
2611 #ifdef CAM_NEW_TRAN_CODE
2612 struct ccb_trans_settings_scsi *scsi =
2613 &cts->proto_specific.scsi;
2614 struct ccb_trans_settings_spi *spi =
2615 &cts->xport_specific.spi;
2617 sdparam *sdp = isp->isp_param;
2618 int bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path));
2619 uint16_t dval, pval, oval;
2623 if (IS_CURRENT_SETTINGS(cts)) {
2624 sdp->isp_devparam[tgt].dev_refresh = 1;
2625 isp->isp_update |= (1 << bus);
2626 (void) isp_control(isp, ISPCTL_UPDATE_PARAMS,
2628 dval = sdp->isp_devparam[tgt].actv_flags;
2629 oval = sdp->isp_devparam[tgt].actv_offset;
2630 pval = sdp->isp_devparam[tgt].actv_period;
2632 dval = sdp->isp_devparam[tgt].nvrm_flags;
2633 oval = sdp->isp_devparam[tgt].nvrm_offset;
2634 pval = sdp->isp_devparam[tgt].nvrm_period;
2637 #ifndef CAM_NEW_TRAN_CODE
2638 cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB);
2640 if (dval & DPARM_DISC) {
2641 cts->flags |= CCB_TRANS_DISC_ENB;
2643 if (dval & DPARM_TQING) {
2644 cts->flags |= CCB_TRANS_TAG_ENB;
2646 if (dval & DPARM_WIDE) {
2647 cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2649 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2651 cts->valid = CCB_TRANS_BUS_WIDTH_VALID |
2652 CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
2654 if ((dval & DPARM_SYNC) && oval != 0) {
2655 cts->sync_period = pval;
2656 cts->sync_offset = oval;
2658 CCB_TRANS_SYNC_RATE_VALID |
2659 CCB_TRANS_SYNC_OFFSET_VALID;
2662 cts->protocol = PROTO_SCSI;
2663 cts->protocol_version = SCSI_REV_2;
2664 cts->transport = XPORT_SPI;
2665 cts->transport_version = 2;
2667 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2668 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
2669 if (dval & DPARM_DISC) {
2670 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
2672 if (dval & DPARM_TQING) {
2673 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
2675 if ((dval & DPARM_SYNC) && oval && pval) {
2676 spi->sync_offset = oval;
2677 spi->sync_period = pval;
2678 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2679 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2681 spi->valid |= CTS_SPI_VALID_BUS_WIDTH;
2682 if (dval & DPARM_WIDE) {
2683 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2685 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2687 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
2688 scsi->valid = CTS_SCSI_VALID_TQ;
2689 spi->valid |= CTS_SPI_VALID_DISC;
2694 isp_prt(isp, ISP_LOGDEBUG0,
2695 "GET %s bus %d targ %d to flags %x off %x per %x",
2696 IS_CURRENT_SETTINGS(cts)? "ACTIVE" : "NVRAM",
2697 bus, tgt, dval, oval, pval);
2699 ISPLOCK_2_CAMLOCK(isp);
2700 ccb->ccb_h.status = CAM_REQ_CMP;
2704 case XPT_CALC_GEOMETRY:
2705 #if __FreeBSD_version < 500000
2707 struct ccb_calc_geometry *ccg;
2708 u_int32_t secs_per_cylinder;
2712 if (ccg->block_size == 0) {
2713 ccb->ccb_h.status = CAM_REQ_INVALID;
2717 size_mb = ccg->volume_size /((1024L * 1024L) / ccg->block_size);
2718 if (size_mb > 1024) {
2720 ccg->secs_per_track = 63;
2723 ccg->secs_per_track = 32;
2725 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
2726 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
2727 ccb->ccb_h.status = CAM_REQ_CMP;
2733 cam_calc_geometry(&ccb->ccg, /*extended*/1);
2738 case XPT_RESET_BUS: /* Reset the specified bus */
2739 bus = cam_sim_bus(sim);
2740 CAMLOCK_2_ISPLOCK(isp);
2741 error = isp_control(isp, ISPCTL_RESET_BUS, &bus);
2742 ISPLOCK_2_CAMLOCK(isp);
2744 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2746 if (cam_sim_bus(sim) && isp->isp_path2 != NULL)
2747 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
2748 else if (isp->isp_path != NULL)
2749 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
2750 ccb->ccb_h.status = CAM_REQ_CMP;
2755 case XPT_TERM_IO: /* Terminate the I/O process */
2756 ccb->ccb_h.status = CAM_REQ_INVALID;
2760 case XPT_PATH_INQ: /* Path routing inquiry */
2762 struct ccb_pathinq *cpi = &ccb->cpi;
2764 cpi->version_num = 1;
2765 #ifdef ISP_TARGET_MODE
2766 cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO;
2768 cpi->target_sprt = 0;
2770 cpi->hba_eng_cnt = 0;
2771 cpi->max_target = ISP_MAX_TARGETS(isp) - 1;
2772 cpi->max_lun = ISP_MAX_LUNS(isp) - 1;
2773 cpi->bus_id = cam_sim_bus(sim);
2775 cpi->hba_misc = PIM_NOBUSRESET;
2777 * Because our loop ID can shift from time to time,
2778 * make our initiator ID out of range of our bus.
2780 cpi->initiator_id = cpi->max_target + 1;
2783 * Set base transfer capabilities for Fibre Channel.
2784 * Technically not correct because we don't know
2785 * what media we're running on top of- but we'll
2786 * look good if we always say 100MB/s.
2788 if (FCPARAM(isp)->isp_gbspeed == 2)
2789 cpi->base_transfer_speed = 200000;
2791 cpi->base_transfer_speed = 100000;
2792 cpi->hba_inquiry = PI_TAG_ABLE;
2793 #ifdef CAM_NEW_TRAN_CODE
2794 cpi->transport = XPORT_FC;
2795 cpi->transport_version = 0; /* WHAT'S THIS FOR? */
2798 sdparam *sdp = isp->isp_param;
2799 sdp += cam_sim_bus(xpt_path_sim(cpi->ccb_h.path));
2800 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
2802 cpi->initiator_id = sdp->isp_initiator_id;
2803 cpi->base_transfer_speed = 3300;
2804 #ifdef CAM_NEW_TRAN_CODE
2805 cpi->transport = XPORT_SPI;
2806 cpi->transport_version = 2; /* WHAT'S THIS FOR? */
2809 #ifdef CAM_NEW_TRAN_CODE
2810 cpi->protocol = PROTO_SCSI;
2811 cpi->protocol_version = SCSI_REV_2;
2813 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
2814 strncpy(cpi->hba_vid, "Qlogic", HBA_IDLEN);
2815 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
2816 cpi->unit_number = cam_sim_unit(sim);
2817 cpi->ccb_h.status = CAM_REQ_CMP;
2822 ccb->ccb_h.status = CAM_REQ_INVALID;
2828 #define ISPDDB (CAM_DEBUG_INFO|CAM_DEBUG_TRACE|CAM_DEBUG_CDB)
2830 isp_done(struct ccb_scsiio *sccb)
2832 ispsoftc_t *isp = XS_ISP(sccb);
2835 XS_SETERR(sccb, CAM_REQ_CMP);
2837 if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
2838 (sccb->scsi_status != SCSI_STATUS_OK)) {
2839 sccb->ccb_h.status &= ~CAM_STATUS_MASK;
2840 if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) &&
2841 (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) {
2842 sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
2844 sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
2848 sccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2849 if ((sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2850 if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
2851 sccb->ccb_h.status |= CAM_DEV_QFRZN;
2852 xpt_freeze_devq(sccb->ccb_h.path, 1);
2853 isp_prt(isp, ISP_LOGDEBUG0,
2854 "freeze devq %d.%d cam sts %x scsi sts %x",
2855 sccb->ccb_h.target_id, sccb->ccb_h.target_lun,
2856 sccb->ccb_h.status, sccb->scsi_status);
2860 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) &&
2861 (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2862 xpt_print_path(sccb->ccb_h.path);
2863 isp_prt(isp, ISP_LOGINFO,
2864 "cam completion status 0x%x", sccb->ccb_h.status);
2867 XS_CMD_S_DONE(sccb);
2868 if (XS_CMD_WDOG_P(sccb) == 0) {
2869 untimeout(isp_watchdog, (caddr_t)sccb, sccb->ccb_h.timeout_ch);
2870 if (XS_CMD_GRACE_P(sccb)) {
2871 isp_prt(isp, ISP_LOGDEBUG2,
2872 "finished command on borrowed time");
2874 XS_CMD_S_CLEAR(sccb);
2875 ISPLOCK_2_CAMLOCK(isp);
2876 xpt_done((union ccb *) sccb);
2877 CAMLOCK_2_ISPLOCK(isp);
2882 isp_async(ispsoftc_t *isp, ispasync_t cmd, void *arg)
2886 case ISPASYNC_NEW_TGT_PARAMS:
2888 #ifdef CAM_NEW_TRAN_CODE
2889 struct ccb_trans_settings_scsi *scsi;
2890 struct ccb_trans_settings_spi *spi;
2893 sdparam *sdp = isp->isp_param;
2894 struct ccb_trans_settings cts;
2895 struct cam_path *tmppath;
2897 memset(&cts, 0, sizeof (struct ccb_trans_settings));
2899 tgt = *((int *)arg);
2900 bus = (tgt >> 16) & 0xffff;
2903 ISPLOCK_2_CAMLOCK(isp);
2904 if (xpt_create_path(&tmppath, NULL,
2905 cam_sim_path(bus? isp->isp_sim2 : isp->isp_sim),
2906 tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2907 CAMLOCK_2_ISPLOCK(isp);
2908 isp_prt(isp, ISP_LOGWARN,
2909 "isp_async cannot make temp path for %d.%d",
2914 CAMLOCK_2_ISPLOCK(isp);
2915 flags = sdp->isp_devparam[tgt].actv_flags;
2916 #ifdef CAM_NEW_TRAN_CODE
2917 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2918 cts.protocol = PROTO_SCSI;
2919 cts.transport = XPORT_SPI;
2921 scsi = &cts.proto_specific.scsi;
2922 spi = &cts.xport_specific.spi;
2924 if (flags & DPARM_TQING) {
2925 scsi->valid |= CTS_SCSI_VALID_TQ;
2926 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
2927 spi->flags |= CTS_SPI_FLAGS_TAG_ENB;
2930 if (flags & DPARM_DISC) {
2931 spi->valid |= CTS_SPI_VALID_DISC;
2932 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
2934 spi->flags |= CTS_SPI_VALID_BUS_WIDTH;
2935 if (flags & DPARM_WIDE) {
2936 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2938 spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
2940 if (flags & DPARM_SYNC) {
2941 spi->valid |= CTS_SPI_VALID_SYNC_RATE;
2942 spi->valid |= CTS_SPI_VALID_SYNC_OFFSET;
2943 spi->sync_period = sdp->isp_devparam[tgt].actv_period;
2944 spi->sync_offset = sdp->isp_devparam[tgt].actv_offset;
2947 cts.flags = CCB_TRANS_CURRENT_SETTINGS;
2948 cts.valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID;
2949 if (flags & DPARM_DISC) {
2950 cts.flags |= CCB_TRANS_DISC_ENB;
2952 if (flags & DPARM_TQING) {
2953 cts.flags |= CCB_TRANS_TAG_ENB;
2955 cts.valid |= CCB_TRANS_BUS_WIDTH_VALID;
2956 cts.bus_width = (flags & DPARM_WIDE)?
2957 MSG_EXT_WDTR_BUS_8_BIT : MSG_EXT_WDTR_BUS_16_BIT;
2958 cts.sync_period = sdp->isp_devparam[tgt].actv_period;
2959 cts.sync_offset = sdp->isp_devparam[tgt].actv_offset;
2960 if (flags & DPARM_SYNC) {
2962 CCB_TRANS_SYNC_RATE_VALID |
2963 CCB_TRANS_SYNC_OFFSET_VALID;
2966 isp_prt(isp, ISP_LOGDEBUG2,
2967 "NEW_TGT_PARAMS bus %d tgt %d period %x offset %x flags %x",
2968 bus, tgt, sdp->isp_devparam[tgt].actv_period,
2969 sdp->isp_devparam[tgt].actv_offset, flags);
2970 xpt_setup_ccb(&cts.ccb_h, tmppath, 1);
2971 ISPLOCK_2_CAMLOCK(isp);
2972 xpt_async(AC_TRANSFER_NEG, tmppath, &cts);
2973 xpt_free_path(tmppath);
2974 CAMLOCK_2_ISPLOCK(isp);
2977 case ISPASYNC_BUS_RESET:
2978 bus = *((int *)arg);
2979 isp_prt(isp, ISP_LOGINFO, "SCSI bus reset on bus %d detected",
2981 if (bus > 0 && isp->isp_path2) {
2982 ISPLOCK_2_CAMLOCK(isp);
2983 xpt_async(AC_BUS_RESET, isp->isp_path2, NULL);
2984 CAMLOCK_2_ISPLOCK(isp);
2985 } else if (isp->isp_path) {
2986 ISPLOCK_2_CAMLOCK(isp);
2987 xpt_async(AC_BUS_RESET, isp->isp_path, NULL);
2988 CAMLOCK_2_ISPLOCK(isp);
2992 if (isp->isp_path) {
2993 isp_freeze_loopdown(isp, "ISPASYNC_LIP");
2995 isp_prt(isp, ISP_LOGINFO, "LIP Received");
2997 case ISPASYNC_LOOP_RESET:
2998 if (isp->isp_path) {
2999 isp_freeze_loopdown(isp, "ISPASYNC_LOOP_RESET");
3001 isp_prt(isp, ISP_LOGINFO, "Loop Reset Received");
3003 case ISPASYNC_LOOP_DOWN:
3004 if (isp->isp_path) {
3005 isp_freeze_loopdown(isp, "ISPASYNC_LOOP_DOWN");
3007 isp_prt(isp, ISP_LOGINFO, "Loop DOWN");
3009 case ISPASYNC_LOOP_UP:
3011 * Now we just note that Loop has come up. We don't
3012 * actually do anything because we're waiting for a
3013 * Change Notify before activating the FC cleanup
3014 * thread to look at the state of the loop again.
3016 isp_prt(isp, ISP_LOGINFO, "Loop UP");
3018 case ISPASYNC_PROMENADE:
3020 const char *fmt = "Target %d (Loop 0x%x) Port ID 0x%x "
3021 "(role %s) %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x";
3022 static const char *roles[4] = {
3023 "(none)", "Target", "Initiator", "Target/Initiator"
3025 fcparam *fcp = isp->isp_param;
3026 int tgt = *((int *) arg);
3027 #if __FreeBSD_version >= 500000
3028 int is_tgt_mask = (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
3029 struct cam_path *tmppath;
3031 struct lportdb *lp = &fcp->portdb[tgt];
3033 isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid,
3034 roles[lp->roles & 0x3],
3035 (lp->valid)? "Arrived" : "Departed",
3036 (uint32_t) (lp->port_wwn >> 32),
3037 (uint32_t) (lp->port_wwn & 0xffffffffLL),
3038 (uint32_t) (lp->node_wwn >> 32),
3039 (uint32_t) (lp->node_wwn & 0xffffffffLL));
3041 ISPLOCK_2_CAMLOCK(isp);
3042 #if __FreeBSD_version >= 500000
3043 if (xpt_create_path(&tmppath, NULL, cam_sim_path(isp->isp_sim),
3044 (target_id_t)tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
3045 CAMLOCK_2_ISPLOCK(isp);
3049 * Policy: only announce targets.
3051 if (lp->roles & is_tgt_mask) {
3053 xpt_async(AC_FOUND_DEVICE, tmppath, NULL);
3055 xpt_async(AC_LOST_DEVICE, tmppath, NULL);
3058 xpt_free_path(tmppath);
3060 CAMLOCK_2_ISPLOCK(isp);
3063 case ISPASYNC_CHANGE_NOTIFY:
3064 if (arg == ISPASYNC_CHANGE_PDB) {
3065 isp_prt(isp, ISP_LOGINFO,
3066 "Port Database Changed");
3067 } else if (arg == ISPASYNC_CHANGE_SNS) {
3068 isp_prt(isp, ISP_LOGINFO,
3069 "Name Server Database Changed");
3071 #if __FreeBSD_version < 500000
3072 wakeup(&isp->isp_osinfo.kproc);
3075 cv_signal(&isp->isp_osinfo.kthread_cv);
3077 wakeup(&isp->isp_osinfo.kthread_cv);
3081 case ISPASYNC_FABRIC_DEV:
3083 int target, base, lim;
3084 fcparam *fcp = isp->isp_param;
3085 struct lportdb *lp = NULL;
3086 struct lportdb *clp = (struct lportdb *) arg;
3089 switch (clp->port_type) {
3116 isp_prt(isp, ISP_LOGINFO,
3117 "%s Fabric Device @ PortID 0x%x", pt, clp->portid);
3120 * If we don't have an initiator role we bail.
3122 * We just use ISPASYNC_FABRIC_DEV for announcement purposes.
3125 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
3130 * Is this entry for us? If so, we bail.
3133 if (fcp->isp_portid == clp->portid) {
3138 * Else, the default policy is to find room for it in
3139 * our local port database. Later, when we execute
3140 * the call to isp_pdb_sync either this newly arrived
3141 * or already logged in device will be (re)announced.
3144 if (fcp->isp_topo == TOPO_FL_PORT)
3149 if (fcp->isp_topo == TOPO_N_PORT)
3155 * Is it already in our list?
3157 for (target = base; target < lim; target++) {
3158 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3161 lp = &fcp->portdb[target];
3162 if (lp->port_wwn == clp->port_wwn &&
3163 lp->node_wwn == clp->node_wwn) {
3171 for (target = base; target < lim; target++) {
3172 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3175 lp = &fcp->portdb[target];
3176 if (lp->port_wwn == 0) {
3180 if (target == lim) {
3181 isp_prt(isp, ISP_LOGWARN,
3182 "out of space for fabric devices");
3185 lp->port_type = clp->port_type;
3186 lp->fc4_type = clp->fc4_type;
3187 lp->node_wwn = clp->node_wwn;
3188 lp->port_wwn = clp->port_wwn;
3189 lp->portid = clp->portid;
3193 #ifdef ISP_TARGET_MODE
3194 case ISPASYNC_TARGET_NOTIFY:
3196 tmd_notify_t *nt = arg;
3197 isp_prt(isp, ISP_LOGALL,
3198 "target notify code 0x%x", nt->nt_ncode);
3201 case ISPASYNC_TARGET_ACTION:
3202 switch (((isphdr_t *)arg)->rqs_entry_type) {
3204 isp_prt(isp, ISP_LOGWARN,
3205 "event 0x%x for unhandled target action",
3206 ((isphdr_t *)arg)->rqs_entry_type);
3208 case RQSTYPE_NOTIFY:
3210 rv = isp_handle_platform_notify_scsi(isp,
3211 (in_entry_t *) arg);
3213 rv = isp_handle_platform_notify_fc(isp,
3214 (in_fcentry_t *) arg);
3218 rv = isp_handle_platform_atio(isp, (at_entry_t *) arg);
3221 rv = isp_handle_platform_atio2(isp, (at2_entry_t *)arg);
3226 rv = isp_handle_platform_ctio(isp, arg);
3228 case RQSTYPE_ENABLE_LUN:
3229 case RQSTYPE_MODIFY_LUN:
3230 isp_ledone(isp, (lun_entry_t *) arg);
3235 case ISPASYNC_FW_CRASH:
3237 uint16_t mbox1, mbox6;
3238 mbox1 = ISP_READ(isp, OUTMAILBOX1);
3239 if (IS_DUALBUS(isp)) {
3240 mbox6 = ISP_READ(isp, OUTMAILBOX6);
3244 isp_prt(isp, ISP_LOGERR,
3245 "Internal Firmware Error on bus %d @ RISC Address 0x%x",
3247 #ifdef ISP_FW_CRASH_DUMP
3249 * XXX: really need a thread to do this right.
3252 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
3253 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
3254 isp_freeze_loopdown(isp, "f/w crash");
3258 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3262 case ISPASYNC_UNHANDLED_RESPONSE:
3265 isp_prt(isp, ISP_LOGERR, "unknown isp_async event %d", cmd);
3273 * Locks are held before coming here.
3276 isp_uninit(ispsoftc_t *isp)
3278 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
3283 isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
3286 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
3289 printf("%s: ", device_get_nameunit(isp->isp_dev));