Deleted Added
full compact
isp_freebsd.c (237537) isp_freebsd.c (238869)
1/*-
2 * Copyright (c) 1997-2009 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27/*
28 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
29 */
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997-2009 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27/*
28 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
29 */
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/isp/isp_freebsd.c 237537 2012-06-24 17:30:54Z mjacob $");
31__FBSDID("$FreeBSD: head/sys/dev/isp/isp_freebsd.c 238869 2012-07-28 20:06:29Z mjacob $");
32#include <dev/isp/isp_freebsd.h>
33#include <sys/unistd.h>
34#include <sys/kthread.h>
35#include <sys/conf.h>
36#include <sys/module.h>
37#include <sys/ioccom.h>
38#include <dev/isp/isp_ioctl.h>
39#include <sys/devicestat.h>

--- 10 unchanged lines hidden (view full) ---

50MODULE_DEPEND(isp, cam, 1, 1, 1);
51int isp_announced = 0;
52int isp_fabric_hysteresis = 5;
53int isp_loop_down_limit = 60; /* default loop down limit */
54int isp_change_is_bad = 0; /* "changed" devices are bad */
55int isp_quickboot_time = 7; /* don't wait more than N secs for loop up */
56int isp_gone_device_time = 30; /* grace time before reporting device lost */
57int isp_autoconfig = 1; /* automatically attach/detach devices */
32#include <dev/isp/isp_freebsd.h>
33#include <sys/unistd.h>
34#include <sys/kthread.h>
35#include <sys/conf.h>
36#include <sys/module.h>
37#include <sys/ioccom.h>
38#include <dev/isp/isp_ioctl.h>
39#include <sys/devicestat.h>

--- 10 unchanged lines hidden (view full) ---

50MODULE_DEPEND(isp, cam, 1, 1, 1);
51int isp_announced = 0;
52int isp_fabric_hysteresis = 5;
53int isp_loop_down_limit = 60; /* default loop down limit */
54int isp_change_is_bad = 0; /* "changed" devices are bad */
55int isp_quickboot_time = 7; /* don't wait more than N secs for loop up */
56int isp_gone_device_time = 30; /* grace time before reporting device lost */
57int isp_autoconfig = 1; /* automatically attach/detach devices */
58static const char *roles[4] = {
59 "(none)", "Target", "Initiator", "Target/Initiator"
60};
61static const char prom3[] = "Chan %d PortID 0x%06x Departed from Target %u because of %s";
62static const char rqo[] = "%s: Request Queue Overflow\n";
63
64static void isp_freeze_loopdown(ispsoftc_t *, int, char *);
65static d_ioctl_t ispioctl;
66static void isp_intr_enable(void *);
67static void isp_cam_async(void *, uint32_t, struct cam_path *, void *);
68static void isp_poll(struct cam_sim *);

--- 46 unchanged lines hidden (view full) ---

115 cam_sim_free(sim, FALSE);
116 return (ENXIO);
117 }
118 xpt_setup_ccb(&csa.ccb_h, path, 5);
119 csa.ccb_h.func_code = XPT_SASYNC_CB;
120 csa.event_enable = AC_LOST_DEVICE;
121 csa.callback = isp_cam_async;
122 csa.callback_arg = sim;
58static const char prom3[] = "Chan %d PortID 0x%06x Departed from Target %u because of %s";
59static const char rqo[] = "%s: Request Queue Overflow\n";
60
61static void isp_freeze_loopdown(ispsoftc_t *, int, char *);
62static d_ioctl_t ispioctl;
63static void isp_intr_enable(void *);
64static void isp_cam_async(void *, uint32_t, struct cam_path *, void *);
65static void isp_poll(struct cam_sim *);

--- 46 unchanged lines hidden (view full) ---

112 cam_sim_free(sim, FALSE);
113 return (ENXIO);
114 }
115 xpt_setup_ccb(&csa.ccb_h, path, 5);
116 csa.ccb_h.func_code = XPT_SASYNC_CB;
117 csa.event_enable = AC_LOST_DEVICE;
118 csa.callback = isp_cam_async;
119 csa.callback_arg = sim;
120
121 ISP_LOCK(isp);
123 xpt_action((union ccb *)&csa);
122 xpt_action((union ccb *)&csa);
123 ISP_UNLOCK(isp);
124
125 if (IS_SCSI(isp)) {
126 struct isp_spi *spi = ISP_SPI_PC(isp, chan);
127 spi->sim = sim;
128 spi->path = path;
129#ifdef ISP_INTERNAL_TARGET
130 ISP_SET_PC(isp, chan, proc_active, 1);
131 if (THREAD_CREATE(isp_target_thread_pi, spi, &spi->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {

--- 17 unchanged lines hidden (view full) ---

149 TASK_INIT(&fc->gtask, 1, isp_gdt_task, fc);
150
151 /*
152 * We start by being "loop down" if we have an initiator role
153 */
154 if (fcp->role & ISP_ROLE_INITIATOR) {
155 isp_freeze_loopdown(isp, chan, "isp_attach");
156 callout_reset(&fc->ldt, isp_quickboot_time * hz, isp_ldt, fc);
124
125 if (IS_SCSI(isp)) {
126 struct isp_spi *spi = ISP_SPI_PC(isp, chan);
127 spi->sim = sim;
128 spi->path = path;
129#ifdef ISP_INTERNAL_TARGET
130 ISP_SET_PC(isp, chan, proc_active, 1);
131 if (THREAD_CREATE(isp_target_thread_pi, spi, &spi->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {

--- 17 unchanged lines hidden (view full) ---

149 TASK_INIT(&fc->gtask, 1, isp_gdt_task, fc);
150
151 /*
152 * We start by being "loop down" if we have an initiator role
153 */
154 if (fcp->role & ISP_ROLE_INITIATOR) {
155 isp_freeze_loopdown(isp, chan, "isp_attach");
156 callout_reset(&fc->ldt, isp_quickboot_time * hz, isp_ldt, fc);
157 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Starting Initial Loop Down Timer @ %lu", (unsigned long) time_uptime);
157 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Starting Initial Loop Down Timer @ %lu", (unsigned long) time_uptime);
158 }
159 ISP_UNLOCK(isp);
160 if (THREAD_CREATE(isp_kthread, fc, &fc->kproc, 0, 0, "%s: fc_thrd%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
161 xpt_free_path(fc->path);
162 ISP_LOCK(isp);
158 }
159 ISP_UNLOCK(isp);
160 if (THREAD_CREATE(isp_kthread, fc, &fc->kproc, 0, 0, "%s: fc_thrd%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
161 xpt_free_path(fc->path);
162 ISP_LOCK(isp);
163 if (callout_active(&fc->ldt)) {
163 if (callout_active(&fc->ldt))
164 callout_stop(&fc->ldt);
164 callout_stop(&fc->ldt);
165 }
166 xpt_bus_deregister(cam_sim_path(fc->sim));
167 ISP_UNLOCK(isp);
168 cam_sim_free(fc->sim, FALSE);
169 return (ENOMEM);
170 }
171#ifdef ISP_INTERNAL_TARGET
172 ISP_SET_PC(isp, chan, proc_active, 1);
173 if (THREAD_CREATE(isp_target_thread_fc, fc, &fc->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
174 ISP_SET_PC(isp, chan, proc_active, 0);
175 isp_prt(isp, ISP_LOGERR, "cannot create test target thread");
176 }
177#endif
178 if (chan == 0) {
179 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(isp->isp_osinfo.dev);
180 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
181 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwnn", CTLFLAG_RD, &FCPARAM(isp, 0)->isp_wwnn, "World Wide Node Name");
182 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwpn", CTLFLAG_RD, &FCPARAM(isp, 0)->isp_wwpn, "World Wide Port Name");
183 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "loop_down_limit", CTLFLAG_RW, &ISP_FC_PC(isp, 0)->loop_down_limit, 0, "Loop Down Limit");
184 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "gone_device_time", CTLFLAG_RW, &ISP_FC_PC(isp, 0)->gone_device_time, 0, "Gone Device Time");
165 xpt_bus_deregister(cam_sim_path(fc->sim));
166 ISP_UNLOCK(isp);
167 cam_sim_free(fc->sim, FALSE);
168 return (ENOMEM);
169 }
170#ifdef ISP_INTERNAL_TARGET
171 ISP_SET_PC(isp, chan, proc_active, 1);
172 if (THREAD_CREATE(isp_target_thread_fc, fc, &fc->target_proc, 0, 0, "%s: isp_test_tgt%d", device_get_nameunit(isp->isp_osinfo.dev), chan)) {
173 ISP_SET_PC(isp, chan, proc_active, 0);
174 isp_prt(isp, ISP_LOGERR, "cannot create test target thread");
175 }
176#endif
177 if (chan == 0) {
178 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(isp->isp_osinfo.dev);
179 struct sysctl_oid *tree = device_get_sysctl_tree(isp->isp_osinfo.dev);
180 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwnn", CTLFLAG_RD, &FCPARAM(isp, 0)->isp_wwnn, "World Wide Node Name");
181 SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "wwpn", CTLFLAG_RD, &FCPARAM(isp, 0)->isp_wwpn, "World Wide Port Name");
182 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "loop_down_limit", CTLFLAG_RW, &ISP_FC_PC(isp, 0)->loop_down_limit, 0, "Loop Down Limit");
183 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "gone_device_time", CTLFLAG_RW, &ISP_FC_PC(isp, 0)->gone_device_time, 0, "Gone Device Time");
184#if defined(ISP_TARGET_MODE) && defined(DEBUG)
185 SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "inject_lost_data_frame", CTLFLAG_RW, &ISP_FC_PC(isp, 0)->inject_lost_data_frame, 0, "Cause a Lost Frame on a Read");
186#endif
185 }
186 }
187 return (0);
188}
189
190int
191isp_attach(ispsoftc_t *isp)
192{

--- 103 unchanged lines hidden (view full) ---

296 sim = ISP_SPI_PC(isp, chan)->sim;
297 path = ISP_SPI_PC(isp, chan)->path;
298 }
299 xpt_setup_ccb(&csa.ccb_h, path, 5);
300 csa.ccb_h.func_code = XPT_SASYNC_CB;
301 csa.event_enable = 0;
302 csa.callback = isp_cam_async;
303 csa.callback_arg = sim;
187 }
188 }
189 return (0);
190}
191
192int
193isp_attach(ispsoftc_t *isp)
194{

--- 103 unchanged lines hidden (view full) ---

298 sim = ISP_SPI_PC(isp, chan)->sim;
299 path = ISP_SPI_PC(isp, chan)->path;
300 }
301 xpt_setup_ccb(&csa.ccb_h, path, 5);
302 csa.ccb_h.func_code = XPT_SASYNC_CB;
303 csa.event_enable = 0;
304 csa.callback = isp_cam_async;
305 csa.callback_arg = sim;
306 ISP_LOCK(isp);
304 xpt_action((union ccb *)&csa);
307 xpt_action((union ccb *)&csa);
308 ISP_UNLOCK(isp);
305 xpt_free_path(path);
306 xpt_bus_deregister(cam_sim_path(sim));
307 cam_sim_free(sim, FALSE);
308 }
309 ISP_UNLOCK(isp);
310 if (isp->isp_osinfo.cdev) {
311 destroy_dev(isp->isp_osinfo.cdev);
312 isp->isp_osinfo.cdev = NULL;

--- 28 unchanged lines hidden (view full) ---

341static void
342isp_unfreeze_loopdown(ispsoftc_t *isp, int chan)
343{
344 if (IS_FC(isp)) {
345 struct isp_fc *fc = ISP_FC_PC(isp, chan);
346 int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
347 fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
348 if (wasfrozen && fc->simqfrozen == 0) {
309 xpt_free_path(path);
310 xpt_bus_deregister(cam_sim_path(sim));
311 cam_sim_free(sim, FALSE);
312 }
313 ISP_UNLOCK(isp);
314 if (isp->isp_osinfo.cdev) {
315 destroy_dev(isp->isp_osinfo.cdev);
316 isp->isp_osinfo.cdev = NULL;

--- 28 unchanged lines hidden (view full) ---

345static void
346isp_unfreeze_loopdown(ispsoftc_t *isp, int chan)
347{
348 if (IS_FC(isp)) {
349 struct isp_fc *fc = ISP_FC_PC(isp, chan);
350 int wasfrozen = fc->simqfrozen & SIMQFRZ_LOOPDOWN;
351 fc->simqfrozen &= ~SIMQFRZ_LOOPDOWN;
352 if (wasfrozen && fc->simqfrozen == 0) {
349 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d releasing simq", __func__, chan);
353 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d releasing simq", __func__, chan);
350 xpt_release_simq(fc->sim, 1);
351 }
352 }
353}
354
355
356static int
357ispioctl(struct cdev *dev, u_long c, caddr_t addr, int flags, struct thread *td)
358{
359 ispsoftc_t *isp;
360 int nr, chan, retval = ENOTTY;
361
362 isp = dev->si_drv1;
354 xpt_release_simq(fc->sim, 1);
355 }
356 }
357}
358
359
360static int
361ispioctl(struct cdev *dev, u_long c, caddr_t addr, int flags, struct thread *td)
362{
363 ispsoftc_t *isp;
364 int nr, chan, retval = ENOTTY;
365
366 isp = dev->si_drv1;
363
367
364 switch (c) {
365 case ISP_SDBLEV:
366 {
367 int olddblev = isp->isp_dblev;
368 isp->isp_dblev = *(int *)addr;
369 *(int *)addr = olddblev;
370 retval = 0;
371 break;

--- 102 unchanged lines hidden (view full) ---

474 break;
475 }
476 if (ifc->loopid >= MAX_FC_TARG) {
477 retval = EINVAL;
478 break;
479 }
480 lp = &FCPARAM(isp, ifc->chan)->portdb[ifc->loopid];
481 if (lp->state == FC_PORTDB_STATE_VALID || lp->target_mode) {
368 switch (c) {
369 case ISP_SDBLEV:
370 {
371 int olddblev = isp->isp_dblev;
372 isp->isp_dblev = *(int *)addr;
373 *(int *)addr = olddblev;
374 retval = 0;
375 break;

--- 102 unchanged lines hidden (view full) ---

478 break;
479 }
480 if (ifc->loopid >= MAX_FC_TARG) {
481 retval = EINVAL;
482 break;
483 }
484 lp = &FCPARAM(isp, ifc->chan)->portdb[ifc->loopid];
485 if (lp->state == FC_PORTDB_STATE_VALID || lp->target_mode) {
482 ifc->role = lp->roles;
486 ifc->role = (lp->prli_word3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
483 ifc->loopid = lp->handle;
484 ifc->portid = lp->portid;
485 ifc->node_wwn = lp->node_wwn;
486 ifc->port_wwn = lp->port_wwn;
487 retval = 0;
488 } else {
489 retval = ENODEV;
490 }

--- 276 unchanged lines hidden (view full) ---

767 }
768 isp->isp_osinfo.pcmd_free = ((struct isp_pcmd *)ISP_PCMD(ccb))->next;
769 return (0);
770}
771
772static ISP_INLINE void
773isp_free_pcmd(ispsoftc_t *isp, union ccb *ccb)
774{
487 ifc->loopid = lp->handle;
488 ifc->portid = lp->portid;
489 ifc->node_wwn = lp->node_wwn;
490 ifc->port_wwn = lp->port_wwn;
491 retval = 0;
492 } else {
493 retval = ENODEV;
494 }

--- 276 unchanged lines hidden (view full) ---

771 }
772 isp->isp_osinfo.pcmd_free = ((struct isp_pcmd *)ISP_PCMD(ccb))->next;
773 return (0);
774}
775
776static ISP_INLINE void
777isp_free_pcmd(ispsoftc_t *isp, union ccb *ccb)
778{
775 ((struct isp_pcmd *)ISP_PCMD(ccb))->next = isp->isp_osinfo.pcmd_free;
776 isp->isp_osinfo.pcmd_free = ISP_PCMD(ccb);
777 ISP_PCMD(ccb) = NULL;
779 if (ISP_PCMD(ccb)) {
780 ((struct isp_pcmd *)ISP_PCMD(ccb))->next = isp->isp_osinfo.pcmd_free;
781 isp->isp_osinfo.pcmd_free = ISP_PCMD(ccb);
782 ISP_PCMD(ccb) = NULL;
783 }
778}
784}
785
779/*
780 * Put the target mode functions here, because some are inlines
781 */
786/*
787 * Put the target mode functions here, because some are inlines
788 */
782
783#ifdef ISP_TARGET_MODE
784static ISP_INLINE void isp_tmlock(ispsoftc_t *, const char *);
785static ISP_INLINE void isp_tmunlk(ispsoftc_t *);
786static ISP_INLINE int is_any_lun_enabled(ispsoftc_t *, int);
787static ISP_INLINE int is_lun_enabled(ispsoftc_t *, int, lun_id_t);
788static ISP_INLINE tstate_t *get_lun_statep(ispsoftc_t *, int, lun_id_t);
789static ISP_INLINE tstate_t *get_lun_statep_from_tag(ispsoftc_t *, int, uint32_t);
790static ISP_INLINE void rls_lun_statep(ispsoftc_t *, tstate_t *);

--- 8 unchanged lines hidden (view full) ---

799static void isp_enable_lun(ispsoftc_t *, union ccb *);
800static cam_status isp_enable_deferred_luns(ispsoftc_t *, int);
801static cam_status isp_enable_deferred(ispsoftc_t *, int, lun_id_t);
802static void isp_disable_lun(ispsoftc_t *, union ccb *);
803static int isp_enable_target_mode(ispsoftc_t *, int);
804static int isp_disable_target_mode(ispsoftc_t *, int);
805static void isp_ledone(ispsoftc_t *, lun_entry_t *);
806static timeout_t isp_refire_putback_atio;
789#ifdef ISP_TARGET_MODE
790static ISP_INLINE void isp_tmlock(ispsoftc_t *, const char *);
791static ISP_INLINE void isp_tmunlk(ispsoftc_t *);
792static ISP_INLINE int is_any_lun_enabled(ispsoftc_t *, int);
793static ISP_INLINE int is_lun_enabled(ispsoftc_t *, int, lun_id_t);
794static ISP_INLINE tstate_t *get_lun_statep(ispsoftc_t *, int, lun_id_t);
795static ISP_INLINE tstate_t *get_lun_statep_from_tag(ispsoftc_t *, int, uint32_t);
796static ISP_INLINE void rls_lun_statep(ispsoftc_t *, tstate_t *);

--- 8 unchanged lines hidden (view full) ---

805static void isp_enable_lun(ispsoftc_t *, union ccb *);
806static cam_status isp_enable_deferred_luns(ispsoftc_t *, int);
807static cam_status isp_enable_deferred(ispsoftc_t *, int, lun_id_t);
808static void isp_disable_lun(ispsoftc_t *, union ccb *);
809static int isp_enable_target_mode(ispsoftc_t *, int);
810static int isp_disable_target_mode(ispsoftc_t *, int);
811static void isp_ledone(ispsoftc_t *, lun_entry_t *);
812static timeout_t isp_refire_putback_atio;
813static timeout_t isp_refire_notify_ack;
807static void isp_complete_ctio(union ccb *);
808static void isp_target_putback_atio(union ccb *);
814static void isp_complete_ctio(union ccb *);
815static void isp_target_putback_atio(union ccb *);
809static void isp_target_start_ctio(ispsoftc_t *, union ccb *);
816enum Start_Ctio_How { FROM_CAM, FROM_SRR, FROM_CTIO_DONE };
817static void isp_target_start_ctio(ispsoftc_t *, union ccb *, enum Start_Ctio_How);
810static void isp_handle_platform_atio(ispsoftc_t *, at_entry_t *);
811static void isp_handle_platform_atio2(ispsoftc_t *, at2_entry_t *);
812static void isp_handle_platform_atio7(ispsoftc_t *, at7_entry_t *);
813static void isp_handle_platform_ctio(ispsoftc_t *, void *);
814static void isp_handle_platform_notify_scsi(ispsoftc_t *, in_entry_t *);
815static void isp_handle_platform_notify_fc(ispsoftc_t *, in_fcentry_t *);
816static void isp_handle_platform_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *);
817static int isp_handle_platform_target_notify_ack(ispsoftc_t *, isp_notify_t *);

--- 203 unchanged lines hidden (view full) ---

1021 }
1022 }
1023 return (NULL);
1024}
1025
1026static ISP_INLINE void
1027isp_put_atpd(ispsoftc_t *isp, tstate_t *tptr, atio_private_data_t *atp)
1028{
818static void isp_handle_platform_atio(ispsoftc_t *, at_entry_t *);
819static void isp_handle_platform_atio2(ispsoftc_t *, at2_entry_t *);
820static void isp_handle_platform_atio7(ispsoftc_t *, at7_entry_t *);
821static void isp_handle_platform_ctio(ispsoftc_t *, void *);
822static void isp_handle_platform_notify_scsi(ispsoftc_t *, in_entry_t *);
823static void isp_handle_platform_notify_fc(ispsoftc_t *, in_fcentry_t *);
824static void isp_handle_platform_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *);
825static int isp_handle_platform_target_notify_ack(ispsoftc_t *, isp_notify_t *);

--- 203 unchanged lines hidden (view full) ---

1029 }
1030 }
1031 return (NULL);
1032}
1033
1034static ISP_INLINE void
1035isp_put_atpd(ispsoftc_t *isp, tstate_t *tptr, atio_private_data_t *atp)
1036{
1029 atp->tag = 0;
1030 atp->dead = 0;
1037 if (atp->ests) {
1038 isp_put_ecmd(isp, atp->ests);
1039 }
1040 memset(atp, 0, sizeof (*atp));
1031 atp->next = tptr->atfree;
1032 tptr->atfree = atp;
1033}
1034
1035static void
1036isp_dump_atpd(ispsoftc_t *isp, tstate_t *tptr)
1037{
1038 atio_private_data_t *atp;

--- 204 unchanged lines hidden (view full) ---

1243 * Now check to see whether this bus is in target mode already.
1244 *
1245 * If not, a later role change into target mode will finish the job.
1246 */
1247 if (tm_enabled == 0) {
1248 ISP_SET_PC(isp, bus, tm_enable_defer, 1);
1249 ccb->ccb_h.status = CAM_REQ_CMP;
1250 xpt_print(ccb->ccb_h.path, "Target Mode not enabled yet- lun enable deferred\n");
1041 atp->next = tptr->atfree;
1042 tptr->atfree = atp;
1043}
1044
1045static void
1046isp_dump_atpd(ispsoftc_t *isp, tstate_t *tptr)
1047{
1048 atio_private_data_t *atp;

--- 204 unchanged lines hidden (view full) ---

1253 * Now check to see whether this bus is in target mode already.
1254 *
1255 * If not, a later role change into target mode will finish the job.
1256 */
1257 if (tm_enabled == 0) {
1258 ISP_SET_PC(isp, bus, tm_enable_defer, 1);
1259 ccb->ccb_h.status = CAM_REQ_CMP;
1260 xpt_print(ccb->ccb_h.path, "Target Mode not enabled yet- lun enable deferred\n");
1251 goto done;
1261 goto done1;
1252 }
1253
1254 /*
1255 * Enable the lun.
1256 */
1257 ccb->ccb_h.status = isp_enable_deferred(isp, bus, lun);
1258
1259done:
1260 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1261 if (tptr) {
1262 destroy_lun_state(isp, tptr);
1263 tptr = NULL;
1264 }
1265 } else {
1266 tptr->enabled = 1;
1267 }
1262 }
1263
1264 /*
1265 * Enable the lun.
1266 */
1267 ccb->ccb_h.status = isp_enable_deferred(isp, bus, lun);
1268
1269done:
1270 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1271 if (tptr) {
1272 destroy_lun_state(isp, tptr);
1273 tptr = NULL;
1274 }
1275 } else {
1276 tptr->enabled = 1;
1277 }
1278done1:
1268 if (tptr) {
1269 rls_lun_statep(isp, tptr);
1270 }
1271
1272 /*
1273 * And we're outta here....
1274 */
1275 isp_tmunlk(isp);
1276 xpt_done(ccb);
1277}
1278
1279static cam_status
1280isp_enable_deferred_luns(ispsoftc_t *isp, int bus)
1281{
1282 tstate_t *tptr = NULL;
1283 struct tslist *lhp;
1284 int i, n;
1285
1279 if (tptr) {
1280 rls_lun_statep(isp, tptr);
1281 }
1282
1283 /*
1284 * And we're outta here....
1285 */
1286 isp_tmunlk(isp);
1287 xpt_done(ccb);
1288}
1289
1290static cam_status
1291isp_enable_deferred_luns(ispsoftc_t *isp, int bus)
1292{
1293 tstate_t *tptr = NULL;
1294 struct tslist *lhp;
1295 int i, n;
1296
1297
1286 ISP_GET_PC(isp, bus, tm_enabled, i);
1287 if (i == 1) {
1288 return (CAM_REQ_CMP);
1289 }
1290 ISP_GET_PC(isp, bus, tm_enable_defer, i);
1291 if (i == 0) {
1292 return (CAM_REQ_CMP);
1293 }

--- 4 unchanged lines hidden (view full) ---

1298 return (CAM_REQ_CMP_ERR);
1299 }
1300 isp_tmlock(isp, "isp_enable_deferred_luns");
1301 for (n = i = 0; i < LUN_HASH_SIZE; i++) {
1302 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
1303 SLIST_FOREACH(tptr, lhp, next) {
1304 tptr->hold++;
1305 if (tptr->enabled == 0) {
1298 ISP_GET_PC(isp, bus, tm_enabled, i);
1299 if (i == 1) {
1300 return (CAM_REQ_CMP);
1301 }
1302 ISP_GET_PC(isp, bus, tm_enable_defer, i);
1303 if (i == 0) {
1304 return (CAM_REQ_CMP);
1305 }

--- 4 unchanged lines hidden (view full) ---

1310 return (CAM_REQ_CMP_ERR);
1311 }
1312 isp_tmlock(isp, "isp_enable_deferred_luns");
1313 for (n = i = 0; i < LUN_HASH_SIZE; i++) {
1314 ISP_GET_PC_ADDR(isp, bus, lun_hash[i], lhp);
1315 SLIST_FOREACH(tptr, lhp, next) {
1316 tptr->hold++;
1317 if (tptr->enabled == 0) {
1306 if (isp_enable_deferred(isp, bus, xpt_path_lun_id(tptr->owner)) == 0) {
1318 if (isp_enable_deferred(isp, bus, xpt_path_lun_id(tptr->owner)) == CAM_REQ_CMP) {
1307 tptr->enabled = 1;
1308 n++;
1309 }
1310 } else {
1311 n++;
1312 }
1313 tptr->hold--;
1314 }

--- 5 unchanged lines hidden (view full) ---

1320 ISP_SET_PC(isp, bus, tm_enable_defer, 0);
1321 return (CAM_REQ_CMP);
1322}
1323
1324static cam_status
1325isp_enable_deferred(ispsoftc_t *isp, int bus, lun_id_t lun)
1326{
1327 cam_status status;
1319 tptr->enabled = 1;
1320 n++;
1321 }
1322 } else {
1323 n++;
1324 }
1325 tptr->hold--;
1326 }

--- 5 unchanged lines hidden (view full) ---

1332 ISP_SET_PC(isp, bus, tm_enable_defer, 0);
1333 return (CAM_REQ_CMP);
1334}
1335
1336static cam_status
1337isp_enable_deferred(ispsoftc_t *isp, int bus, lun_id_t lun)
1338{
1339 cam_status status;
1328 int luns_already_enabled = ISP_FC_PC(isp, bus)->tm_luns_enabled;
1340 int luns_already_enabled;
1329
1341
1330 isp_prt(isp, ISP_LOGTINFO, "%s: bus %d lun %u", __func__, bus, lun);
1342 ISP_GET_PC(isp, bus, tm_luns_enabled, luns_already_enabled);
1343 isp_prt(isp, ISP_LOGTINFO, "%s: bus %d lun %u luns_enabled %d", __func__, bus, lun, luns_already_enabled);
1331 if (IS_24XX(isp) || (IS_FC(isp) && luns_already_enabled)) {
1332 status = CAM_REQ_CMP;
1333 } else {
1334 int cmd_cnt, not_cnt;
1335
1336 if (IS_23XX(isp)) {
1337 cmd_cnt = DFLT_CMND_CNT;
1338 not_cnt = DFLT_INOT_CNT;
1339 } else {
1340 cmd_cnt = 64;
1341 not_cnt = 8;
1342 }
1343 status = CAM_REQ_INPROG;
1344 isp->isp_osinfo.rptr = &status;
1344 if (IS_24XX(isp) || (IS_FC(isp) && luns_already_enabled)) {
1345 status = CAM_REQ_CMP;
1346 } else {
1347 int cmd_cnt, not_cnt;
1348
1349 if (IS_23XX(isp)) {
1350 cmd_cnt = DFLT_CMND_CNT;
1351 not_cnt = DFLT_INOT_CNT;
1352 } else {
1353 cmd_cnt = 64;
1354 not_cnt = 8;
1355 }
1356 status = CAM_REQ_INPROG;
1357 isp->isp_osinfo.rptr = &status;
1345 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun, DFLT_CMND_CNT, DFLT_INOT_CNT)) {
1358 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun == CAM_LUN_WILDCARD? 0 : lun, cmd_cnt, not_cnt)) {
1346 status = CAM_RESRC_UNAVAIL;
1347 } else {
1348 mtx_sleep(&status, &isp->isp_lock, PRIBIO, "isp_enable_deferred", 0);
1349 }
1350 isp->isp_osinfo.rptr = NULL;
1351 }
1352 if (status == CAM_REQ_CMP) {
1353 ISP_SET_PC(isp, bus, tm_luns_enabled, 1);

--- 53 unchanged lines hidden (view full) ---

1407 if (IS_24XX(isp)) {
1408 status = CAM_REQ_CMP;
1409 goto done;
1410 }
1411
1412 /*
1413 * For SCC FW, we only deal with lun zero.
1414 */
1359 status = CAM_RESRC_UNAVAIL;
1360 } else {
1361 mtx_sleep(&status, &isp->isp_lock, PRIBIO, "isp_enable_deferred", 0);
1362 }
1363 isp->isp_osinfo.rptr = NULL;
1364 }
1365 if (status == CAM_REQ_CMP) {
1366 ISP_SET_PC(isp, bus, tm_luns_enabled, 1);

--- 53 unchanged lines hidden (view full) ---

1420 if (IS_24XX(isp)) {
1421 status = CAM_REQ_CMP;
1422 goto done;
1423 }
1424
1425 /*
1426 * For SCC FW, we only deal with lun zero.
1427 */
1415 if (IS_FC(isp)) {
1416 lun = 0;
1428 if (IS_FC(isp) && lun > 0) {
1429 status = CAM_REQ_CMP;
1430 goto done;
1417 }
1418 isp->isp_osinfo.rptr = &status;
1419 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun, 0, 0)) {
1420 status = CAM_RESRC_UNAVAIL;
1421 } else {
1422 mtx_sleep(ccb, &isp->isp_lock, PRIBIO, "isp_disable_lun", 0);
1423 }
1424 isp->isp_osinfo.rptr = NULL;
1425done:
1426 if (status == CAM_REQ_CMP) {
1427 tptr->enabled = 0;
1428 /*
1431 }
1432 isp->isp_osinfo.rptr = &status;
1433 if (isp_lun_cmd(isp, RQSTYPE_ENABLE_LUN, bus, lun, 0, 0)) {
1434 status = CAM_RESRC_UNAVAIL;
1435 } else {
1436 mtx_sleep(ccb, &isp->isp_lock, PRIBIO, "isp_disable_lun", 0);
1437 }
1438 isp->isp_osinfo.rptr = NULL;
1439done:
1440 if (status == CAM_REQ_CMP) {
1441 tptr->enabled = 0;
1442 /*
1429 * If we have no more luns enabled for this bus, delete all tracked wwns for it (if we are FC)
1443 * If we have no more luns enabled for this bus,
1444 * delete all tracked wwns for it (if we are FC),
1430 * and disable target mode.
1431 */
1432 if (is_any_lun_enabled(isp, bus) == 0) {
1433 isp_del_all_wwn_entries(isp, bus);
1434 if (isp_disable_target_mode(isp, bus)) {
1435 status = CAM_REQ_CMP_ERR;
1436 }
1437 }

--- 49 unchanged lines hidden (view full) ---

1487 MBSINIT(&mbs, MBOX_ENABLE_TARGET_MODE, MBLOGALL, 0);
1488 mbs.param[2] = bus << 7;
1489 if (isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs) < 0 || mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1490 isp_prt(isp, ISP_LOGERR, "Unable to disable Target Role on Bus %d", bus);
1491 return (EIO);
1492 }
1493 }
1494 ISP_SET_PC(isp, bus, tm_enabled, 0);
1445 * and disable target mode.
1446 */
1447 if (is_any_lun_enabled(isp, bus) == 0) {
1448 isp_del_all_wwn_entries(isp, bus);
1449 if (isp_disable_target_mode(isp, bus)) {
1450 status = CAM_REQ_CMP_ERR;
1451 }
1452 }

--- 49 unchanged lines hidden (view full) ---

1502 MBSINIT(&mbs, MBOX_ENABLE_TARGET_MODE, MBLOGALL, 0);
1503 mbs.param[2] = bus << 7;
1504 if (isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs) < 0 || mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1505 isp_prt(isp, ISP_LOGERR, "Unable to disable Target Role on Bus %d", bus);
1506 return (EIO);
1507 }
1508 }
1509 ISP_SET_PC(isp, bus, tm_enabled, 0);
1495 isp_prt(isp, ISP_LOGINFO, "Target Role disabled onon Bus %d", bus);
1510 isp_prt(isp, ISP_LOGINFO, "Target Role disabled on Bus %d", bus);
1496 return (0);
1497}
1498
1499static void
1500isp_ledone(ispsoftc_t *isp, lun_entry_t *lep)
1501{
1502 uint32_t *rptr;
1503

--- 8 unchanged lines hidden (view full) ---

1512 if (rptr) {
1513 *rptr = CAM_REQ_CMP;
1514 wakeup_one(rptr);
1515 }
1516 }
1517}
1518
1519static void
1511 return (0);
1512}
1513
1514static void
1515isp_ledone(ispsoftc_t *isp, lun_entry_t *lep)
1516{
1517 uint32_t *rptr;
1518

--- 8 unchanged lines hidden (view full) ---

1527 if (rptr) {
1528 *rptr = CAM_REQ_CMP;
1529 wakeup_one(rptr);
1530 }
1531 }
1532}
1533
1534static void
1520isp_target_start_ctio(ispsoftc_t *isp, union ccb *ccb)
1535isp_target_start_ctio(ispsoftc_t *isp, union ccb *ccb, enum Start_Ctio_How how)
1521{
1536{
1537
1522 void *qe;
1538 void *qe;
1539 int fctape, sendstatus, resid, repval = ISP_LOGTDEBUG0;
1523 tstate_t *tptr;
1540 tstate_t *tptr;
1541 fcparam *fcp;
1524 atio_private_data_t *atp;
1525 struct ccb_scsiio *cso = &ccb->csio;
1542 atio_private_data_t *atp;
1543 struct ccb_scsiio *cso = &ccb->csio;
1526 uint32_t dmaresult, handle;
1544 uint32_t dmaresult, handle, xfrlen, sense_length;
1527 uint8_t local[QENTRY_LEN];
1528
1529 /*
1530 * Do some sanity checks.
1531 */
1545 uint8_t local[QENTRY_LEN];
1546
1547 /*
1548 * Do some sanity checks.
1549 */
1532 if (cso->dxfer_len == 0) {
1550 xfrlen = cso->dxfer_len;
1551 if (xfrlen == 0) {
1533 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
1552 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
1534 xpt_print(ccb->ccb_h.path, "a data transfer length of zero but no status to send is wrong\n");
1553 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "a data transfer length of zero but no status to send is wrong\n");
1535 ccb->ccb_h.status = CAM_REQ_INVALID;
1536 xpt_done(ccb);
1537 return;
1538 }
1539 }
1540
1541 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), XS_LUN(ccb));
1542 if (tptr == NULL) {
1543 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), CAM_LUN_WILDCARD);
1544 if (tptr == NULL) {
1554 ccb->ccb_h.status = CAM_REQ_INVALID;
1555 xpt_done(ccb);
1556 return;
1557 }
1558 }
1559
1560 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), XS_LUN(ccb));
1561 if (tptr == NULL) {
1562 tptr = get_lun_statep(isp, XS_CHANNEL(ccb), CAM_LUN_WILDCARD);
1563 if (tptr == NULL) {
1545 xpt_print(ccb->ccb_h.path, "%s: [0x%x] cannot find tstate pointer in %s\n", __func__, cso->tag_id);
1546 dump_tstates(isp, XS_CHANNEL(ccb));
1564 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "%s: [0x%x] cannot find tstate pointer in %s\n", __func__, cso->tag_id);
1547 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
1548 xpt_done(ccb);
1549 return;
1550 }
1551 }
1552
1553 atp = isp_get_atpd(isp, tptr, cso->tag_id);
1554 if (atp == NULL) {
1565 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
1566 xpt_done(ccb);
1567 return;
1568 }
1569 }
1570
1571 atp = isp_get_atpd(isp, tptr, cso->tag_id);
1572 if (atp == NULL) {
1555 xpt_print(ccb->ccb_h.path, "%s: [0x%x] cannot find private data adjunct\n", __func__, cso->tag_id);
1573 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "%s: [0x%x] cannot find private data adjunct\n", __func__, cso->tag_id);
1556 isp_dump_atpd(isp, tptr);
1557 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1558 xpt_done(ccb);
1559 return;
1560 }
1574 isp_dump_atpd(isp, tptr);
1575 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1576 xpt_done(ccb);
1577 return;
1578 }
1579
1580 /*
1581 * Is this command a dead duck?
1582 */
1561 if (atp->dead) {
1583 if (atp->dead) {
1562 xpt_print(ccb->ccb_h.path, "%s: [0x%x] stopping sending a CTIO for a dead command\n", __func__, cso->tag_id);
1584 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "%s: [0x%x] not sending a CTIO for a dead command\n", __func__, cso->tag_id);
1563 ccb->ccb_h.status = CAM_REQ_ABORTED;
1564 xpt_done(ccb);
1565 return;
1566 }
1567
1568 /*
1569 * Check to make sure we're still in target mode.
1570 */
1585 ccb->ccb_h.status = CAM_REQ_ABORTED;
1586 xpt_done(ccb);
1587 return;
1588 }
1589
1590 /*
1591 * Check to make sure we're still in target mode.
1592 */
1571 if ((FCPARAM(isp, XS_CHANNEL(ccb))->role & ISP_ROLE_TARGET) == 0) {
1572 xpt_print(ccb->ccb_h.path, "%s: [0x%x] stopping sending a CTIO because we're no longer in target mode\n", __func__, cso->tag_id);
1593 fcp = FCPARAM(isp, XS_CHANNEL(ccb));
1594 if ((fcp->role & ISP_ROLE_TARGET) == 0) {
1595 ISP_PATH_PRT(isp, ISP_LOGERR, ccb->ccb_h.path, "%s: [0x%x] stopping sending a CTIO because we're no longer in target mode\n", __func__, cso->tag_id);
1573 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1574 xpt_done(ccb);
1575 return;
1576 }
1577
1578 /*
1596 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
1597 xpt_done(ccb);
1598 return;
1599 }
1600
1601 /*
1602 * We're only handling one outstanding CTIO at a time (which
1603 * could be split into two to split data and status)
1604 */
1605 if (atp->ctcnt) {
1606 ISP_PATH_PRT(isp, ISP_LOGINFO, ccb->ccb_h.path, "sending only one CTIO at a time\n");
1607 goto restart_delay;
1608 }
1609
1610
1611 /*
1579 * Get some resources
1580 */
1581 if (isp_get_pcmd(isp, ccb)) {
1612 * Get some resources
1613 */
1614 if (isp_get_pcmd(isp, ccb)) {
1582 rls_lun_statep(isp, tptr);
1583 xpt_print(ccb->ccb_h.path, "out of PCMDs\n");
1584 cam_freeze_devq(ccb->ccb_h.path);
1585 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
1586 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1587 xpt_done(ccb);
1588 return;
1615 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "out of PCMDs\n");
1616 goto restart_delay;
1589 }
1590 qe = isp_getrqentry(isp);
1591 if (qe == NULL) {
1617 }
1618 qe = isp_getrqentry(isp);
1619 if (qe == NULL) {
1592 xpt_print(ccb->ccb_h.path, rqo, __func__);
1593 cam_freeze_devq(ccb->ccb_h.path);
1594 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
1595 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1596 goto out;
1620 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, rqo, __func__);
1621 goto restart_delay;
1597 }
1598 memset(local, 0, QENTRY_LEN);
1599
1600 /*
1622 }
1623 memset(local, 0, QENTRY_LEN);
1624
1625 /*
1601 * We're either moving data or completing a command here.
1626 * Does the initiator expect FC-Tape style responses?
1627 * Can we provide them?
1602 */
1628 */
1629 if ((atp->word3 & PRLI_WD3_RETRY) && fcp->fctape_enabled) {
1630 fctape = 1;
1631 } else {
1632 fctape = 0;
1633 }
1634
1635 /*
1636 * If we already did the data xfer portion of a CTIO that sends data
1637 * and status, don't do it again and do the status portion now.
1638 */
1639 if (atp->sendst) {
1640 xfrlen = 0; /* we already did the data transfer */
1641 atp->sendst = 0;
1642 }
1643 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1644 sendstatus = 1;
1645 } else {
1646 sendstatus = 0;
1647 }
1648
1649 if (ccb->ccb_h.flags & CAM_SEND_SENSE) {
1650 /*
1651 * Sense length is not the entire sense data structure size. Periph
1652 * drivers don't seem to be setting sense_len to reflect the actual
1653 * size. We'll peek inside to get the right amount.
1654 */
1655 sense_length = cso->sense_len;
1656
1657 /*
1658 * This 'cannot' happen
1659 */
1660 if (sense_length > (XCMD_SIZE - MIN_FCP_RESPONSE_SIZE)) {
1661 sense_length = XCMD_SIZE - MIN_FCP_RESPONSE_SIZE;
1662 }
1663 } else {
1664 sense_length = 0;
1665 }
1666
1667 if (how == FROM_SRR || atp->nsrr)
1668 repval = ISP_LOGINFO;
1669
1603 if (IS_24XX(isp)) {
1604 ct7_entry_t *cto = (ct7_entry_t *) local;
1605
1606 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
1607 cto->ct_header.rqs_entry_count = 1;
1608 cto->ct_header.rqs_seqno = 1;
1609 cto->ct_nphdl = atp->nphdl;
1610 cto->ct_rxid = atp->tag;
1611 cto->ct_iid_lo = atp->portid;
1612 cto->ct_iid_hi = atp->portid >> 16;
1613 cto->ct_oxid = atp->oxid;
1614 cto->ct_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(ccb));
1670 if (IS_24XX(isp)) {
1671 ct7_entry_t *cto = (ct7_entry_t *) local;
1672
1673 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
1674 cto->ct_header.rqs_entry_count = 1;
1675 cto->ct_header.rqs_seqno = 1;
1676 cto->ct_nphdl = atp->nphdl;
1677 cto->ct_rxid = atp->tag;
1678 cto->ct_iid_lo = atp->portid;
1679 cto->ct_iid_hi = atp->portid >> 16;
1680 cto->ct_oxid = atp->oxid;
1681 cto->ct_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(ccb));
1615 cto->ct_scsi_status = cso->scsi_status;
1616 cto->ct_timeout = 120;
1617 cto->ct_flags = atp->tattr << CT7_TASK_ATTR_SHIFT;
1682 cto->ct_timeout = 120;
1683 cto->ct_flags = atp->tattr << CT7_TASK_ATTR_SHIFT;
1618 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1619 cto->ct_flags |= CT7_SENDSTATUS;
1620 }
1621 if (cso->dxfer_len == 0) {
1622 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_NO_DATA;
1623 if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) {
1624 int m = min(cso->sense_len, sizeof (struct scsi_sense_data));
1625 cto->rsp.m1.ct_resplen = cto->ct_senselen = min(m, MAXRESPLEN_24XX);
1626 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, cto->ct_senselen);
1627 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
1684
1685 /*
1686 * Mode 1, status, no data. Only possible when we are sending status, have
1687 * no data to transfer, and any sense length can fit in the ct7_entry.
1688 *
1689 * Mode 2, status, no data. We have to use this in the case sense data
1690 * won't fit into a ct7_entry_t.
1691 *
1692 */
1693 if (sendstatus && xfrlen == 0) {
1694 cto->ct_flags |= CT7_SENDSTATUS | CT7_NO_DATA;
1695 resid = atp->orig_datalen - atp->bytes_xfered;
1696 if (sense_length <= MAXRESPLEN_24XX) {
1697 if (resid < 0) {
1698 cto->ct_resid = -resid;
1699 } else if (resid > 0) {
1700 cto->ct_resid = resid;
1701 }
1702 cto->ct_flags |= CT7_FLAG_MODE1;
1703 cto->ct_scsi_status = cso->scsi_status;
1704 if (resid < 0) {
1705 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
1706 } else if (resid > 0) {
1707 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
1708 }
1709 if (fctape) {
1710 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1711 }
1712 if (sense_length) {
1713 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
1714 cto->rsp.m1.ct_resplen = cto->ct_senselen = sense_length;
1715 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, sense_length);
1716 }
1717 } else {
1718 bus_addr_t addr;
1719 char buf[XCMD_SIZE];
1720 fcp_rsp_iu_t *rp;
1721
1722 if (atp->ests == NULL) {
1723 atp->ests = isp_get_ecmd(isp);
1724 if (atp->ests == NULL) {
1725 goto restart_delay;
1726 }
1727 }
1728 memset(buf, 0, sizeof (buf));
1729 rp = (fcp_rsp_iu_t *)buf;
1730 if (fctape) {
1731 cto->ct_flags |= CT7_CONFIRM|CT7_EXPLCT_CONF;
1732 rp->fcp_rsp_bits |= FCP_CONF_REQ;
1733 }
1734 cto->ct_flags |= CT7_FLAG_MODE2;
1735 rp->fcp_rsp_scsi_status = cso->scsi_status;
1736 if (resid < 0) {
1737 rp->fcp_rsp_resid = -resid;
1738 rp->fcp_rsp_bits |= FCP_RESID_OVERFLOW;
1739 } else if (resid > 0) {
1740 rp->fcp_rsp_resid = resid;
1741 rp->fcp_rsp_bits |= FCP_RESID_UNDERFLOW;
1742 }
1743 if (sense_length) {
1744 rp->fcp_rsp_snslen = sense_length;
1745 cto->ct_senselen = sense_length;
1746 rp->fcp_rsp_bits |= FCP_SNSLEN_VALID;
1747 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1748 memcpy(((fcp_rsp_iu_t *)atp->ests)->fcp_rsp_extra, &cso->sense_data, sense_length);
1749 } else {
1750 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1751 }
1752 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
1753 isp_print_bytes(isp, "FCP Response Frame After Swizzling", MIN_FCP_RESPONSE_SIZE + sense_length, atp->ests);
1754 }
1755 addr = isp->isp_osinfo.ecmd_dma;
1756 addr += ((((isp_ecmd_t *)atp->ests) - isp->isp_osinfo.ecmd_base) * XCMD_SIZE);
1757 isp_prt(isp, repval, "%s: ests base %p vaddr %p ecmd_dma %jx addr %jx len %u", __func__, isp->isp_osinfo.ecmd_base, atp->ests,
1758 (uintmax_t) isp->isp_osinfo.ecmd_dma, (uintmax_t)addr, MIN_FCP_RESPONSE_SIZE + sense_length);
1759 cto->rsp.m2.ct_datalen = MIN_FCP_RESPONSE_SIZE + sense_length;
1760 cto->rsp.m2.ct_fcp_rsp_iudata.ds_base = DMA_LO32(addr);
1761 cto->rsp.m2.ct_fcp_rsp_iudata.ds_basehi = DMA_HI32(addr);
1762 cto->rsp.m2.ct_fcp_rsp_iudata.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
1628 }
1763 }
1629 } else {
1764 if (sense_length) {
1765 isp_prt(isp, repval, "%s: CTIO7[0x%x] CDB0=%x sstatus=0x%x flags=0x%x resid=%d slen %u sense: %x %x/%x/%x", __func__,
1766 cto->ct_rxid, atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid, sense_length, cso->sense_data.error_code,
1767 cso->sense_data.sense_buf[1], cso->sense_data.sense_buf[11], cso->sense_data.sense_buf[12]);
1768 } else {
1769 isp_prt(isp, repval, "%s: CTIO7[0x%x] CDB0=%x sstatus=0x%x flags=0x%x resid=%d", __func__,
1770 cto->ct_rxid, atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid);
1771 }
1772 atp->state = ATPD_STATE_LAST_CTIO;
1773 }
1774
1775 /*
1776 * Mode 0 data transfers, *possibly* with status.
1777 */
1778 if (xfrlen != 0) {
1630 cto->ct_flags |= CT7_FLAG_MODE0;
1631 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1632 cto->ct_flags |= CT7_DATA_IN;
1633 } else {
1634 cto->ct_flags |= CT7_DATA_OUT;
1635 }
1779 cto->ct_flags |= CT7_FLAG_MODE0;
1780 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1781 cto->ct_flags |= CT7_DATA_IN;
1782 } else {
1783 cto->ct_flags |= CT7_DATA_OUT;
1784 }
1636 cto->rsp.m0.reloff = atp->bytes_xfered;
1785
1637 /*
1786 /*
1638 * Don't overrun the limits placed on us
1787 * Don't overrun the limits placed on us, but record it as
1788 * if we had so that we can set an overflow bit later.
1639 */
1789 */
1640 if (atp->bytes_xfered + cso->dxfer_len > atp->orig_datalen) {
1641 cso->dxfer_len = atp->orig_datalen - atp->bytes_xfered;
1790 atp->last_xframt = xfrlen;
1791 if (atp->bytes_xfered >= atp->orig_datalen) {
1792 resid = atp->orig_datalen - (atp->bytes_xfered + xfrlen);
1793 } else if (atp->bytes_xfered + xfrlen > atp->orig_datalen) {
1794 resid = atp->orig_datalen - (atp->bytes_xfered + xfrlen);
1795 xfrlen = atp->orig_datalen - atp->bytes_xfered;
1796 } else {
1797 resid = atp->orig_datalen - xfrlen;
1642 }
1798 }
1643 atp->last_xframt = cso->dxfer_len;
1644 cto->rsp.m0.ct_xfrlen = cso->dxfer_len;
1645 }
1646 if (cto->ct_flags & CT7_SENDSTATUS) {
1647 int lvl = (cso->scsi_status)? ISP_LOGTINFO : ISP_LOGTDEBUG0;
1648 cto->ct_resid = atp->orig_datalen - (atp->bytes_xfered + cso->dxfer_len);
1649 if (cto->ct_resid < 0) {
1650 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
1651 } else if (cto->ct_resid > 0) {
1652 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
1799 cto->rsp.m0.reloff = atp->bytes_xfered;
1800 cto->rsp.m0.ct_xfrlen = xfrlen;
1801
1802#ifdef DEBUG
1803 if (ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame && xfrlen > ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame) {
1804 isp_prt(isp, ISP_LOGWARN, "%s: truncating data frame with xfrlen %d to %d", __func__, xfrlen, xfrlen - (xfrlen >> 2));
1805 ISP_FC_PC(isp, XS_CHANNEL(ccb))->inject_lost_data_frame = 0;
1806 cto->rsp.m0.ct_xfrlen -= xfrlen >> 2;
1653 }
1807 }
1654 atp->state = ATPD_STATE_LAST_CTIO;
1655 ISP_PATH_PRT(isp, lvl, cso->ccb_h.path, "%s: CTIO7[%x] CDB0=%x scsi status %x flags %x resid %d xfrlen %u offset %u\n", __func__, cto->ct_rxid,
1656 atp->cdb0, cto->ct_scsi_status, cto->ct_flags, cto->ct_resid, cso->dxfer_len, atp->bytes_xfered);
1657 } else {
1658 cto->ct_resid = 0;
1659 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, cso->ccb_h.path, "%s: CTIO7[%x] flags %x xfrlen %u offset %u\n", __func__, cto->ct_rxid, cto->ct_flags,
1660 cso->dxfer_len, atp->bytes_xfered);
1661 atp->state = ATPD_STATE_CTIO;
1808#endif
1809 if (sendstatus) {
1810 if (cso->scsi_status == SCSI_STATUS_OK && resid == 0 && fctape == 0) {
1811 cto->ct_flags |= CT7_SENDSTATUS;
1812 atp->state = ATPD_STATE_LAST_CTIO;
1813 } else {
1814 atp->sendst = 1; /* send status later */
1815 cto->ct_header.rqs_seqno = 0;
1816 atp->state = ATPD_STATE_CTIO;
1817 }
1818 } else {
1819 atp->state = ATPD_STATE_CTIO;
1820 }
1821 isp_prt(isp, repval, "%s: CTIO7[0x%x] CDB0=%x sstatus=0x%x flags=0x%x xfrlen=%u off=%u", __func__,
1822 cto->ct_rxid, atp->cdb0, cto->ct_scsi_status, cto->ct_flags, xfrlen, atp->bytes_xfered);
1662 }
1663 } else if (IS_FC(isp)) {
1664 ct2_entry_t *cto = (ct2_entry_t *) local;
1665
1823 }
1824 } else if (IS_FC(isp)) {
1825 ct2_entry_t *cto = (ct2_entry_t *) local;
1826
1666 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1827 if (isp->isp_osinfo.sixtyfourbit)
1828 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO3;
1829 else
1830 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
1667 cto->ct_header.rqs_entry_count = 1;
1668 cto->ct_header.rqs_seqno = 1;
1669 if (ISP_CAP_2KLOGIN(isp) == 0) {
1670 ((ct2e_entry_t *)cto)->ct_iid = cso->init_id;
1671 } else {
1672 cto->ct_iid = cso->init_id;
1673 if (ISP_CAP_SCCFW(isp) == 0) {
1674 cto->ct_lun = ccb->ccb_h.target_lun;
1675 }
1676 }
1831 cto->ct_header.rqs_entry_count = 1;
1832 cto->ct_header.rqs_seqno = 1;
1833 if (ISP_CAP_2KLOGIN(isp) == 0) {
1834 ((ct2e_entry_t *)cto)->ct_iid = cso->init_id;
1835 } else {
1836 cto->ct_iid = cso->init_id;
1837 if (ISP_CAP_SCCFW(isp) == 0) {
1838 cto->ct_lun = ccb->ccb_h.target_lun;
1839 }
1840 }
1841 cto->ct_timeout = 10;
1842 cto->ct_rxid = cso->tag_id;
1677
1843
1844 /*
1845 * Mode 1, status, no data. Only possible when we are sending status, have
1846 * no data to transfer, and the sense length can fit in the ct7_entry.
1847 *
1848 * Mode 2, status, no data. We have to use this in the case the the response
1849 * length won't fit into a ct2_entry_t.
1850 *
1851 * We'll fill out this structure with information as if this were a
1852 * Mode 1. The hardware layer will create the Mode 2 FCP RSP IU as
1853 * needed based upon this.
1854 */
1855 if (sendstatus && xfrlen == 0) {
1856 cto->ct_flags |= CT2_SENDSTATUS | CT2_NO_DATA;
1857 resid = atp->orig_datalen - atp->bytes_xfered;
1858 if (sense_length <= MAXRESPLEN) {
1859 if (resid < 0) {
1860 cto->ct_resid = -resid;
1861 } else if (resid > 0) {
1862 cto->ct_resid = resid;
1863 }
1864 cto->ct_flags |= CT2_FLAG_MODE1;
1865 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1866 if (resid < 0) {
1867 cto->rsp.m1.ct_scsi_status |= CT2_DATA_OVER;
1868 } else if (resid > 0) {
1869 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
1870 }
1871 if (fctape) {
1872 cto->ct_flags |= CT2_CONFIRM;
1873 }
1874 if (sense_length) {
1875 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1876 cto->rsp.m1.ct_resplen = cto->rsp.m1.ct_senselen = sense_length;
1877 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, sense_length);
1878 }
1879 } else {
1880 bus_addr_t addr;
1881 char buf[XCMD_SIZE];
1882 fcp_rsp_iu_t *rp;
1678
1883
1679 cto->ct_rxid = cso->tag_id;
1680 if (cso->dxfer_len == 0) {
1681 cto->ct_flags |= CT2_FLAG_MODE1 | CT2_NO_DATA | CT2_SENDSTATUS;
1682 cto->rsp.m1.ct_scsi_status = cso->scsi_status;
1683 cto->ct_resid = atp->orig_datalen - atp->bytes_xfered;
1684 if (cto->ct_resid < 0) {
1685 cto->rsp.m1.ct_scsi_status |= CT2_DATA_OVER;
1686 } else if (cto->ct_resid > 0) {
1687 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
1884 if (atp->ests == NULL) {
1885 atp->ests = isp_get_ecmd(isp);
1886 if (atp->ests == NULL) {
1887 goto restart_delay;
1888 }
1889 }
1890 memset(buf, 0, sizeof (buf));
1891 rp = (fcp_rsp_iu_t *)buf;
1892 if (fctape) {
1893 cto->ct_flags |= CT2_CONFIRM;
1894 rp->fcp_rsp_bits |= FCP_CONF_REQ;
1895 }
1896 cto->ct_flags |= CT2_FLAG_MODE2;
1897 rp->fcp_rsp_scsi_status = cso->scsi_status;
1898 if (resid < 0) {
1899 rp->fcp_rsp_resid = -resid;
1900 rp->fcp_rsp_bits |= FCP_RESID_OVERFLOW;
1901 } else if (resid > 0) {
1902 rp->fcp_rsp_resid = resid;
1903 rp->fcp_rsp_bits |= FCP_RESID_UNDERFLOW;
1904 }
1905 if (sense_length) {
1906 rp->fcp_rsp_snslen = sense_length;
1907 rp->fcp_rsp_bits |= FCP_SNSLEN_VALID;
1908 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1909 memcpy(((fcp_rsp_iu_t *)atp->ests)->fcp_rsp_extra, &cso->sense_data, sense_length);
1910 } else {
1911 isp_put_fcp_rsp_iu(isp, rp, atp->ests);
1912 }
1913 if (isp->isp_dblev & ISP_LOGTDEBUG1) {
1914 isp_print_bytes(isp, "FCP Response Frame After Swizzling", MIN_FCP_RESPONSE_SIZE + sense_length, atp->ests);
1915 }
1916 addr = isp->isp_osinfo.ecmd_dma;
1917 addr += ((((isp_ecmd_t *)atp->ests) - isp->isp_osinfo.ecmd_base) * XCMD_SIZE);
1918 isp_prt(isp, repval, "%s: ests base %p vaddr %p ecmd_dma %jx addr %jx len %u", __func__, isp->isp_osinfo.ecmd_base, atp->ests,
1919 (uintmax_t) isp->isp_osinfo.ecmd_dma, (uintmax_t)addr, MIN_FCP_RESPONSE_SIZE + sense_length);
1920 cto->rsp.m2.ct_datalen = MIN_FCP_RESPONSE_SIZE + sense_length;
1921 if (isp->isp_osinfo.sixtyfourbit) {
1922 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_base = DMA_LO32(addr);
1923 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_basehi = DMA_HI32(addr);
1924 cto->rsp.m2.u.ct_fcp_rsp_iudata_64.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
1925 } else {
1926 cto->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_base = DMA_LO32(addr);
1927 cto->rsp.m2.u.ct_fcp_rsp_iudata_32.ds_count = MIN_FCP_RESPONSE_SIZE + sense_length;
1928 }
1688 }
1929 }
1689 if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) {
1690 int m = min(cso->sense_len, MAXRESPLEN);
1691 memcpy(cto->rsp.m1.ct_resp, &cso->sense_data, m);
1692 cto->rsp.m1.ct_senselen = m;
1693 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
1694 } else if (cso->scsi_status == SCSI_STATUS_CHECK_COND) {
1695 /*
1696 * XXX: DEBUG
1697 */
1698 xpt_print(ccb->ccb_h.path, "CHECK CONDITION being sent without associated SENSE DATA for CDB=0x%x\n", atp->cdb0);
1930 if (sense_length) {
1931 isp_prt(isp, repval, "%s: CTIO2[0x%x] CDB0=%x sstatus=0x%x flags=0x%x resid=%d sense: %x %x/%x/%x", __func__,
1932 cto->ct_rxid, atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid, cso->sense_data.error_code,
1933 cso->sense_data.sense_buf[1], cso->sense_data.sense_buf[11], cso->sense_data.sense_buf[12]);
1934 } else {
1935 isp_prt(isp, repval, "%s: CTIO2[0x%x] CDB0=%x sstatus=0x%x flags=0x%x resid=%d", __func__,
1936 cto->ct_rxid, atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid);
1699 }
1937 }
1700 } else {
1938 atp->state = ATPD_STATE_LAST_CTIO;
1939 }
1940
1941 if (xfrlen != 0) {
1942 int resid = 0;
1701 cto->ct_flags |= CT2_FLAG_MODE0;
1702 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1703 cto->ct_flags |= CT2_DATA_IN;
1704 } else {
1705 cto->ct_flags |= CT2_DATA_OUT;
1706 }
1943 cto->ct_flags |= CT2_FLAG_MODE0;
1944 if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1945 cto->ct_flags |= CT2_DATA_IN;
1946 } else {
1947 cto->ct_flags |= CT2_DATA_OUT;
1948 }
1707 cto->ct_reloff = atp->bytes_xfered;
1708 cto->rsp.m0.ct_xfrlen = cso->dxfer_len;
1949
1709 /*
1950 /*
1710 * Don't overrun the limits placed on us
1951 * Don't overrun the limits placed on us, but record it as
1952 * if we had so that we can set an overflow bit later.
1711 */
1953 */
1712 if (atp->bytes_xfered + cso->dxfer_len > atp->orig_datalen) {
1713 cso->dxfer_len = atp->orig_datalen - atp->bytes_xfered;
1954 atp->last_xframt = xfrlen;
1955 if (atp->bytes_xfered + xfrlen > atp->orig_datalen) {
1956 resid = 1;
1957 xfrlen = atp->orig_datalen - atp->bytes_xfered;
1714 }
1958 }
1715 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
1716 cto->ct_flags |= CT2_SENDSTATUS;
1717 cto->rsp.m0.ct_scsi_status = cso->scsi_status;
1718 cto->ct_resid = atp->orig_datalen - (atp->bytes_xfered + cso->dxfer_len);
1719 if (cto->ct_resid < 0) {
1720 cto->rsp.m0.ct_scsi_status |= CT2_DATA_OVER;
1721 } else if (cto->ct_resid > 0) {
1722 cto->rsp.m0.ct_scsi_status |= CT2_DATA_UNDER;
1959 cto->ct_reloff = atp->bytes_xfered;
1960 cto->rsp.m0.ct_xfrlen = xfrlen;
1961
1962 if (sendstatus) {
1963 if (cso->scsi_status == SCSI_STATUS_OK && resid == 0 && fctape == 0) {
1964 cto->ct_flags |= CT2_SENDSTATUS;
1965 atp->state = ATPD_STATE_LAST_CTIO;
1966 } else {
1967 atp->sendst = 1; /* send status later */
1968 cto->ct_header.rqs_seqno = 0;
1969 atp->state = ATPD_STATE_CTIO;
1723 }
1724 } else {
1970 }
1971 } else {
1725 atp->last_xframt = cso->dxfer_len;
1972 atp->state = ATPD_STATE_CTIO;
1726 }
1973 }
1727 /*
1728 * If we're sending data and status back together,
1729 * we can't also send back sense data as well.
1730 */
1731 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1732 }
1974 }
1733
1734 if (cto->ct_flags & CT2_SENDSTATUS) {
1735 int lvl = (cso->scsi_status)? ISP_LOGTINFO : ISP_LOGTDEBUG0;
1736 cto->ct_flags |= CT2_CCINCR;
1737 atp->state = ATPD_STATE_LAST_CTIO;
1738 ISP_PATH_PRT(isp, lvl, cso->ccb_h.path, "%s: CTIO2[%x] CDB0=%x scsi status %x flags %x resid %d xfrlen %u offset %u\n", __func__, cto->ct_rxid,
1739 atp->cdb0, cto->rsp.m0.ct_scsi_status, cto->ct_flags, cto->ct_resid, cso->dxfer_len, atp->bytes_xfered);
1740 } else {
1741 cto->ct_resid = 0;
1742 atp->state = ATPD_STATE_CTIO;
1743 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: CTIO2[%x] flags %x xfrlen %u offset %u\n", __func__, cto->ct_rxid, cto->ct_flags,
1744 cso->dxfer_len, atp->bytes_xfered);
1745 }
1746 cto->ct_timeout = 10;
1975 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO2[%x] CDB0=%x scsi status %x flags %x resid %d xfrlen %u offset %u", __func__, cto->ct_rxid,
1976 atp->cdb0, cso->scsi_status, cto->ct_flags, cto->ct_resid, cso->dxfer_len, atp->bytes_xfered);
1747 } else {
1748 ct_entry_t *cto = (ct_entry_t *) local;
1749
1750 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
1751 cto->ct_header.rqs_entry_count = 1;
1752 cto->ct_header.rqs_seqno = 1;
1753 cto->ct_iid = cso->init_id;
1754 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
1755 cto->ct_tgt = ccb->ccb_h.target_id;
1756 cto->ct_lun = ccb->ccb_h.target_lun;
1977 } else {
1978 ct_entry_t *cto = (ct_entry_t *) local;
1979
1980 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
1981 cto->ct_header.rqs_entry_count = 1;
1982 cto->ct_header.rqs_seqno = 1;
1983 cto->ct_iid = cso->init_id;
1984 cto->ct_iid |= XS_CHANNEL(ccb) << 7;
1985 cto->ct_tgt = ccb->ccb_h.target_id;
1986 cto->ct_lun = ccb->ccb_h.target_lun;
1757 cto->ct_fwhandle = cso->tag_id >> 16;
1758 if (AT_HAS_TAG(cso->tag_id)) {
1759 cto->ct_tag_val = cso->tag_id;
1987 cto->ct_fwhandle = cso->tag_id;
1988 if (atp->rxid) {
1989 cto->ct_tag_val = atp->rxid;
1760 cto->ct_flags |= CT_TQAE;
1761 }
1762 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
1763 cto->ct_flags |= CT_NODISC;
1764 }
1765 if (cso->dxfer_len == 0) {
1766 cto->ct_flags |= CT_NO_DATA;
1767 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1768 cto->ct_flags |= CT_DATA_IN;
1769 } else {
1770 cto->ct_flags |= CT_DATA_OUT;
1771 }
1772 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
1773 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
1774 cto->ct_scsi_status = cso->scsi_status;
1775 cto->ct_resid = cso->resid;
1990 cto->ct_flags |= CT_TQAE;
1991 }
1992 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) {
1993 cto->ct_flags |= CT_NODISC;
1994 }
1995 if (cso->dxfer_len == 0) {
1996 cto->ct_flags |= CT_NO_DATA;
1997 } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1998 cto->ct_flags |= CT_DATA_IN;
1999 } else {
2000 cto->ct_flags |= CT_DATA_OUT;
2001 }
2002 if (ccb->ccb_h.flags & CAM_SEND_STATUS) {
2003 cto->ct_flags |= CT_SENDSTATUS|CT_CCINCR;
2004 cto->ct_scsi_status = cso->scsi_status;
2005 cto->ct_resid = cso->resid;
1776 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: CTIO[%x] scsi status %x resid %d tag_id %x\n", __func__,
2006 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO[%x] scsi status %x resid %d tag_id %x", __func__,
1777 cto->ct_fwhandle, cso->scsi_status, cso->resid, cso->tag_id);
1778 }
1779 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1780 cto->ct_timeout = 10;
1781 }
1782
1783 if (isp_allocate_xs_tgt(isp, ccb, &handle)) {
2007 cto->ct_fwhandle, cso->scsi_status, cso->resid, cso->tag_id);
2008 }
2009 ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
2010 cto->ct_timeout = 10;
2011 }
2012
2013 if (isp_allocate_xs_tgt(isp, ccb, &handle)) {
1784 xpt_print(ccb->ccb_h.path, "No XFLIST pointers for %s\n", __func__);
1785 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1786 goto out;
2014 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "No XFLIST pointers for %s\n", __func__);
2015 goto restart_delay;
1787 }
1788
2016 }
2017
1789
1790 /*
1791 * Call the dma setup routines for this entry (and any subsequent
1792 * CTIOs) if there's data to move, and then tell the f/w it's got
1793 * new things to play with. As with isp_start's usage of DMA setup,
1794 * any swizzling is done in the machine dependent layer. Because
1795 * of this, we put the request onto the queue area first in native
1796 * format.
1797 */

--- 7 unchanged lines hidden (view full) ---

1805 } else {
1806 ct_entry_t *cto = (ct_entry_t *) local;
1807 cto->ct_syshandle = handle;
1808 }
1809
1810 dmaresult = ISP_DMASETUP(isp, cso, (ispreq_t *) local);
1811 if (dmaresult == CMD_QUEUED) {
1812 isp->isp_nactive++;
2018 /*
2019 * Call the dma setup routines for this entry (and any subsequent
2020 * CTIOs) if there's data to move, and then tell the f/w it's got
2021 * new things to play with. As with isp_start's usage of DMA setup,
2022 * any swizzling is done in the machine dependent layer. Because
2023 * of this, we put the request onto the queue area first in native
2024 * format.
2025 */

--- 7 unchanged lines hidden (view full) ---

2033 } else {
2034 ct_entry_t *cto = (ct_entry_t *) local;
2035 cto->ct_syshandle = handle;
2036 }
2037
2038 dmaresult = ISP_DMASETUP(isp, cso, (ispreq_t *) local);
2039 if (dmaresult == CMD_QUEUED) {
2040 isp->isp_nactive++;
1813 ccb->ccb_h.status |= CAM_SIM_QUEUED;
2041 if (xfrlen) {
2042 ccb->ccb_h.spriv_field0 = atp->bytes_xfered;
2043 } else {
2044 ccb->ccb_h.spriv_field0 = ~0;
2045 }
2046 ccb->ccb_h.status = CAM_REQ_INPROG | CAM_SIM_QUEUED;
2047 atp->ctcnt++;
1814 rls_lun_statep(isp, tptr);
1815 return;
1816 }
2048 rls_lun_statep(isp, tptr);
2049 return;
2050 }
1817 if (dmaresult == CMD_EAGAIN) {
1818 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1819 } else {
2051 isp_destroy_tgt_handle(isp, handle);
2052 if (dmaresult != CMD_EAGAIN) {
1820 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2053 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2054 goto out;
1821 }
2055 }
1822 isp_destroy_tgt_handle(isp, handle);
2056restart_delay:
2057 cam_freeze_devq(ccb->ccb_h.path);
2058 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
2059 ccb->ccb_h.status = CAM_REQUEUE_REQ;
1823out:
1824 rls_lun_statep(isp, tptr);
1825 isp_free_pcmd(isp, ccb);
1826 xpt_done(ccb);
1827}
1828
1829static void
1830isp_refire_putback_atio(void *arg)
1831{
1832 union ccb *ccb = arg;
1833 ispsoftc_t *isp = XS_ISP(ccb);
1834 ISP_LOCK(isp);
1835 isp_target_putback_atio(ccb);
1836 ISP_UNLOCK(isp);
1837}
1838
1839static void
2060out:
2061 rls_lun_statep(isp, tptr);
2062 isp_free_pcmd(isp, ccb);
2063 xpt_done(ccb);
2064}
2065
2066static void
2067isp_refire_putback_atio(void *arg)
2068{
2069 union ccb *ccb = arg;
2070 ispsoftc_t *isp = XS_ISP(ccb);
2071 ISP_LOCK(isp);
2072 isp_target_putback_atio(ccb);
2073 ISP_UNLOCK(isp);
2074}
2075
2076static void
2077isp_refire_notify_ack(void *arg)
2078{
2079 isp_tna_t *tp = arg;
2080 ispsoftc_t *isp = tp->isp;
2081 ISP_LOCK(isp);
2082 if (isp_notify_ack(isp, tp->not)) {
2083 (void) timeout(isp_refire_notify_ack, tp, 5);
2084 } else {
2085 free(tp, M_DEVBUF);
2086 }
2087 ISP_UNLOCK(isp);
2088}
2089
2090
2091static void
1840isp_target_putback_atio(union ccb *ccb)
1841{
1842 ispsoftc_t *isp;
1843 struct ccb_scsiio *cso;
1844 void *qe;
1845
1846 isp = XS_ISP(ccb);
1847

--- 36 unchanged lines hidden (view full) ---

1884 ISP_TDQE(isp, "isp_target_putback_atio", isp->isp_reqidx, qe);
1885 ISP_SYNC_REQUEST(isp);
1886 isp_complete_ctio(ccb);
1887}
1888
1889static void
1890isp_complete_ctio(union ccb *ccb)
1891{
2092isp_target_putback_atio(union ccb *ccb)
2093{
2094 ispsoftc_t *isp;
2095 struct ccb_scsiio *cso;
2096 void *qe;
2097
2098 isp = XS_ISP(ccb);
2099

--- 36 unchanged lines hidden (view full) ---

2136 ISP_TDQE(isp, "isp_target_putback_atio", isp->isp_reqidx, qe);
2137 ISP_SYNC_REQUEST(isp);
2138 isp_complete_ctio(ccb);
2139}
2140
2141static void
2142isp_complete_ctio(union ccb *ccb)
2143{
1892 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
1893 ccb->ccb_h.status |= CAM_REQ_CMP;
2144 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
2145 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
2146 xpt_done(ccb);
1894 }
2147 }
1895 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
1896 isp_free_pcmd(XS_ISP(ccb), ccb);
1897 xpt_done(ccb);
1898}
1899
1900/*
1901 * Handle ATIO stuff that the generic code can't.
1902 * This means handling CDBs.
1903 */
1904
1905static void

--- 64 unchanged lines hidden (view full) ---

1970 ((atp == NULL)? "ATPs" : "ATIOs"), aep->at_lun, aep->at_iid);
1971 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
1972 if (atp) {
1973 isp_put_atpd(isp, tptr, atp);
1974 }
1975 rls_lun_statep(isp, tptr);
1976 return;
1977 }
2148}
2149
2150/*
2151 * Handle ATIO stuff that the generic code can't.
2152 * This means handling CDBs.
2153 */
2154
2155static void

--- 64 unchanged lines hidden (view full) ---

2220 ((atp == NULL)? "ATPs" : "ATIOs"), aep->at_lun, aep->at_iid);
2221 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2222 if (atp) {
2223 isp_put_atpd(isp, tptr, atp);
2224 }
2225 rls_lun_statep(isp, tptr);
2226 return;
2227 }
1978 atp->tag = aep->at_tag_val;
1979 if (atp->tag == 0) {
1980 atp->tag = ~0;
1981 }
2228 atp->tag = aep->at_handle;
2229 atp->rxid = aep->at_tag_val;
1982 atp->state = ATPD_STATE_ATIO;
1983 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
1984 tptr->atio_count--;
2230 atp->state = ATPD_STATE_ATIO;
2231 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2232 tptr->atio_count--;
1985 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2233 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
1986 atiop->ccb_h.target_id = aep->at_tgt;
1987 atiop->ccb_h.target_lun = aep->at_lun;
1988 if (aep->at_flags & AT_NODISC) {
1989 atiop->ccb_h.flags = CAM_DIS_DISCONNECT;
1990 } else {
1991 atiop->ccb_h.flags = 0;
1992 }
1993

--- 23 unchanged lines hidden (view full) ---

2017 atp->last_xframt = 0;
2018 atp->lun = aep->at_lun;
2019 atp->nphdl = aep->at_iid;
2020 atp->portid = PORT_NONE;
2021 atp->oxid = 0;
2022 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2023 atp->tattr = aep->at_tag_type;
2024 atp->state = ATPD_STATE_CAM;
2234 atiop->ccb_h.target_id = aep->at_tgt;
2235 atiop->ccb_h.target_lun = aep->at_lun;
2236 if (aep->at_flags & AT_NODISC) {
2237 atiop->ccb_h.flags = CAM_DIS_DISCONNECT;
2238 } else {
2239 atiop->ccb_h.flags = 0;
2240 }
2241

--- 23 unchanged lines hidden (view full) ---

2265 atp->last_xframt = 0;
2266 atp->lun = aep->at_lun;
2267 atp->nphdl = aep->at_iid;
2268 atp->portid = PORT_NONE;
2269 atp->oxid = 0;
2270 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2271 atp->tattr = aep->at_tag_type;
2272 atp->state = ATPD_STATE_CAM;
2025 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, tptr->owner, "ATIO[%x] CDB=0x%x lun %d\n", aep->at_tag_val, atp->cdb0, atp->lun);
2273 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO[0x%x] CDB=0x%x lun %d", aep->at_tag_val, atp->cdb0, atp->lun);
2026 rls_lun_statep(isp, tptr);
2027}
2028
2029static void
2030isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
2031{
2032 lun_id_t lun;
2033 fcportdb_t *lp;

--- 24 unchanged lines hidden (view full) ---

2058 nphdl = ((at2e_entry_t *)aep)->at_iid;
2059 } else {
2060 nphdl = aep->at_iid;
2061 }
2062 tptr = get_lun_statep(isp, 0, lun);
2063 if (tptr == NULL) {
2064 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
2065 if (tptr == NULL) {
2274 rls_lun_statep(isp, tptr);
2275}
2276
2277static void
2278isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
2279{
2280 lun_id_t lun;
2281 fcportdb_t *lp;

--- 24 unchanged lines hidden (view full) ---

2306 nphdl = ((at2e_entry_t *)aep)->at_iid;
2307 } else {
2308 nphdl = aep->at_iid;
2309 }
2310 tptr = get_lun_statep(isp, 0, lun);
2311 if (tptr == NULL) {
2312 tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD);
2313 if (tptr == NULL) {
2066 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] no state pointer for lun %d", aep->at_rxid, lun);
2067 isp_endcmd(isp, aep, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2314 isp_prt(isp, ISP_LOGWARN, "%s: [0x%x] no state pointer for lun %d or wildcard", __func__, aep->at_rxid, lun);
2315 if (lun == 0) {
2316 isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0);
2317 } else {
2318 isp_endcmd(isp, aep, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2319 }
2068 return;
2069 }
2070 }
2071
2072 /*
2073 * Start any commands pending resources first.
2074 */
2075 if (tptr->restart_queue) {

--- 31 unchanged lines hidden (view full) ---

2107 if (atp == NULL) {
2108 goto noresrc;
2109 }
2110
2111 atp->tag = aep->at_rxid;
2112 atp->state = ATPD_STATE_ATIO;
2113 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2114 tptr->atio_count--;
2320 return;
2321 }
2322 }
2323
2324 /*
2325 * Start any commands pending resources first.
2326 */
2327 if (tptr->restart_queue) {

--- 31 unchanged lines hidden (view full) ---

2359 if (atp == NULL) {
2360 goto noresrc;
2361 }
2362
2363 atp->tag = aep->at_rxid;
2364 atp->state = ATPD_STATE_ATIO;
2365 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2366 tptr->atio_count--;
2115 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2367 isp_prt(isp, ISP_LOGTDEBUG2, "Take FREE ATIO count now %d", tptr->atio_count);
2116 atiop->ccb_h.target_id = FCPARAM(isp, 0)->isp_loopid;
2117 atiop->ccb_h.target_lun = lun;
2118
2119 /*
2120 * We don't get 'suggested' sense data as we do with SCSI cards.
2121 */
2122 atiop->sense_len = 0;
2123 if (ISP_CAP_2KLOGIN(isp)) {

--- 17 unchanged lines hidden (view full) ---

2141 (((uint64_t) aep->at_wwpn[3]) << 0);
2142 /*
2143 * However, make sure we delete ourselves if otherwise
2144 * we were there but at a different loop id.
2145 */
2146 if (isp_find_pdb_by_wwn(isp, 0, iid, &lp)) {
2147 isp_del_wwn_entry(isp, 0, iid, lp->handle, lp->portid);
2148 }
2368 atiop->ccb_h.target_id = FCPARAM(isp, 0)->isp_loopid;
2369 atiop->ccb_h.target_lun = lun;
2370
2371 /*
2372 * We don't get 'suggested' sense data as we do with SCSI cards.
2373 */
2374 atiop->sense_len = 0;
2375 if (ISP_CAP_2KLOGIN(isp)) {

--- 17 unchanged lines hidden (view full) ---

2393 (((uint64_t) aep->at_wwpn[3]) << 0);
2394 /*
2395 * However, make sure we delete ourselves if otherwise
2396 * we were there but at a different loop id.
2397 */
2398 if (isp_find_pdb_by_wwn(isp, 0, iid, &lp)) {
2399 isp_del_wwn_entry(isp, 0, iid, lp->handle, lp->portid);
2400 }
2149 isp_add_wwn_entry(isp, 0, iid, atiop->init_id, PORT_ANY);
2401 isp_add_wwn_entry(isp, 0, iid, atiop->init_id, PORT_ANY, 0);
2150 }
2151 atiop->cdb_len = ATIO2_CDBLEN;
2152 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
2153 atiop->ccb_h.status = CAM_CDB_RECVD;
2154 atiop->tag_id = atp->tag;
2155 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
2156 case ATIO2_TC_ATTR_SIMPLEQ:
2157 atiop->ccb_h.flags = CAM_TAG_ACTION_VALID;

--- 20 unchanged lines hidden (view full) ---

2178 atp->lun = lun;
2179 atp->nphdl = atiop->init_id;
2180 atp->sid = PORT_ANY;
2181 atp->oxid = aep->at_oxid;
2182 atp->cdb0 = aep->at_cdb[0];
2183 atp->tattr = aep->at_taskflags & ATIO2_TC_ATTR_MASK;
2184 atp->state = ATPD_STATE_CAM;
2185 xpt_done((union ccb *)atiop);
2402 }
2403 atiop->cdb_len = ATIO2_CDBLEN;
2404 ISP_MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN);
2405 atiop->ccb_h.status = CAM_CDB_RECVD;
2406 atiop->tag_id = atp->tag;
2407 switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) {
2408 case ATIO2_TC_ATTR_SIMPLEQ:
2409 atiop->ccb_h.flags = CAM_TAG_ACTION_VALID;

--- 20 unchanged lines hidden (view full) ---

2430 atp->lun = lun;
2431 atp->nphdl = atiop->init_id;
2432 atp->sid = PORT_ANY;
2433 atp->oxid = aep->at_oxid;
2434 atp->cdb0 = aep->at_cdb[0];
2435 atp->tattr = aep->at_taskflags & ATIO2_TC_ATTR_MASK;
2436 atp->state = ATPD_STATE_CAM;
2437 xpt_done((union ccb *)atiop);
2186 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, tptr->owner, "ATIO2[%x] CDB=0x%x lun %d datalen %u\n", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2438 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO2[0x%x] CDB=0x%x lun %d datalen %u", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2187 rls_lun_statep(isp, tptr);
2188 return;
2189noresrc:
2190 ntp = isp_get_ntpd(isp, tptr);
2191 if (ntp == NULL) {
2192 rls_lun_statep(isp, tptr);
2193 isp_endcmd(isp, aep, nphdl, 0, SCSI_STATUS_BUSY, 0);
2194 return;

--- 81 unchanged lines hidden (view full) ---

2276
2277 /*
2278 * Get the tstate pointer
2279 */
2280 tptr = get_lun_statep(isp, chan, lun);
2281 if (tptr == NULL) {
2282 tptr = get_lun_statep(isp, chan, CAM_LUN_WILDCARD);
2283 if (tptr == NULL) {
2439 rls_lun_statep(isp, tptr);
2440 return;
2441noresrc:
2442 ntp = isp_get_ntpd(isp, tptr);
2443 if (ntp == NULL) {
2444 rls_lun_statep(isp, tptr);
2445 isp_endcmd(isp, aep, nphdl, 0, SCSI_STATUS_BUSY, 0);
2446 return;

--- 81 unchanged lines hidden (view full) ---

2528
2529 /*
2530 * Get the tstate pointer
2531 */
2532 tptr = get_lun_statep(isp, chan, lun);
2533 if (tptr == NULL) {
2534 tptr = get_lun_statep(isp, chan, CAM_LUN_WILDCARD);
2535 if (tptr == NULL) {
2284 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] no state pointer for lun %d or wildcard", aep->at_rxid, lun);
2285 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2536 isp_prt(isp, ISP_LOGWARN, "%s: [0x%x] no state pointer for lun %d or wildcard", __func__, aep->at_rxid, lun);
2537 if (lun == 0) {
2538 isp_endcmd(isp, aep, nphdl, SCSI_STATUS_BUSY, 0);
2539 } else {
2540 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_CHECK_COND | ECMD_SVALID | (0x5 << 12) | (0x25 << 16), 0);
2541 }
2286 return;
2287 }
2288 }
2289
2290 /*
2291 * Start any commands pending resources first.
2292 */
2293 if (tptr->restart_queue) {

--- 45 unchanged lines hidden (view full) ---

2339
2340 atp = isp_get_atpd(isp, tptr, 0);
2341 if (atp == NULL) {
2342 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atps", aep->at_rxid);
2343 goto noresrc;
2344 }
2345 oatp = isp_get_atpd(isp, tptr, aep->at_rxid);
2346 if (oatp) {
2542 return;
2543 }
2544 }
2545
2546 /*
2547 * Start any commands pending resources first.
2548 */
2549 if (tptr->restart_queue) {

--- 45 unchanged lines hidden (view full) ---

2595
2596 atp = isp_get_atpd(isp, tptr, 0);
2597 if (atp == NULL) {
2598 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] out of atps", aep->at_rxid);
2599 goto noresrc;
2600 }
2601 oatp = isp_get_atpd(isp, tptr, aep->at_rxid);
2602 if (oatp) {
2347 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] tag wraparound in isp_handle_platforms_atio7 (N-Port Handle 0x%04x S_ID 0x%04x OX_ID 0x%04x) oatp state %d\n",
2603 isp_prt(isp, ISP_LOGTDEBUG0, "[0x%x] tag wraparound in isp_handle_platforms_atio7 (N-Port Handle 0x%04x S_ID 0x%04x OX_ID 0x%04x) oatp state %d",
2348 aep->at_rxid, nphdl, sid, aep->at_hdr.ox_id, oatp->state);
2349 /*
2350 * It's not a "no resource" condition- but we can treat it like one
2351 */
2352 goto noresrc;
2353 }
2604 aep->at_rxid, nphdl, sid, aep->at_hdr.ox_id, oatp->state);
2605 /*
2606 * It's not a "no resource" condition- but we can treat it like one
2607 */
2608 goto noresrc;
2609 }
2610 atp->word3 = lp->prli_word3;
2354 atp->tag = aep->at_rxid;
2355 atp->state = ATPD_STATE_ATIO;
2356 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2357 tptr->atio_count--;
2611 atp->tag = aep->at_rxid;
2612 atp->state = ATPD_STATE_ATIO;
2613 SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle);
2614 tptr->atio_count--;
2358 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2615 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, atiop->ccb_h.path, "Take FREE ATIO count now %d\n", tptr->atio_count);
2359 atiop->init_id = nphdl;
2360 atiop->ccb_h.target_id = FCPARAM(isp, chan)->isp_loopid;
2361 atiop->ccb_h.target_lun = lun;
2362 atiop->sense_len = 0;
2363 cdbxlen = aep->at_cmnd.fcp_cmnd_alen_datadir >> FCP_CMND_ADDTL_CDBLEN_SHIFT;
2364 if (cdbxlen) {
2365 isp_prt(isp, ISP_LOGWARN, "additional CDBLEN ignored");
2366 }

--- 28 unchanged lines hidden (view full) ---

2395 atp->lun = lun;
2396 atp->nphdl = nphdl;
2397 atp->portid = sid;
2398 atp->oxid = aep->at_hdr.ox_id;
2399 atp->rxid = aep->at_hdr.rx_id;
2400 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2401 atp->tattr = aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK;
2402 atp->state = ATPD_STATE_CAM;
2616 atiop->init_id = nphdl;
2617 atiop->ccb_h.target_id = FCPARAM(isp, chan)->isp_loopid;
2618 atiop->ccb_h.target_lun = lun;
2619 atiop->sense_len = 0;
2620 cdbxlen = aep->at_cmnd.fcp_cmnd_alen_datadir >> FCP_CMND_ADDTL_CDBLEN_SHIFT;
2621 if (cdbxlen) {
2622 isp_prt(isp, ISP_LOGWARN, "additional CDBLEN ignored");
2623 }

--- 28 unchanged lines hidden (view full) ---

2652 atp->lun = lun;
2653 atp->nphdl = nphdl;
2654 atp->portid = sid;
2655 atp->oxid = aep->at_hdr.ox_id;
2656 atp->rxid = aep->at_hdr.rx_id;
2657 atp->cdb0 = atiop->cdb_io.cdb_bytes[0];
2658 atp->tattr = aep->at_cmnd.fcp_cmnd_task_attribute & FCP_CMND_TASK_ATTR_MASK;
2659 atp->state = ATPD_STATE_CAM;
2403 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, tptr->owner, "ATIO7[%x] CDB=0x%x lun %d datalen %u\n", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2660 isp_prt(isp, ISP_LOGTDEBUG0, "ATIO7[0x%x] CDB=0x%x lun %d datalen %u", aep->at_rxid, atp->cdb0, lun, atp->orig_datalen);
2404 xpt_done((union ccb *)atiop);
2405 rls_lun_statep(isp, tptr);
2406 return;
2407noresrc:
2408 if (atp) {
2409 isp_put_atpd(isp, tptr, atp);
2410 }
2411 ntp = isp_get_ntpd(isp, tptr);
2412 if (ntp == NULL) {
2413 rls_lun_statep(isp, tptr);
2414 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
2415 return;
2416 }
2417 memcpy(ntp->rd.data, aep, QENTRY_LEN);
2418 ntp->rd.nt.nt_hba = tptr->restart_queue;
2419 tptr->restart_queue = ntp;
2420 rls_lun_statep(isp, tptr);
2421}
2422
2661 xpt_done((union ccb *)atiop);
2662 rls_lun_statep(isp, tptr);
2663 return;
2664noresrc:
2665 if (atp) {
2666 isp_put_atpd(isp, tptr, atp);
2667 }
2668 ntp = isp_get_ntpd(isp, tptr);
2669 if (ntp == NULL) {
2670 rls_lun_statep(isp, tptr);
2671 isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
2672 return;
2673 }
2674 memcpy(ntp->rd.data, aep, QENTRY_LEN);
2675 ntp->rd.nt.nt_hba = tptr->restart_queue;
2676 tptr->restart_queue = ntp;
2677 rls_lun_statep(isp, tptr);
2678}
2679
2680
2681/*
2682 * Handle starting an SRR (sequence retransmit request)
2683 * We get here when we've gotten the immediate notify
2684 * and the return of all outstanding CTIOs for this
2685 * transaction.
2686 */
2423static void
2687static void
2688isp_handle_srr_start(ispsoftc_t *isp, tstate_t *tptr, atio_private_data_t *atp)
2689{
2690 in_fcentry_24xx_t *inot;
2691 uint32_t srr_off, ccb_off, ccb_len, ccb_end;
2692 union ccb *ccb;
2693
2694 inot = (in_fcentry_24xx_t *)atp->srr;
2695 srr_off = inot->in_srr_reloff_lo | (inot->in_srr_reloff_hi << 16);
2696 ccb = atp->srr_ccb;
2697 atp->srr_ccb = NULL;
2698 atp->nsrr++;
2699 if (ccb == NULL) {
2700 isp_prt(isp, ISP_LOGWARN, "SRR[0x%08x] null ccb", atp->tag);
2701 goto fail;
2702 }
2703
2704 ccb_off = ccb->ccb_h.spriv_field0;
2705 ccb_len = ccb->csio.dxfer_len;
2706 ccb_end = (ccb_off == ~0)? ~0 : ccb_off + ccb_len;
2707
2708 switch (inot->in_srr_iu) {
2709 case R_CTL_INFO_SOLICITED_DATA:
2710 /*
2711 * We have to restart a FCP_DATA data out transaction
2712 */
2713 atp->sendst = 0;
2714 atp->last_xframt = 0;
2715 atp->bytes_xfered = srr_off;
2716 if (ccb_len == 0) {
2717 isp_prt(isp, ISP_LOGWARN, "SRR[0x%08x] SRR offset 0x%x but current CCB doesn't transfer data", atp->tag, srr_off);
2718 goto mdp;
2719 }
2720 if (srr_off < ccb_off || ccb_off > srr_off + ccb_len) {
2721 isp_prt(isp, ISP_LOGWARN, "SRR[0x%08x] SRR offset 0x%x not covered by current CCB data range [0x%x..0x%x]", atp->tag, srr_off, ccb_off, ccb_end);
2722 goto mdp;
2723 }
2724 isp_prt(isp, ISP_LOGWARN, "SRR[0x%08x] SRR offset 0x%x covered by current CCB data range [0x%x..0x%x]", atp->tag, srr_off, ccb_off, ccb_end);
2725 break;
2726 case R_CTL_INFO_COMMAND_STATUS:
2727 isp_prt(isp, ISP_LOGTINFO, "SRR[0x%08x] Got an FCP RSP SRR- resending status", atp->tag);
2728 atp->sendst = 1;
2729 /*
2730 * We have to restart a FCP_RSP IU transaction
2731 */
2732 break;
2733 case R_CTL_INFO_DATA_DESCRIPTOR:
2734 /*
2735 * We have to restart an FCP DATA in transaction
2736 */
2737 isp_prt(isp, ISP_LOGWARN, "Got an FCP DATA IN SRR- dropping");
2738 goto fail;
2739
2740 default:
2741 isp_prt(isp, ISP_LOGWARN, "Got an unknown information (%x) SRR- dropping", inot->in_srr_iu);
2742 goto fail;
2743 }
2744
2745 /*
2746 * We can't do anything until this is acked, so we might as well start it now.
2747 * We aren't going to do the usual asynchronous ack issue because we need
2748 * to make sure this gets on the wire first.
2749 */
2750 if (isp_notify_ack(isp, inot)) {
2751 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
2752 goto fail;
2753 }
2754 isp_target_start_ctio(isp, ccb, FROM_SRR);
2755 return;
2756fail:
2757 inot->in_reserved = 1;
2758 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2759 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2760 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2761 isp_complete_ctio(ccb);
2762 return;
2763mdp:
2764 if (isp_notify_ack(isp, inot)) {
2765 isp_prt(isp, ISP_LOGWARN, "could not push positive ack for SRR- you lose");
2766 goto fail;
2767 }
2768 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2769 ccb->ccb_h.status = CAM_MESSAGE_RECV;
2770 /*
2771 * This is not a strict interpretation of MDP, but it's close
2772 */
2773 ccb->csio.msg_ptr = &ccb->csio.sense_data.sense_buf[SSD_FULL_SIZE - 16];
2774 ccb->csio.msg_len = 7;
2775 ccb->csio.msg_ptr[0] = MSG_EXTENDED;
2776 ccb->csio.msg_ptr[1] = 5;
2777 ccb->csio.msg_ptr[2] = 0; /* modify data pointer */
2778 ccb->csio.msg_ptr[3] = srr_off >> 24;
2779 ccb->csio.msg_ptr[4] = srr_off >> 16;
2780 ccb->csio.msg_ptr[5] = srr_off >> 8;
2781 ccb->csio.msg_ptr[6] = srr_off;
2782 isp_complete_ctio(ccb);
2783}
2784
2785
2786static void
2787isp_handle_srr_notify(ispsoftc_t *isp, void *inot_raw)
2788{
2789 tstate_t *tptr;
2790 in_fcentry_24xx_t *inot = inot_raw;
2791 atio_private_data_t *atp;
2792 uint32_t tag = inot->in_rxid;
2793 uint32_t bus = inot->in_vpidx;
2794
2795 if (!IS_24XX(isp)) {
2796 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot_raw);
2797 return;
2798 }
2799
2800 tptr = get_lun_statep_from_tag(isp, bus, tag);
2801 if (tptr == NULL) {
2802 isp_prt(isp, ISP_LOGERR, "%s: cannot find tptr for tag %x in SRR Notify", __func__, tag);
2803 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2804 return;
2805 }
2806 atp = isp_get_atpd(isp, tptr, tag);
2807 if (atp == NULL) {
2808 rls_lun_statep(isp, tptr);
2809 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x in SRR Notify", __func__, tag);
2810 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2811 return;
2812 }
2813 atp->srr_notify_rcvd = 1;
2814 memcpy(atp->srr, inot, sizeof (atp->srr));
2815 isp_prt(isp, ISP_LOGTINFO /* ISP_LOGTDEBUG0 */, "SRR[0x%08x] inot->in_rxid flags 0x%x srr_iu=%x reloff 0x%x", inot->in_rxid, inot->in_flags, inot->in_srr_iu,
2816 inot->in_srr_reloff_lo | (inot->in_srr_reloff_hi << 16));
2817 if (atp->srr_ccb)
2818 isp_handle_srr_start(isp, tptr, atp);
2819 rls_lun_statep(isp, tptr);
2820}
2821
2822static void
2424isp_handle_platform_ctio(ispsoftc_t *isp, void *arg)
2425{
2426 union ccb *ccb;
2823isp_handle_platform_ctio(ispsoftc_t *isp, void *arg)
2824{
2825 union ccb *ccb;
2427 int sentstatus, ok, notify_cam, resid = 0;
2826 int sentstatus = 0, ok = 0, notify_cam = 0, resid = 0, moved_data = 0, failure = 0;
2428 tstate_t *tptr = NULL;
2429 atio_private_data_t *atp = NULL;
2430 int bus;
2827 tstate_t *tptr = NULL;
2828 atio_private_data_t *atp = NULL;
2829 int bus;
2431 uint32_t tval, handle;
2830 uint32_t handle;
2432
2433 /*
2434 * CTIO handles are 16 bits.
2435 * CTIO2 and CTIO7 are 32 bits.
2436 */
2437
2438 if (IS_SCSI(isp)) {
2439 handle = ((ct_entry_t *)arg)->ct_syshandle;
2440 } else {
2441 handle = ((ct2_entry_t *)arg)->ct_syshandle;
2442 }
2443 ccb = isp_find_xs_tgt(isp, handle);
2444 if (ccb == NULL) {
2445 isp_print_bytes(isp, "null ccb in isp_handle_platform_ctio", QENTRY_LEN, arg);
2446 return;
2447 }
2448 isp_destroy_tgt_handle(isp, handle);
2831
2832 /*
2833 * CTIO handles are 16 bits.
2834 * CTIO2 and CTIO7 are 32 bits.
2835 */
2836
2837 if (IS_SCSI(isp)) {
2838 handle = ((ct_entry_t *)arg)->ct_syshandle;
2839 } else {
2840 handle = ((ct2_entry_t *)arg)->ct_syshandle;
2841 }
2842 ccb = isp_find_xs_tgt(isp, handle);
2843 if (ccb == NULL) {
2844 isp_print_bytes(isp, "null ccb in isp_handle_platform_ctio", QENTRY_LEN, arg);
2845 return;
2846 }
2847 isp_destroy_tgt_handle(isp, handle);
2848 isp_free_pcmd(isp, ccb);
2849 if (isp->isp_nactive) {
2850 isp->isp_nactive--;
2851 }
2852
2449 bus = XS_CHANNEL(ccb);
2450 tptr = get_lun_statep(isp, bus, XS_LUN(ccb));
2451 if (tptr == NULL) {
2452 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
2453 }
2853 bus = XS_CHANNEL(ccb);
2854 tptr = get_lun_statep(isp, bus, XS_LUN(ccb));
2855 if (tptr == NULL) {
2856 tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD);
2857 }
2454 KASSERT((tptr != NULL), ("cannot get state pointer"));
2455 if (isp->isp_nactive) {
2456 isp->isp_nactive++;
2858 if (tptr == NULL) {
2859 isp_prt(isp, ISP_LOGERR, "%s: cannot find tptr for tag %x after I/O", __func__, ccb->csio.tag_id);
2860 return;
2457 }
2861 }
2862
2458 if (IS_24XX(isp)) {
2863 if (IS_24XX(isp)) {
2864 atp = isp_get_atpd(isp, tptr, ((ct7_entry_t *)arg)->ct_rxid);
2865 } else if (IS_FC(isp)) {
2866 atp = isp_get_atpd(isp, tptr, ((ct2_entry_t *)arg)->ct_rxid);
2867 } else {
2868 atp = isp_get_atpd(isp, tptr, ((ct_entry_t *)arg)->ct_fwhandle);
2869 }
2870 if (atp == NULL) {
2871 rls_lun_statep(isp, tptr);
2872 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x after I/O", __func__, ccb->csio.tag_id);
2873 return;
2874 }
2875 KASSERT((atp->ctcnt > 0), ("ctio count not greater than zero"));
2876 atp->ctcnt -= 1;
2877 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2878
2879 if (IS_24XX(isp)) {
2459 ct7_entry_t *ct = arg;
2460
2880 ct7_entry_t *ct = arg;
2881
2461 atp = isp_get_atpd(isp, tptr, ct->ct_rxid);
2462 if (atp == NULL) {
2882 if (ct->ct_nphdl == CT7_SRR) {
2883 atp->srr_ccb = ccb;
2884 if (atp->srr_notify_rcvd)
2885 isp_handle_srr_start(isp, tptr, atp);
2463 rls_lun_statep(isp, tptr);
2886 rls_lun_statep(isp, tptr);
2464 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x after I/O", __func__, ct->ct_rxid);
2465 return;
2466 }
2887 return;
2888 }
2467
2468 sentstatus = ct->ct_flags & CT7_SENDSTATUS;
2469 ok = (ct->ct_nphdl == CT7_OK);
2470 if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
2471 ccb->ccb_h.status |= CAM_SENT_SENSE;
2472 }
2473 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2474 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) {
2475 resid = ct->ct_resid;
2476 atp->bytes_xfered += (atp->last_xframt - resid);
2477 atp->last_xframt = 0;
2478 }
2479 if (ct->ct_nphdl == CT_HBA_RESET) {
2889 if (ct->ct_nphdl == CT_HBA_RESET) {
2480 ok = 0;
2481 notify_cam = 1;
2482 sentstatus = 1;
2483 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
2484 } else if (!ok) {
2485 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2890 failure = CAM_UNREC_HBA_ERROR;
2891 } else {
2892 sentstatus = ct->ct_flags & CT7_SENDSTATUS;
2893 ok = (ct->ct_nphdl == CT7_OK);
2894 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2895 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) {
2896 resid = ct->ct_resid;
2897 moved_data = 1;
2898 }
2486 }
2899 }
2487 tval = atp->tag;
2488 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO7[%x] sts 0x%x flg 0x%x sns %d resid %d %s", __func__,
2489 ct->ct_rxid, ct->ct_nphdl, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
2900 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO7[%x] sts 0x%x flg 0x%x sns %d resid %d %s", __func__,
2901 ct->ct_rxid, ct->ct_nphdl, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
2490 atp->state = ATPD_STATE_PDON; /* XXX: should really come after isp_complete_ctio */
2491 } else if (IS_FC(isp)) {
2492 ct2_entry_t *ct = arg;
2902 } else if (IS_FC(isp)) {
2903 ct2_entry_t *ct = arg;
2493
2494 atp = isp_get_atpd(isp, tptr, ct->ct_rxid);
2495 if (atp == NULL) {
2904 if (ct->ct_status == CT_SRR) {
2905 atp->srr_ccb = ccb;
2906 if (atp->srr_notify_rcvd)
2907 isp_handle_srr_start(isp, tptr, atp);
2496 rls_lun_statep(isp, tptr);
2908 rls_lun_statep(isp, tptr);
2497 isp_prt(isp, ISP_LOGERR, "%s: cannot find adjunct for %x after I/O", __func__, ct->ct_rxid);
2909 isp_target_putback_atio(ccb);
2498 return;
2499 }
2910 return;
2911 }
2500 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
2501 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
2502 if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
2503 ccb->ccb_h.status |= CAM_SENT_SENSE;
2504 }
2505 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2506 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
2507 resid = ct->ct_resid;
2508 atp->bytes_xfered += (atp->last_xframt - resid);
2509 atp->last_xframt = 0;
2510 }
2511 if (ct->ct_status == CT_HBA_RESET) {
2912 if (ct->ct_status == CT_HBA_RESET) {
2512 ok = 0;
2513 notify_cam = 1;
2514 sentstatus = 1;
2515 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
2516 } else if (!ok) {
2517 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2913 failure = CAM_UNREC_HBA_ERROR;
2914 } else {
2915 sentstatus = ct->ct_flags & CT2_SENDSTATUS;
2916 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
2917 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2918 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
2919 resid = ct->ct_resid;
2920 moved_data = 1;
2921 }
2518 }
2519 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO2[%x] sts 0x%x flg 0x%x sns %d resid %d %s", __func__,
2520 ct->ct_rxid, ct->ct_status, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
2922 }
2923 isp_prt(isp, ok? ISP_LOGTDEBUG0 : ISP_LOGWARN, "%s: CTIO2[%x] sts 0x%x flg 0x%x sns %d resid %d %s", __func__,
2924 ct->ct_rxid, ct->ct_status, ct->ct_flags, (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, resid, sentstatus? "FIN" : "MID");
2521 tval = atp->tag;
2522 atp->state = ATPD_STATE_PDON; /* XXX: should really come after isp_complete_ctio */
2523 } else {
2524 ct_entry_t *ct = arg;
2925 } else {
2926 ct_entry_t *ct = arg;
2525 sentstatus = ct->ct_flags & CT_SENDSTATUS;
2526 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
2527 /*
2528 * We *ought* to be able to get back to the original ATIO
2529 * here, but for some reason this gets lost. It's just as
2530 * well because it's squirrelled away as part of periph
2531 * private data.
2532 *
2533 * We can live without it as long as we continue to use
2534 * the auto-replenish feature for CTIOs.
2535 */
2536 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2927
2537 if (ct->ct_status == (CT_HBA_RESET & 0xff)) {
2928 if (ct->ct_status == (CT_HBA_RESET & 0xff)) {
2538 ok = 0;
2539 notify_cam = 1;
2540 sentstatus = 1;
2541 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
2542 } else if (!ok) {
2543 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2544 } else if (ct->ct_status & QLTM_SVALID) {
2545 char *sp = (char *)ct;
2546 sp += CTIO_SENSE_OFFSET;
2547 ccb->csio.sense_len = min(sizeof (ccb->csio.sense_data), QLTM_SENSELEN);
2548 ISP_MEMCPY(&ccb->csio.sense_data, sp, ccb->csio.sense_len);
2549 ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
2929 failure = CAM_UNREC_HBA_ERROR;
2930 } else {
2931 sentstatus = ct->ct_flags & CT_SENDSTATUS;
2932 ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK;
2933 notify_cam = ct->ct_header.rqs_seqno & 0x1;
2550 }
2551 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
2552 resid = ct->ct_resid;
2934 }
2935 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
2936 resid = ct->ct_resid;
2937 moved_data = 1;
2553 }
2554 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO[%x] tag %x S_ID 0x%x lun %d sts %x flg %x resid %d %s", __func__,
2555 ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_lun, ct->ct_status, ct->ct_flags, resid, sentstatus? "FIN" : "MID");
2938 }
2939 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO[%x] tag %x S_ID 0x%x lun %d sts %x flg %x resid %d %s", __func__,
2940 ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_lun, ct->ct_status, ct->ct_flags, resid, sentstatus? "FIN" : "MID");
2556 tval = ct->ct_fwhandle;
2557 }
2941 }
2558 ccb->csio.resid += resid;
2942 if (ok) {
2943 if (moved_data) {
2944 ccb->csio.resid += resid;
2945 atp->bytes_xfered += (atp->last_xframt - resid);
2946 atp->last_xframt = 0;
2947 }
2948 if (sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) {
2949 ccb->ccb_h.status |= CAM_SENT_SENSE;
2950 }
2951 ccb->ccb_h.status |= CAM_REQ_CMP;
2952 } else {
2953 notify_cam = 1;
2954 if (failure == CAM_UNREC_HBA_ERROR)
2955 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
2956 else
2957 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
2958 }
2959 atp->state = ATPD_STATE_PDON;
2960 rls_lun_statep(isp, tptr);
2559
2560 /*
2961
2962 /*
2561 * We're here either because intermediate data transfers are done
2562 * and/or the final status CTIO (which may have joined with a
2563 * Data Transfer) is done.
2564 *
2565 * In any case, for this platform, the upper layers figure out
2566 * what to do next, so all we do here is collect status and
2567 * pass information along. Any DMA handles have already been
2568 * freed.
2963 * We never *not* notify CAM when there has been any error (ok == 0),
2964 * so we never need to do an ATIO putback if we're not notifying CAM.
2569 */
2965 */
2966 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done (notify_cam=%d nowsendstatus=%d)", (sentstatus)? " FINAL " : "MIDTERM ", atp->tag, notify_cam, atp->sendst);
2570 if (notify_cam == 0) {
2967 if (notify_cam == 0) {
2571 isp_prt(isp, ISP_LOGTDEBUG0, " INTER CTIO[0x%x] done", tval);
2968 if (atp->sendst) {
2969 isp_target_start_ctio(isp, ccb, FROM_CTIO_DONE);
2970 }
2572 return;
2573 }
2971 return;
2972 }
2574 if (tptr) {
2575 rls_lun_statep(isp, tptr);
2576 }
2577 isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO[0x%x] done", (sentstatus)? " FINAL " : "MIDTERM ", tval);
2578
2973
2579 if (!ok && !IS_24XX(isp)) {
2580 isp_target_putback_atio(ccb);
2581 } else {
2974 /*
2975 * We're telling CAM we're done with this CTIO transaction.
2976 *
2977 * 24XX cards never need an ATIO put back.
2978 *
2979 * Other cards need one put back only on error.
2980 * In the latter case, a timeout will re-fire
2981 * and try again in case we didn't have
2982 * queue resources to do so at first. In any case,
2983 * once the putback is done we do the completion
2984 * call.
2985 */
2986 if (ok || IS_24XX(isp)) {
2582 isp_complete_ctio(ccb);
2987 isp_complete_ctio(ccb);
2988 } else {
2989 isp_target_putback_atio(ccb);
2583 }
2584}
2585
2586static void
2587isp_handle_platform_notify_scsi(ispsoftc_t *isp, in_entry_t *inot)
2588{
2990 }
2991}
2992
2993static void
2994isp_handle_platform_notify_scsi(ispsoftc_t *isp, in_entry_t *inot)
2995{
2589 (void) isp_notify_ack(isp, inot);
2996 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2590}
2591
2592static void
2593isp_handle_platform_notify_fc(ispsoftc_t *isp, in_fcentry_t *inp)
2594{
2595 int needack = 1;
2596 switch (inp->in_status) {
2597 case IN_PORT_LOGOUT:

--- 46 unchanged lines hidden (view full) ---

2644 atp = isp_get_atpd(isp, tptr, inp->in_seqid);
2645
2646 if (atp) {
2647 inot = (struct ccb_immediate_notify *) SLIST_FIRST(&tptr->inots);
2648 isp_prt(isp, ISP_LOGTDEBUG0, "ABORT TASK RX_ID %x WWN 0x%016llx state %d", inp->in_seqid, (unsigned long long) wwn, atp->state);
2649 if (inot) {
2650 tptr->inot_count--;
2651 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
2997}
2998
2999static void
3000isp_handle_platform_notify_fc(ispsoftc_t *isp, in_fcentry_t *inp)
3001{
3002 int needack = 1;
3003 switch (inp->in_status) {
3004 case IN_PORT_LOGOUT:

--- 46 unchanged lines hidden (view full) ---

3051 atp = isp_get_atpd(isp, tptr, inp->in_seqid);
3052
3053 if (atp) {
3054 inot = (struct ccb_immediate_notify *) SLIST_FIRST(&tptr->inots);
3055 isp_prt(isp, ISP_LOGTDEBUG0, "ABORT TASK RX_ID %x WWN 0x%016llx state %d", inp->in_seqid, (unsigned long long) wwn, atp->state);
3056 if (inot) {
3057 tptr->inot_count--;
3058 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
2652 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
3059 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
2653 } else {
3060 } else {
2654 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, tptr->owner, "out of INOT structures\n");
3061 ISP_PATH_PRT(isp, ISP_LOGWARN, tptr->owner, "out of INOT structures\n");
2655 }
2656 } else {
2657 ISP_PATH_PRT(isp, ISP_LOGWARN, tptr->owner, "abort task RX_ID %x from wwn 0x%016llx, state unknown\n", inp->in_seqid, wwn);
2658 }
2659 if (inot) {
2660 isp_notify_t tmp, *nt = &tmp;
2661 ISP_MEMZERO(nt, sizeof (isp_notify_t));
2662 nt->nt_hba = isp;

--- 12 unchanged lines hidden (view full) ---

2675 }
2676 rls_lun_statep(isp, tptr);
2677 break;
2678 }
2679 default:
2680 break;
2681 }
2682 if (needack) {
3062 }
3063 } else {
3064 ISP_PATH_PRT(isp, ISP_LOGWARN, tptr->owner, "abort task RX_ID %x from wwn 0x%016llx, state unknown\n", inp->in_seqid, wwn);
3065 }
3066 if (inot) {
3067 isp_notify_t tmp, *nt = &tmp;
3068 ISP_MEMZERO(nt, sizeof (isp_notify_t));
3069 nt->nt_hba = isp;

--- 12 unchanged lines hidden (view full) ---

3082 }
3083 rls_lun_statep(isp, tptr);
3084 break;
3085 }
3086 default:
3087 break;
3088 }
3089 if (needack) {
2683 (void) isp_notify_ack(isp, inp);
3090 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp);
2684 }
2685}
2686
2687static void
2688isp_handle_platform_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot)
2689{
2690 uint16_t nphdl;
3091 }
3092}
3093
3094static void
3095isp_handle_platform_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot)
3096{
3097 uint16_t nphdl;
3098 uint16_t prli_options = 0;
2691 uint32_t portid;
2692 fcportdb_t *lp;
2693 uint8_t *ptr = NULL;
2694 uint64_t wwn;
2695
2696 nphdl = inot->in_nphdl;
2697 if (nphdl != NIL_HANDLE) {
2698 portid = inot->in_portid_hi << 16 | inot->in_portid_lo;

--- 33 unchanged lines hidden (view full) ---

2732 case PRLO:
2733 msg = "PRLO";
2734 break;
2735 case PLOGI:
2736 case PRLI:
2737 /*
2738 * Treat PRLI the same as PLOGI and make a database entry for it.
2739 */
3099 uint32_t portid;
3100 fcportdb_t *lp;
3101 uint8_t *ptr = NULL;
3102 uint64_t wwn;
3103
3104 nphdl = inot->in_nphdl;
3105 if (nphdl != NIL_HANDLE) {
3106 portid = inot->in_portid_hi << 16 | inot->in_portid_lo;

--- 33 unchanged lines hidden (view full) ---

3140 case PRLO:
3141 msg = "PRLO";
3142 break;
3143 case PLOGI:
3144 case PRLI:
3145 /*
3146 * Treat PRLI the same as PLOGI and make a database entry for it.
3147 */
2740 if (inot->in_status_subcode == PLOGI)
3148 if (inot->in_status_subcode == PLOGI) {
2741 msg = "PLOGI";
3149 msg = "PLOGI";
2742 else
3150 } else {
3151 prli_options = inot->in_prli_options;
2743 msg = "PRLI";
3152 msg = "PRLI";
3153 }
2744 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25)) {
2745 ptr = (uint8_t *)inot; /* point to unswizzled entry! */
2746 wwn = (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF]) << 56) |
2747 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+1]) << 48) |
2748 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+2]) << 40) |
2749 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+3]) << 32) |
2750 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+4]) << 24) |
2751 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+5]) << 16) |
2752 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+6]) << 8) |
2753 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+7]));
2754 } else {
2755 wwn = INI_NONE;
2756 }
3154 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25)) {
3155 ptr = (uint8_t *)inot; /* point to unswizzled entry! */
3156 wwn = (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF]) << 56) |
3157 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+1]) << 48) |
3158 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+2]) << 40) |
3159 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+3]) << 32) |
3160 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+4]) << 24) |
3161 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+5]) << 16) |
3162 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+6]) << 8) |
3163 (((uint64_t) ptr[IN24XX_PLOGI_WWPN_OFF+7]));
3164 } else {
3165 wwn = INI_NONE;
3166 }
2757 isp_add_wwn_entry(isp, chan, wwn, nphdl, portid);
3167 isp_add_wwn_entry(isp, chan, wwn, nphdl, portid, prli_options);
2758 break;
2759 case PDISC:
2760 msg = "PDISC";
2761 break;
2762 case ADISC:
2763 msg = "ADISC";
2764 break;
2765 default:
2766 ISP_SNPRINTF(buf, sizeof (buf), "ELS 0x%x", inot->in_status_subcode);
2767 msg = buf;
2768 break;
2769 }
2770 if (inot->in_flags & IN24XX_FLAG_PUREX_IOCB) {
2771 isp_prt(isp, ISP_LOGERR, "%s Chan %d ELS N-port handle %x PortID 0x%06x marked as needing a PUREX response", msg, chan, nphdl, portid);
2772 break;
2773 }
2774 isp_prt(isp, ISP_LOGTDEBUG0, "%s Chan %d ELS N-port handle %x PortID 0x%06x RX_ID 0x%x OX_ID 0x%x", msg, chan, nphdl, portid,
2775 inot->in_rxid, inot->in_oxid);
3168 break;
3169 case PDISC:
3170 msg = "PDISC";
3171 break;
3172 case ADISC:
3173 msg = "ADISC";
3174 break;
3175 default:
3176 ISP_SNPRINTF(buf, sizeof (buf), "ELS 0x%x", inot->in_status_subcode);
3177 msg = buf;
3178 break;
3179 }
3180 if (inot->in_flags & IN24XX_FLAG_PUREX_IOCB) {
3181 isp_prt(isp, ISP_LOGERR, "%s Chan %d ELS N-port handle %x PortID 0x%06x marked as needing a PUREX response", msg, chan, nphdl, portid);
3182 break;
3183 }
3184 isp_prt(isp, ISP_LOGTDEBUG0, "%s Chan %d ELS N-port handle %x PortID 0x%06x RX_ID 0x%x OX_ID 0x%x", msg, chan, nphdl, portid,
3185 inot->in_rxid, inot->in_oxid);
2776 (void) isp_notify_ack(isp, inot);
3186 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2777 break;
2778 }
2779
2780 case IN24XX_PORT_LOGOUT:
2781 ptr = "PORT LOGOUT";
2782 if (isp_find_pdb_by_loopid(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), nphdl, &lp)) {
2783 isp_del_wwn_entry(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), lp->port_wwn, nphdl, lp->portid);
2784 }

--- 10 unchanged lines hidden (view full) ---

2795 isp_prt(isp, ISP_LOGINFO, "Chan %d %s (sub-status 0x%x) for N-port handle 0x%x", ISP_GET_VPIDX(isp, inot->in_vpidx), ptr, inot->in_status_subcode, nphdl);
2796
2797 /*
2798 * All subcodes here are irrelevant. What is relevant
2799 * is that we need to terminate all active commands from
2800 * this initiator (known by N-port handle).
2801 */
2802 /* XXX IMPLEMENT XXX */
3187 break;
3188 }
3189
3190 case IN24XX_PORT_LOGOUT:
3191 ptr = "PORT LOGOUT";
3192 if (isp_find_pdb_by_loopid(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), nphdl, &lp)) {
3193 isp_del_wwn_entry(isp, ISP_GET_VPIDX(isp, inot->in_vpidx), lp->port_wwn, nphdl, lp->portid);
3194 }

--- 10 unchanged lines hidden (view full) ---

3205 isp_prt(isp, ISP_LOGINFO, "Chan %d %s (sub-status 0x%x) for N-port handle 0x%x", ISP_GET_VPIDX(isp, inot->in_vpidx), ptr, inot->in_status_subcode, nphdl);
3206
3207 /*
3208 * All subcodes here are irrelevant. What is relevant
3209 * is that we need to terminate all active commands from
3210 * this initiator (known by N-port handle).
3211 */
3212 /* XXX IMPLEMENT XXX */
2803 (void) isp_notify_ack(isp, inot);
3213 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2804 break;
2805
3214 break;
3215
3216 case IN24XX_SRR_RCVD:
3217#ifdef ISP_TARGET_MODE
3218 isp_handle_srr_notify(isp, inot);
3219 break;
3220#else
3221 if (ptr == NULL) {
3222 ptr = "SRR RCVD";
3223 }
3224 /* FALLTHROUGH */
3225#endif
2806 case IN24XX_LINK_RESET:
3226 case IN24XX_LINK_RESET:
3227 if (ptr == NULL) {
3228 ptr = "LINK RESET";
3229 }
2807 case IN24XX_LINK_FAILED:
3230 case IN24XX_LINK_FAILED:
2808 case IN24XX_SRR_RCVD:
3231 if (ptr == NULL) {
3232 ptr = "LINK FAILED";
3233 }
2809 default:
3234 default:
2810 (void) isp_notify_ack(isp, inot);
3235 isp_prt(isp, ISP_LOGWARN, "Chan %d %s", ISP_GET_VPIDX(isp, inot->in_vpidx), ptr);
3236 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
2811 break;
2812 }
2813}
2814
2815static int
2816isp_handle_platform_target_notify_ack(ispsoftc_t *isp, isp_notify_t *mp)
2817{
2818

--- 81 unchanged lines hidden (view full) ---

2900 }
2901 }
2902
2903 /*
2904 * General purpose acknowledgement
2905 */
2906 if (mp->nt_need_ack) {
2907 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) being acked", mp->nt_ncode, mp->nt_lreserved != NULL);
3237 break;
3238 }
3239}
3240
3241static int
3242isp_handle_platform_target_notify_ack(ispsoftc_t *isp, isp_notify_t *mp)
3243{
3244

--- 81 unchanged lines hidden (view full) ---

3326 }
3327 }
3328
3329 /*
3330 * General purpose acknowledgement
3331 */
3332 if (mp->nt_need_ack) {
3333 isp_prt(isp, ISP_LOGTINFO, "Notify Code 0x%x (qevalid=%d) being acked", mp->nt_ncode, mp->nt_lreserved != NULL);
3334 /*
3335 * Don't need to use the guaranteed send because the caller can retry
3336 */
2908 return (isp_notify_ack(isp, mp->nt_lreserved));
2909 }
2910 return (0);
2911}
2912
2913/*
2914 * Handle task management functions.
2915 *

--- 82 unchanged lines hidden (view full) ---

2998 ntp->rd.nt.nt_lreserved = &ntp->rd.data;
2999 }
3000 ntp->rd.seq_id = notify->nt_tagval;
3001 ntp->rd.tag_id = notify->nt_tagval >> 32;
3002
3003 tptr->inot_count--;
3004 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
3005 rls_lun_statep(isp, tptr);
3337 return (isp_notify_ack(isp, mp->nt_lreserved));
3338 }
3339 return (0);
3340}
3341
3342/*
3343 * Handle task management functions.
3344 *

--- 82 unchanged lines hidden (view full) ---

3427 ntp->rd.nt.nt_lreserved = &ntp->rd.data;
3428 }
3429 ntp->rd.seq_id = notify->nt_tagval;
3430 ntp->rd.tag_id = notify->nt_tagval >> 32;
3431
3432 tptr->inot_count--;
3433 SLIST_REMOVE_HEAD(&tptr->inots, sim_links.sle);
3434 rls_lun_statep(isp, tptr);
3006 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
3435 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, inot->ccb_h.path, "%s: Take FREE INOT count now %d\n", __func__, tptr->inot_count);
3007 inot->ccb_h.status = CAM_MESSAGE_RECV;
3008 xpt_done((union ccb *)inot);
3009 return;
3010bad:
3011 if (tptr) {
3012 rls_lun_statep(isp, tptr);
3013 }
3014 if (notify->nt_need_ack && notify->nt_lreserved) {
3015 if (((isphdr_t *)notify->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD) {
3436 inot->ccb_h.status = CAM_MESSAGE_RECV;
3437 xpt_done((union ccb *)inot);
3438 return;
3439bad:
3440 if (tptr) {
3441 rls_lun_statep(isp, tptr);
3442 }
3443 if (notify->nt_need_ack && notify->nt_lreserved) {
3444 if (((isphdr_t *)notify->nt_lreserved)->rqs_entry_type == RQSTYPE_ABTS_RCVD) {
3016 (void) isp_acknak_abts(isp, notify->nt_lreserved, ENOMEM);
3445 if (isp_acknak_abts(isp, notify->nt_lreserved, ENOMEM)) {
3446 isp_prt(isp, ISP_LOGWARN, "you lose- unable to send an ACKNAK");
3447 }
3017 } else {
3448 } else {
3018 (void) isp_notify_ack(isp, notify->nt_lreserved);
3449 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, notify->nt_lreserved);
3019 }
3020 }
3021}
3022
3023/*
3024 * Find the associated private data and mark it as dead so
3025 * we don't try to work on it any further.
3026 */

--- 150 unchanged lines hidden (view full) ---

3177 };
3178 const uint8_t iqd[SHORT_INQUIRY_LENGTH] = {
3179 0, 0x0, 0x5, 0x2, 32, 0, 0, 0x32,
3180 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ',
3181 'S', 'C', 'S', 'I', ' ', 'M', 'E', 'M',
3182 'O', 'R', 'Y', ' ', 'D', 'I', 'S', 'K',
3183 '0', '0', '0', '1'
3184 };
3450 }
3451 }
3452}
3453
3454/*
3455 * Find the associated private data and mark it as dead so
3456 * we don't try to work on it any further.
3457 */

--- 150 unchanged lines hidden (view full) ---

3608 };
3609 const uint8_t iqd[SHORT_INQUIRY_LENGTH] = {
3610 0, 0x0, 0x5, 0x2, 32, 0, 0, 0x32,
3611 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ',
3612 'S', 'C', 'S', 'I', ' ', 'M', 'E', 'M',
3613 'O', 'R', 'Y', ' ', 'D', 'I', 'S', 'K',
3614 '0', '0', '0', '1'
3615 };
3185 int i, more = 0, last;
3616 int r, i, more = 0, last;
3186 struct isptarg_softc *softc = periph->softc;
3187 struct ccb_scsiio *csio;
3188 lun_id_t return_lun;
3189 struct ccb_accept_tio *atio;
3190 uint8_t *cdb, *ptr, status;
3191 uint8_t *data_ptr;
3192 uint32_t data_len, flags;
3193 struct ccb_hdr *ccbh;
3194
3195 mtx_assert(periph->sim->mtx, MA_OWNED);
3617 struct isptarg_softc *softc = periph->softc;
3618 struct ccb_scsiio *csio;
3619 lun_id_t return_lun;
3620 struct ccb_accept_tio *atio;
3621 uint8_t *cdb, *ptr, status;
3622 uint8_t *data_ptr;
3623 uint32_t data_len, flags;
3624 struct ccb_hdr *ccbh;
3625
3626 mtx_assert(periph->sim->mtx, MA_OWNED);
3196 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, iccb->ccb_h.path, "%s: function code 0x%x INOTQ=%c WORKQ=%c REWORKQ=%c\n", __func__, iccb->ccb_h.func_code,
3627 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, iccb->ccb_h.path, "%s: function code 0x%x INOTQ=%c WORKQ=%c REWORKQ=%c\n", __func__, iccb->ccb_h.func_code,
3197 TAILQ_FIRST(&softc->inot_queue)? 'y' : 'n', TAILQ_FIRST(&softc->work_queue)? 'y' : 'n', TAILQ_FIRST(&softc->rework_queue)? 'y' : 'n');
3198 /*
3199 * Check for immediate notifies first
3200 */
3201 ccbh = TAILQ_FIRST(&softc->inot_queue);
3202 if (ccbh) {
3203 TAILQ_REMOVE(&softc->inot_queue, ccbh, periph_links.tqe);
3204 if (TAILQ_FIRST(&softc->inot_queue) || TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue)) {

--- 9 unchanged lines hidden (view full) ---

3214 ccbh = TAILQ_FIRST(&softc->rework_queue);
3215 if (ccbh) {
3216 atio = (struct ccb_accept_tio *)ccbh;
3217 TAILQ_REMOVE(&softc->rework_queue, ccbh, periph_links.tqe);
3218 more = TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue);
3219 } else {
3220 ccbh = TAILQ_FIRST(&softc->work_queue);
3221 if (ccbh == NULL) {
3628 TAILQ_FIRST(&softc->inot_queue)? 'y' : 'n', TAILQ_FIRST(&softc->work_queue)? 'y' : 'n', TAILQ_FIRST(&softc->rework_queue)? 'y' : 'n');
3629 /*
3630 * Check for immediate notifies first
3631 */
3632 ccbh = TAILQ_FIRST(&softc->inot_queue);
3633 if (ccbh) {
3634 TAILQ_REMOVE(&softc->inot_queue, ccbh, periph_links.tqe);
3635 if (TAILQ_FIRST(&softc->inot_queue) || TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue)) {

--- 9 unchanged lines hidden (view full) ---

3645 ccbh = TAILQ_FIRST(&softc->rework_queue);
3646 if (ccbh) {
3647 atio = (struct ccb_accept_tio *)ccbh;
3648 TAILQ_REMOVE(&softc->rework_queue, ccbh, periph_links.tqe);
3649 more = TAILQ_FIRST(&softc->work_queue) || TAILQ_FIRST(&softc->rework_queue);
3650 } else {
3651 ccbh = TAILQ_FIRST(&softc->work_queue);
3652 if (ccbh == NULL) {
3222 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, iccb->ccb_h.path, "%s: woken up but no work?\n", __func__);
3653 ISP_PATH_PRT(softc->isp, ISP_LOGWARN, iccb->ccb_h.path, "%s: woken up but no work?\n", __func__);
3223 xpt_release_ccb(iccb);
3224 return;
3225 }
3226 atio = (struct ccb_accept_tio *)ccbh;
3227 TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe);
3228 more = TAILQ_FIRST(&softc->work_queue) != NULL;
3229 atio->ccb_h.ccb_data_offset = 0;
3230 }

--- 4 unchanged lines hidden (view full) ---

3235
3236 data_ptr = NULL;
3237 data_len = 0;
3238 csio = &iccb->csio;
3239 status = SCSI_STATUS_OK;
3240 flags = CAM_SEND_STATUS;
3241 memset(&atio->sense_data, 0, sizeof (atio->sense_data));
3242 cdb = atio->cdb_io.cdb_bytes;
3654 xpt_release_ccb(iccb);
3655 return;
3656 }
3657 atio = (struct ccb_accept_tio *)ccbh;
3658 TAILQ_REMOVE(&softc->work_queue, ccbh, periph_links.tqe);
3659 more = TAILQ_FIRST(&softc->work_queue) != NULL;
3660 atio->ccb_h.ccb_data_offset = 0;
3661 }

--- 4 unchanged lines hidden (view full) ---

3666
3667 data_ptr = NULL;
3668 data_len = 0;
3669 csio = &iccb->csio;
3670 status = SCSI_STATUS_OK;
3671 flags = CAM_SEND_STATUS;
3672 memset(&atio->sense_data, 0, sizeof (atio->sense_data));
3673 cdb = atio->cdb_io.cdb_bytes;
3243 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, ccbh->path, "%s: [0x%x] processing ATIO from 0x%x CDB=0x%x data_offset=%u\n", __func__, atio->tag_id, atio->init_id,
3674 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, ccbh->path, "%s: [0x%x] processing ATIO from 0x%x CDB=0x%x data_offset=%u\n", __func__, atio->tag_id, atio->init_id,
3244 cdb[0], atio->ccb_h.ccb_data_offset);
3245
3246 return_lun = XS_LUN(atio);
3247 if (return_lun != 0) {
3248 xpt_print(atio->ccb_h.path, "[0x%x] Non-Zero Lun %d: cdb0=0x%x\n", atio->tag_id, return_lun, cdb[0]);
3249 if (cdb[0] != INQUIRY && cdb[0] != REPORT_LUNS && cdb[0] != REQUEST_SENSE) {
3250 status = SCSI_STATUS_CHECK_COND;
3675 cdb[0], atio->ccb_h.ccb_data_offset);
3676
3677 return_lun = XS_LUN(atio);
3678 if (return_lun != 0) {
3679 xpt_print(atio->ccb_h.path, "[0x%x] Non-Zero Lun %d: cdb0=0x%x\n", atio->tag_id, return_lun, cdb[0]);
3680 if (cdb[0] != INQUIRY && cdb[0] != REPORT_LUNS && cdb[0] != REQUEST_SENSE) {
3681 status = SCSI_STATUS_CHECK_COND;
3251 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_ILLEGAL_REQUEST;
3252 SDFIXED(atio->sense_data)->add_sense_code = 0x25;
3253 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x0;
3682 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3683 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3684 SDFIXED(atio->sense_data)->add_sense_code = 0x25; /* LOGICAL UNIT NOT SUPPORTED */
3254 atio->sense_len = SSD_MIN_SIZE;
3255 }
3256 return_lun = CAM_LUN_WILDCARD;
3257 }
3258
3259 switch (cdb[0]) {
3260 case REQUEST_SENSE:
3261 flags |= CAM_DIR_IN;

--- 6 unchanged lines hidden (view full) ---

3268 if (data_len) {
3269 data_ptr = junk_data;
3270 }
3271 break;
3272 case READ_6:
3273 case READ_10:
3274 case READ_12:
3275 case READ_16:
3685 atio->sense_len = SSD_MIN_SIZE;
3686 }
3687 return_lun = CAM_LUN_WILDCARD;
3688 }
3689
3690 switch (cdb[0]) {
3691 case REQUEST_SENSE:
3692 flags |= CAM_DIR_IN;

--- 6 unchanged lines hidden (view full) ---

3699 if (data_len) {
3700 data_ptr = junk_data;
3701 }
3702 break;
3703 case READ_6:
3704 case READ_10:
3705 case READ_12:
3706 case READ_16:
3276 if (isptarg_rwparm(cdb, disk_data, disk_size, atio->ccb_h.ccb_data_offset, &data_ptr, &data_len, &last)) {
3707 r = isptarg_rwparm(cdb, disk_data, disk_size, atio->ccb_h.ccb_data_offset, &data_ptr, &data_len, &last);
3708 if (r != 0) {
3277 status = SCSI_STATUS_CHECK_COND;
3709 status = SCSI_STATUS_CHECK_COND;
3278 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3279 SDFIXED(atio->sense_data)->add_sense_code = 0x5;
3280 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x24;
3710 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3711 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3712 if (r == -1) {
3713 SDFIXED(atio->sense_data)->add_sense_code = 0x21; /* LOGICAL BLOCK ADDRESS OUT OF RANGE */
3714 } else {
3715 SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */
3716 }
3281 atio->sense_len = SSD_MIN_SIZE;
3282 } else {
3283#ifdef ISP_FORCE_TIMEOUT
3284 {
3285 static int foo;
3286 if (foo++ == 500) {
3287 if (more) {
3288 xpt_schedule(periph, 1);

--- 18 unchanged lines hidden (view full) ---

3307 flags |= CAM_DIR_NONE;
3308 }
3309 }
3310 break;
3311 case WRITE_6:
3312 case WRITE_10:
3313 case WRITE_12:
3314 case WRITE_16:
3717 atio->sense_len = SSD_MIN_SIZE;
3718 } else {
3719#ifdef ISP_FORCE_TIMEOUT
3720 {
3721 static int foo;
3722 if (foo++ == 500) {
3723 if (more) {
3724 xpt_schedule(periph, 1);

--- 18 unchanged lines hidden (view full) ---

3743 flags |= CAM_DIR_NONE;
3744 }
3745 }
3746 break;
3747 case WRITE_6:
3748 case WRITE_10:
3749 case WRITE_12:
3750 case WRITE_16:
3315 if (isptarg_rwparm(cdb, disk_data, disk_size, atio->ccb_h.ccb_data_offset, &data_ptr, &data_len, &last)) {
3751 r = isptarg_rwparm(cdb, disk_data, disk_size, atio->ccb_h.ccb_data_offset, &data_ptr, &data_len, &last);
3752 if (r != 0) {
3316 status = SCSI_STATUS_CHECK_COND;
3753 status = SCSI_STATUS_CHECK_COND;
3317 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3318 SDFIXED(atio->sense_data)->add_sense_code = 0x5;
3319 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x24;
3754 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3755 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3756 if (r == -1) {
3757 SDFIXED(atio->sense_data)->add_sense_code = 0x21; /* LOGICAL BLOCK ADDRESS OUT OF RANGE */
3758 } else {
3759 SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */
3760 }
3320 atio->sense_len = SSD_MIN_SIZE;
3321 } else {
3322#ifdef ISP_FORCE_TIMEOUT
3323 {
3324 static int foo;
3325 if (foo++ == 500) {
3326 if (more) {
3327 xpt_schedule(periph, 1);

--- 18 unchanged lines hidden (view full) ---

3346 flags |= CAM_DIR_NONE;
3347 }
3348 }
3349 break;
3350 case INQUIRY:
3351 flags |= CAM_DIR_IN;
3352 if (cdb[1] || cdb[2] || cdb[3]) {
3353 status = SCSI_STATUS_CHECK_COND;
3761 atio->sense_len = SSD_MIN_SIZE;
3762 } else {
3763#ifdef ISP_FORCE_TIMEOUT
3764 {
3765 static int foo;
3766 if (foo++ == 500) {
3767 if (more) {
3768 xpt_schedule(periph, 1);

--- 18 unchanged lines hidden (view full) ---

3787 flags |= CAM_DIR_NONE;
3788 }
3789 }
3790 break;
3791 case INQUIRY:
3792 flags |= CAM_DIR_IN;
3793 if (cdb[1] || cdb[2] || cdb[3]) {
3794 status = SCSI_STATUS_CHECK_COND;
3354 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3355 SDFIXED(atio->sense_data)->add_sense_code = 0x5;
3356 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x20;
3795 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3796 SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION;
3797 SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */
3357 atio->sense_len = SSD_MIN_SIZE;
3358 break;
3359 }
3360 data_len = sizeof (iqd);
3361 if (data_len > cdb[4]) {
3362 data_len = cdb[4];
3363 }
3364 if (data_len) {

--- 5 unchanged lines hidden (view full) ---

3370 data_ptr = junk_data;
3371 }
3372 break;
3373 case TEST_UNIT_READY:
3374 flags |= CAM_DIR_NONE;
3375 if (ca) {
3376 ca = 0;
3377 status = SCSI_STATUS_CHECK_COND;
3798 atio->sense_len = SSD_MIN_SIZE;
3799 break;
3800 }
3801 data_len = sizeof (iqd);
3802 if (data_len > cdb[4]) {
3803 data_len = cdb[4];
3804 }
3805 if (data_len) {

--- 5 unchanged lines hidden (view full) ---

3811 data_ptr = junk_data;
3812 }
3813 break;
3814 case TEST_UNIT_READY:
3815 flags |= CAM_DIR_NONE;
3816 if (ca) {
3817 ca = 0;
3818 status = SCSI_STATUS_CHECK_COND;
3378 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3379 SDFIXED(atio->sense_data)->add_sense_code = 0x28;
3380 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x0;
3819 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3820 SDFIXED(atio->sense_data)->flags = SSD_KEY_UNIT_ATTENTION;
3821 SDFIXED(atio->sense_data)->add_sense_code = 0x29; /* POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */
3381 atio->sense_len = SSD_MIN_SIZE;
3382 }
3383 break;
3384 case SYNCHRONIZE_CACHE:
3385 case START_STOP:
3386 case RESERVE:
3387 case RELEASE:
3388 case VERIFY_10:
3389 flags |= CAM_DIR_NONE;
3390 break;
3391
3392 case READ_CAPACITY:
3393 flags |= CAM_DIR_IN;
3394 if (cdb[2] || cdb[3] || cdb[4] || cdb[5]) {
3395 status = SCSI_STATUS_CHECK_COND;
3822 atio->sense_len = SSD_MIN_SIZE;
3823 }
3824 break;
3825 case SYNCHRONIZE_CACHE:
3826 case START_STOP:
3827 case RESERVE:
3828 case RELEASE:
3829 case VERIFY_10:
3830 flags |= CAM_DIR_NONE;
3831 break;
3832
3833 case READ_CAPACITY:
3834 flags |= CAM_DIR_IN;
3835 if (cdb[2] || cdb[3] || cdb[4] || cdb[5]) {
3836 status = SCSI_STATUS_CHECK_COND;
3396 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3397 SDFIXED(atio->sense_data)->add_sense_code = 0x5;
3398 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x24;
3837 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3838 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3839 SDFIXED(atio->sense_data)->add_sense_code = 0x24; /* INVALID FIELD IN CDB */
3399 atio->sense_len = SSD_MIN_SIZE;
3400 break;
3401 }
3402 if (cdb[8] & 0x1) { /* PMI */
3403 junk_data[0] = 0xff;
3404 junk_data[1] = 0xff;
3405 junk_data[2] = 0xff;
3406 junk_data[3] = 0xff;

--- 35 unchanged lines hidden (view full) ---

3442 }
3443 data_ptr = junk_data;
3444 data_len = (ptr + 8) - junk_data;
3445 break;
3446
3447 default:
3448 flags |= CAM_DIR_NONE;
3449 status = SCSI_STATUS_CHECK_COND;
3840 atio->sense_len = SSD_MIN_SIZE;
3841 break;
3842 }
3843 if (cdb[8] & 0x1) { /* PMI */
3844 junk_data[0] = 0xff;
3845 junk_data[1] = 0xff;
3846 junk_data[2] = 0xff;
3847 junk_data[3] = 0xff;

--- 35 unchanged lines hidden (view full) ---

3883 }
3884 data_ptr = junk_data;
3885 data_len = (ptr + 8) - junk_data;
3886 break;
3887
3888 default:
3889 flags |= CAM_DIR_NONE;
3890 status = SCSI_STATUS_CHECK_COND;
3450 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR|SSD_KEY_UNIT_ATTENTION;
3451 SDFIXED(atio->sense_data)->add_sense_code = 0x5;
3452 SDFIXED(atio->sense_data)->add_sense_code_qual = 0x20;
3891 SDFIXED(atio->sense_data)->error_code = SSD_ERRCODE_VALID|SSD_CURRENT_ERROR;
3892 SDFIXED(atio->sense_data)->flags = SSD_KEY_ILLEGAL_REQUEST;
3893 SDFIXED(atio->sense_data)->add_sense_code = 0x20; /* INVALID COMMAND OPERATION CODE */
3453 atio->sense_len = SSD_MIN_SIZE;
3454 break;
3455 }
3456
3457 /*
3458 * If we are done with the transaction, tell the
3459 * controller to send status and perform a CMD_CMPLT.
3460 * If we have associated sense data, see if we can

--- 26 unchanged lines hidden (view full) ---

3487isptargctor(struct cam_periph *periph, void *arg)
3488{
3489 struct isptarg_softc *softc;
3490
3491 softc = (struct isptarg_softc *)arg;
3492 periph->softc = softc;
3493 softc->periph = periph;
3494 softc->path = periph->path;
3894 atio->sense_len = SSD_MIN_SIZE;
3895 break;
3896 }
3897
3898 /*
3899 * If we are done with the transaction, tell the
3900 * controller to send status and perform a CMD_CMPLT.
3901 * If we have associated sense data, see if we can

--- 26 unchanged lines hidden (view full) ---

3928isptargctor(struct cam_periph *periph, void *arg)
3929{
3930 struct isptarg_softc *softc;
3931
3932 softc = (struct isptarg_softc *)arg;
3933 periph->softc = softc;
3934 softc->periph = periph;
3935 softc->path = periph->path;
3495 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, periph->path, "%s called\n", __func__);
3936 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__);
3496 return (CAM_REQ_CMP);
3497}
3498
3499static void
3500isptargdtor(struct cam_periph *periph)
3501{
3502 struct isptarg_softc *softc;
3503 softc = (struct isptarg_softc *)periph->softc;
3937 return (CAM_REQ_CMP);
3938}
3939
3940static void
3941isptargdtor(struct cam_periph *periph)
3942{
3943 struct isptarg_softc *softc;
3944 softc = (struct isptarg_softc *)periph->softc;
3504 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG0, periph->path, "%s called\n", __func__);
3945 ISP_PATH_PRT(softc->isp, ISP_LOGTDEBUG1, periph->path, "%s called\n", __func__);
3505 softc->periph = NULL;
3506 softc->path = NULL;
3507 periph->softc = NULL;
3508}
3509
3510static void
3511isptarg_done(struct cam_periph *periph, union ccb *ccb)
3512{

--- 5 unchanged lines hidden (view full) ---

3518
3519 softc = (struct isptarg_softc *)periph->softc;
3520 isp = softc->isp;
3521 status = ccb->ccb_h.status & CAM_STATUS_MASK;
3522
3523 switch (ccb->ccb_h.func_code) {
3524 case XPT_ACCEPT_TARGET_IO:
3525 atio = (struct ccb_accept_tio *) ccb;
3946 softc->periph = NULL;
3947 softc->path = NULL;
3948 periph->softc = NULL;
3949}
3950
3951static void
3952isptarg_done(struct cam_periph *periph, union ccb *ccb)
3953{

--- 5 unchanged lines hidden (view full) ---

3959
3960 softc = (struct isptarg_softc *)periph->softc;
3961 isp = softc->isp;
3962 status = ccb->ccb_h.status & CAM_STATUS_MASK;
3963
3964 switch (ccb->ccb_h.func_code) {
3965 case XPT_ACCEPT_TARGET_IO:
3966 atio = (struct ccb_accept_tio *) ccb;
3526 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] ATIO seen in %s\n", atio->tag_id, __func__);
3967 ISP_PATH_PRT(isp, ISP_LOGTDEBUG1, ccb->ccb_h.path, "[0x%x] ATIO seen in %s\n", atio->tag_id, __func__);
3527 TAILQ_INSERT_TAIL(&softc->work_queue, &ccb->ccb_h, periph_links.tqe);
3528 xpt_schedule(periph, 1);
3529 break;
3530 case XPT_IMMEDIATE_NOTIFY:
3531 inot = (struct ccb_immediate_notify *) ccb;
3968 TAILQ_INSERT_TAIL(&softc->work_queue, &ccb->ccb_h, periph_links.tqe);
3969 xpt_schedule(periph, 1);
3970 break;
3971 case XPT_IMMEDIATE_NOTIFY:
3972 inot = (struct ccb_immediate_notify *) ccb;
3532 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] INOT for 0x%x seen in %s\n", inot->tag_id, inot->seq_id, __func__);
3973 ISP_PATH_PRT(isp, ISP_LOGTDEBUG1, ccb->ccb_h.path, "[0x%x] INOT for 0x%x seen in %s\n", inot->tag_id, inot->seq_id, __func__);
3533 TAILQ_INSERT_TAIL(&softc->inot_queue, &ccb->ccb_h, periph_links.tqe);
3534 xpt_schedule(periph, 1);
3535 break;
3536 case XPT_CONT_TARGET_IO:
3537 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3538 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
3539 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
3540 }
3541 atio = ccb->ccb_h.ccb_atio;
3542 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3974 TAILQ_INSERT_TAIL(&softc->inot_queue, &ccb->ccb_h, periph_links.tqe);
3975 xpt_schedule(periph, 1);
3976 break;
3977 case XPT_CONT_TARGET_IO:
3978 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3979 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
3980 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
3981 }
3982 atio = ccb->ccb_h.ccb_atio;
3983 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3543 cam_error_print(ccb, CAM_ESF_ALL, CAM_EPF_ALL);
3544 xpt_action((union ccb *)atio);
3984 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_MESSAGE_RECV) {
3985 uint32_t newoff = (ccb->csio.msg_ptr[3] << 24) | (ccb->csio.msg_ptr[4] << 16) | (ccb->csio.msg_ptr[5] << 8) | (ccb->csio.msg_ptr[6]);
3986 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "[0x%08x] got message to return to reset offset to 0x%x\n", atio->tag_id, newoff);
3987 atio->ccb_h.ccb_data_offset = newoff;
3988 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
3989 xpt_schedule(periph, 1);
3990 } else {
3991 cam_error_print(ccb, CAM_ESF_ALL, CAM_EPF_ALL);
3992 xpt_action((union ccb *)atio);
3993 }
3545 } else if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
3546 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] MID CTIO seen in %s\n", atio->tag_id, __func__);
3547 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
3548 xpt_schedule(periph, 1);
3549 } else {
3550 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] FINAL CTIO seen in %s\n", atio->tag_id, __func__);
3551 xpt_action((union ccb *)atio);
3552 }
3553 xpt_release_ccb(ccb);
3554 break;
3555 case XPT_NOTIFY_ACKNOWLEDGE:
3556 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3557 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
3558 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
3559 }
3560 inot = ccb->ccb_h.ccb_inot;
3994 } else if ((ccb->ccb_h.flags & CAM_SEND_STATUS) == 0) {
3995 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] MID CTIO seen in %s\n", atio->tag_id, __func__);
3996 TAILQ_INSERT_TAIL(&softc->rework_queue, &atio->ccb_h, periph_links.tqe);
3997 xpt_schedule(periph, 1);
3998 } else {
3999 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "[0x%x] FINAL CTIO seen in %s\n", atio->tag_id, __func__);
4000 xpt_action((union ccb *)atio);
4001 }
4002 xpt_release_ccb(ccb);
4003 break;
4004 case XPT_NOTIFY_ACKNOWLEDGE:
4005 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4006 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
4007 ccb->ccb_h.status &= ~CAM_DEV_QFRZN;
4008 }
4009 inot = ccb->ccb_h.ccb_inot;
3561 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, inot->ccb_h.path, "[0x%x] recycle notify for tag 0x%x\n", inot->tag_id, inot->seq_id);
4010 ISP_PATH_PRT(isp, ISP_LOGTDEBUG1, inot->ccb_h.path, "[0x%x] recycle notify for tag 0x%x\n", inot->tag_id, inot->seq_id);
3562 xpt_release_ccb(ccb);
3563 xpt_action((union ccb *)inot);
3564 break;
3565 default:
3566 xpt_print(ccb->ccb_h.path, "unexpected code 0x%x\n", ccb->ccb_h.func_code);
3567 break;
3568 }
3569}

--- 315 unchanged lines hidden (view full) ---

3885 lba <<= DISK_SHIFT;
3886
3887 if (offset == cnt) {
3888 *lp = 1;
3889 return (0);
3890 }
3891
3892 if (lba + cnt > dl) {
4011 xpt_release_ccb(ccb);
4012 xpt_action((union ccb *)inot);
4013 break;
4014 default:
4015 xpt_print(ccb->ccb_h.path, "unexpected code 0x%x\n", ccb->ccb_h.func_code);
4016 break;
4017 }
4018}

--- 315 unchanged lines hidden (view full) ---

4334 lba <<= DISK_SHIFT;
4335
4336 if (offset == cnt) {
4337 *lp = 1;
4338 return (0);
4339 }
4340
4341 if (lba + cnt > dl) {
3893 return (-1);
4342 return (-2);
3894 }
3895
3896
3897 curcnt = MAX_ISP_TARG_TRANSFER;
3898 if (offset + curcnt >= cnt) {
3899 curcnt = cnt - offset;
3900 *lp = 1;
3901 } else {

--- 69 unchanged lines hidden (view full) ---

3971 struct ccb_scsiio *xs = arg;
3972 ispsoftc_t *isp;
3973 uint32_t ohandle = ISP_HANDLE_FREE, handle;
3974
3975 isp = XS_ISP(xs);
3976
3977 handle = isp_find_handle(isp, xs);
3978
4343 }
4344
4345
4346 curcnt = MAX_ISP_TARG_TRANSFER;
4347 if (offset + curcnt >= cnt) {
4348 curcnt = cnt - offset;
4349 *lp = 1;
4350 } else {

--- 69 unchanged lines hidden (view full) ---

4420 struct ccb_scsiio *xs = arg;
4421 ispsoftc_t *isp;
4422 uint32_t ohandle = ISP_HANDLE_FREE, handle;
4423
4424 isp = XS_ISP(xs);
4425
4426 handle = isp_find_handle(isp, xs);
4427
3979 if (handle != ISP_HANDLE_FREE && !XS_CMD_WPEND_P(xs)) {
3980 isp_xs_prt(isp, xs, ISP_LOGWARN, "first watchdog (handle 0x%x) timed out- deferring for grace period", handle);
3981 callout_reset(&PISP_PCMD(xs)->wdog, 2 * hz, isp_watchdog, xs);
3982 XS_CMD_S_WPEND(xs);
3983 return;
3984 }
3985 XS_C_TACTIVE(xs);
3986
3987 /*
3988 * Hand crank the interrupt code just to be sure the command isn't stuck somewhere.
3989 */
3990 if (handle != ISP_HANDLE_FREE) {
3991 uint32_t isr;
3992 uint16_t sema, mbox;
3993 if (ISP_READ_ISR(isp, &isr, &sema, &mbox) != 0) {
3994 isp_intr(isp, isr, sema, mbox);

--- 31 unchanged lines hidden (view full) ---

4026 /*
4027 * After this point, the command is really dead.
4028 */
4029 if (XS_XFRLEN(xs)) {
4030 ISP_DMAFREE(isp, xs, handle);
4031 }
4032 isp_destroy_handle(isp, handle);
4033 isp_prt(isp, ISP_LOGERR, "%s: timeout for handle 0x%x", __func__, handle);
4428 /*
4429 * Hand crank the interrupt code just to be sure the command isn't stuck somewhere.
4430 */
4431 if (handle != ISP_HANDLE_FREE) {
4432 uint32_t isr;
4433 uint16_t sema, mbox;
4434 if (ISP_READ_ISR(isp, &isr, &sema, &mbox) != 0) {
4435 isp_intr(isp, isr, sema, mbox);

--- 31 unchanged lines hidden (view full) ---

4467 /*
4468 * After this point, the command is really dead.
4469 */
4470 if (XS_XFRLEN(xs)) {
4471 ISP_DMAFREE(isp, xs, handle);
4472 }
4473 isp_destroy_handle(isp, handle);
4474 isp_prt(isp, ISP_LOGERR, "%s: timeout for handle 0x%x", __func__, handle);
4034 XS_SETERR(xs, CAM_CMD_TIMEOUT);
4475 xs->ccb_h.status &= ~CAM_STATUS_MASK;
4476 xs->ccb_h.status |= CAM_CMD_TIMEOUT;
4035 isp_prt_endcmd(isp, xs);
4036 isp_done(xs);
4037 } else {
4038 if (ohandle != ISP_HANDLE_FREE) {
4039 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle 0x%x, recovered during interrupt", __func__, ohandle);
4040 } else {
4041 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle already free", __func__);
4042 }

--- 74 unchanged lines hidden (view full) ---

4117
4118 if (lp->state != FC_PORTDB_STATE_ZOMBIE) {
4119 continue;
4120 }
4121 if (lp->dev_map_idx == 0 || lp->target_mode) {
4122 continue;
4123 }
4124 if (lp->gone_timer != 0) {
4477 isp_prt_endcmd(isp, xs);
4478 isp_done(xs);
4479 } else {
4480 if (ohandle != ISP_HANDLE_FREE) {
4481 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle 0x%x, recovered during interrupt", __func__, ohandle);
4482 } else {
4483 isp_prt(isp, ISP_LOGWARN, "%s: timeout for handle already free", __func__);
4484 }

--- 74 unchanged lines hidden (view full) ---

4559
4560 if (lp->state != FC_PORTDB_STATE_ZOMBIE) {
4561 continue;
4562 }
4563 if (lp->dev_map_idx == 0 || lp->target_mode) {
4564 continue;
4565 }
4566 if (lp->gone_timer != 0) {
4125 isp_prt(isp, ISP_LOGSANCFG, "%s: Chan %d more to do for target %u (timer=%u)", __func__, chan, lp->dev_map_idx - 1, lp->gone_timer);
4567 isp_prt(isp, ISP_LOG_SANCFG, "%s: Chan %d more to do for target %u (timer=%u)", __func__, chan, lp->dev_map_idx - 1, lp->gone_timer);
4126 lp->gone_timer -= 1;
4127 more_to_do++;
4128 continue;
4129 }
4130 tgt = lp->dev_map_idx - 1;
4131 FCPARAM(isp, chan)->isp_dev_map[tgt] = 0;
4132 lp->dev_map_idx = 0;
4133 lp->state = FC_PORTDB_STATE_NIL;
4134 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, lp->portid, tgt, "Gone Device Timeout");
4135 isp_make_gone(isp, chan, tgt);
4136 }
4137 if (fc->ready) {
4138 if (more_to_do) {
4139 callout_reset(&fc->gdt, hz, isp_gdt, fc);
4140 } else {
4141 callout_deactivate(&fc->gdt);
4568 lp->gone_timer -= 1;
4569 more_to_do++;
4570 continue;
4571 }
4572 tgt = lp->dev_map_idx - 1;
4573 FCPARAM(isp, chan)->isp_dev_map[tgt] = 0;
4574 lp->dev_map_idx = 0;
4575 lp->state = FC_PORTDB_STATE_NIL;
4576 isp_prt(isp, ISP_LOGCONFIG, prom3, chan, lp->portid, tgt, "Gone Device Timeout");
4577 isp_make_gone(isp, chan, tgt);
4578 }
4579 if (fc->ready) {
4580 if (more_to_do) {
4581 callout_reset(&fc->gdt, hz, isp_gdt, fc);
4582 } else {
4583 callout_deactivate(&fc->gdt);
4142 isp_prt(isp, ISP_LOGSANCFG, "Chan %d Stopping Gone Device Timer @ %lu", chan, (unsigned long) time_uptime);
4584 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Stopping Gone Device Timer @ %lu", chan, (unsigned long) time_uptime);
4143 }
4144 }
4145 ISP_UNLOCK(isp);
4146}
4147
4148/*
4149 * Loop Down Timer Function- when loop goes down, a timer is started and
4150 * and after it expires we come here and take all probational devices that

--- 15 unchanged lines hidden (view full) ---

4166{
4167 struct isp_fc *fc = arg;
4168 ispsoftc_t *isp = fc->isp;
4169 int chan = fc - isp->isp_osinfo.pc.fc;
4170 fcportdb_t *lp;
4171 int dbidx, tgt, i;
4172
4173 ISP_LOCK(isp);
4585 }
4586 }
4587 ISP_UNLOCK(isp);
4588}
4589
4590/*
4591 * Loop Down Timer Function- when loop goes down, a timer is started and
4592 * and after it expires we come here and take all probational devices that

--- 15 unchanged lines hidden (view full) ---

4608{
4609 struct isp_fc *fc = arg;
4610 ispsoftc_t *isp = fc->isp;
4611 int chan = fc - isp->isp_osinfo.pc.fc;
4612 fcportdb_t *lp;
4613 int dbidx, tgt, i;
4614
4615 ISP_LOCK(isp);
4174 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d Loop Down Timer expired @ %lu", chan, (unsigned long) time_uptime);
4616 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Loop Down Timer expired @ %lu", chan, (unsigned long) time_uptime);
4175 callout_deactivate(&fc->ldt);
4176
4177 /*
4178 * Notify to the OS all targets who we now consider have departed.
4179 */
4180 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
4181 lp = &FCPARAM(isp, chan)->portdb[dbidx];
4182
4183 if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
4184 continue;
4185 }
4186 if (lp->dev_map_idx == 0 || lp->target_mode) {
4187 continue;
4188 }
4189
4190 /*
4191 * XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
4192 */
4617 callout_deactivate(&fc->ldt);
4618
4619 /*
4620 * Notify to the OS all targets who we now consider have departed.
4621 */
4622 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
4623 lp = &FCPARAM(isp, chan)->portdb[dbidx];
4624
4625 if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
4626 continue;
4627 }
4628 if (lp->dev_map_idx == 0 || lp->target_mode) {
4629 continue;
4630 }
4631
4632 /*
4633 * XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
4634 */
4193
4194
4635
4636
4195 for (i = 0; i < isp->isp_maxcmds; i++) {
4196 struct ccb_scsiio *xs;
4197
4198 if (!ISP_VALID_HANDLE(isp, isp->isp_xflist[i].handle)) {
4199 continue;
4200 }
4201 if ((xs = isp->isp_xflist[i].cmd) == NULL) {
4202 continue;
4203 }
4204 if (dbidx != (FCPARAM(isp, chan)->isp_dev_map[XS_TGT(xs)] - 1)) {
4205 continue;
4206 }
4207 isp_prt(isp, ISP_LOGWARN, "command handle 0x%08x for %d.%d.%d orphaned by loop down timeout",
4208 isp->isp_xflist[i].handle, chan, XS_TGT(xs), XS_LUN(xs));
4209 }
4210
4211 /*
4212 * Mark that we've announced that this device is gone....
4213 */
4637 for (i = 0; i < isp->isp_maxcmds; i++) {
4638 struct ccb_scsiio *xs;
4639
4640 if (!ISP_VALID_HANDLE(isp, isp->isp_xflist[i].handle)) {
4641 continue;
4642 }
4643 if ((xs = isp->isp_xflist[i].cmd) == NULL) {
4644 continue;
4645 }
4646 if (dbidx != (FCPARAM(isp, chan)->isp_dev_map[XS_TGT(xs)] - 1)) {
4647 continue;
4648 }
4649 isp_prt(isp, ISP_LOGWARN, "command handle 0x%08x for %d.%d.%d orphaned by loop down timeout",
4650 isp->isp_xflist[i].handle, chan, XS_TGT(xs), XS_LUN(xs));
4651 }
4652
4653 /*
4654 * Mark that we've announced that this device is gone....
4655 */
4214 lp->reserved = 1;
4656 lp->announced = 1;
4215
4216 /*
4217 * but *don't* change the state of the entry. Just clear
4218 * any target id stuff and announce to CAM that the
4219 * device is gone. This way any necessary PLOGO stuff
4220 * will happen when loop comes back up.
4221 */
4222

--- 26 unchanged lines hidden (view full) ---

4249 int chan = fc - isp->isp_osinfo.pc.fc;
4250 int slp = 0;
4251
4252 mtx_lock(&isp->isp_osinfo.lock);
4253
4254 for (;;) {
4255 int lb, lim;
4256
4657
4658 /*
4659 * but *don't* change the state of the entry. Just clear
4660 * any target id stuff and announce to CAM that the
4661 * device is gone. This way any necessary PLOGO stuff
4662 * will happen when loop comes back up.
4663 */
4664

--- 26 unchanged lines hidden (view full) ---

4691 int chan = fc - isp->isp_osinfo.pc.fc;
4692 int slp = 0;
4693
4694 mtx_lock(&isp->isp_osinfo.lock);
4695
4696 for (;;) {
4697 int lb, lim;
4698
4257 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d checking FC state", __func__, chan);
4699 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d checking FC state", __func__, chan);
4258 lb = isp_fc_runstate(isp, chan, 250000);
4259
4260 /*
4261 * Our action is different based upon whether we're supporting
4262 * Initiator mode or not. If we are, we might freeze the simq
4263 * when loop is down and set all sorts of different delays to
4264 * check again.
4265 *
4266 * If not, we simply just wait for loop to come up.
4267 */
4268 if (lb && (FCPARAM(isp, chan)->role & ISP_ROLE_INITIATOR)) {
4269 /*
4270 * Increment loop down time by the last sleep interval
4271 */
4272 fc->loop_down_time += slp;
4273
4274 if (lb < 0) {
4700 lb = isp_fc_runstate(isp, chan, 250000);
4701
4702 /*
4703 * Our action is different based upon whether we're supporting
4704 * Initiator mode or not. If we are, we might freeze the simq
4705 * when loop is down and set all sorts of different delays to
4706 * check again.
4707 *
4708 * If not, we simply just wait for loop to come up.
4709 */
4710 if (lb && (FCPARAM(isp, chan)->role & ISP_ROLE_INITIATOR)) {
4711 /*
4712 * Increment loop down time by the last sleep interval
4713 */
4714 fc->loop_down_time += slp;
4715
4716 if (lb < 0) {
4275 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC loop not up (down count %d)", __func__, chan, fc->loop_down_time);
4717 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC loop not up (down count %d)", __func__, chan, fc->loop_down_time);
4276 } else {
4718 } else {
4277 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC got to %d (down count %d)", __func__, chan, lb, fc->loop_down_time);
4719 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC got to %d (down count %d)", __func__, chan, lb, fc->loop_down_time);
4278 }
4279
4280 /*
4281 * If we've never seen loop up and we've waited longer
4282 * than quickboot time, or we've seen loop up but we've
4283 * waited longer than loop_down_limit, give up and go
4284 * to sleep until loop comes up.
4285 */

--- 13 unchanged lines hidden (view full) ---

4299 slp = 10;
4300 } else if (fc->loop_down_time < 120) {
4301 slp = 20;
4302 } else {
4303 slp = 30;
4304 }
4305
4306 } else if (lb) {
4720 }
4721
4722 /*
4723 * If we've never seen loop up and we've waited longer
4724 * than quickboot time, or we've seen loop up but we've
4725 * waited longer than loop_down_limit, give up and go
4726 * to sleep until loop comes up.
4727 */

--- 13 unchanged lines hidden (view full) ---

4741 slp = 10;
4742 } else if (fc->loop_down_time < 120) {
4743 slp = 20;
4744 } else {
4745 slp = 30;
4746 }
4747
4748 } else if (lb) {
4307 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC Loop Down", __func__, chan);
4749 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC Loop Down", __func__, chan);
4308 fc->loop_down_time += slp;
4750 fc->loop_down_time += slp;
4309 slp = 60;
4751 if (fc->loop_down_time > 300)
4752 slp = 0;
4753 else
4754 slp = 60;
4310 } else {
4755 } else {
4311 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC state OK", __func__, chan);
4756 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d FC state OK", __func__, chan);
4312 fc->loop_down_time = 0;
4313 slp = 0;
4314 }
4315
4316
4317 /*
4318 * If this is past the first loop up or the loop is dead and if we'd frozen the simq, unfreeze it
4319 * now so that CAM can start sending us commands.
4320 *
4321 * If the FC state isn't okay yet, they'll hit that in isp_start which will freeze the queue again
4322 * or kill the commands, as appropriate.
4323 */
4324
4325 if (FCPARAM(isp, chan)->loop_seen_once || fc->loop_dead) {
4326 isp_unfreeze_loopdown(isp, chan);
4327 }
4328
4757 fc->loop_down_time = 0;
4758 slp = 0;
4759 }
4760
4761
4762 /*
4763 * If this is past the first loop up or the loop is dead and if we'd frozen the simq, unfreeze it
4764 * now so that CAM can start sending us commands.
4765 *
4766 * If the FC state isn't okay yet, they'll hit that in isp_start which will freeze the queue again
4767 * or kill the commands, as appropriate.
4768 */
4769
4770 if (FCPARAM(isp, chan)->loop_seen_once || fc->loop_dead) {
4771 isp_unfreeze_loopdown(isp, chan);
4772 }
4773
4329 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep time %d", __func__, chan, slp);
4774 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep time %d", __func__, chan, slp);
4330
4331 msleep(fc, &isp->isp_osinfo.lock, PRIBIO, "ispf", slp * hz);
4332
4333 /*
4334 * If slp is zero, we're waking up for the first time after
4335 * things have been okay. In this case, we set a deferral state
4336 * for all commands and delay hysteresis seconds before starting
4337 * the FC state evaluation. This gives the loop/fabric a chance
4338 * to settle.
4339 */
4340 if (slp == 0 && fc->hysteresis) {
4775
4776 msleep(fc, &isp->isp_osinfo.lock, PRIBIO, "ispf", slp * hz);
4777
4778 /*
4779 * If slp is zero, we're waking up for the first time after
4780 * things have been okay. In this case, we set a deferral state
4781 * for all commands and delay hysteresis seconds before starting
4782 * the FC state evaluation. This gives the loop/fabric a chance
4783 * to settle.
4784 */
4785 if (slp == 0 && fc->hysteresis) {
4341 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep hysteresis ticks %d", __func__, chan, fc->hysteresis * hz);
4786 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "%s: Chan %d sleep hysteresis ticks %d", __func__, chan, fc->hysteresis * hz);
4342 mtx_unlock(&isp->isp_osinfo.lock);
4343 pause("ispt", fc->hysteresis * hz);
4344 mtx_lock(&isp->isp_osinfo.lock);
4345 }
4346 }
4347 mtx_unlock(&isp->isp_osinfo.lock);
4348}
4349
4350static void
4351isp_action(struct cam_sim *sim, union ccb *ccb)
4352{
4353 int bus, tgt, ts, error, lim;
4354 ispsoftc_t *isp;
4355 struct ccb_trans_settings *cts;
4356
4357 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
4787 mtx_unlock(&isp->isp_osinfo.lock);
4788 pause("ispt", fc->hysteresis * hz);
4789 mtx_lock(&isp->isp_osinfo.lock);
4790 }
4791 }
4792 mtx_unlock(&isp->isp_osinfo.lock);
4793}
4794
4795static void
4796isp_action(struct cam_sim *sim, union ccb *ccb)
4797{
4798 int bus, tgt, ts, error, lim;
4799 ispsoftc_t *isp;
4800 struct ccb_trans_settings *cts;
4801
4802 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n"));
4358
4803
4359 isp = (ispsoftc_t *)cam_sim_softc(sim);
4360 mtx_assert(&isp->isp_lock, MA_OWNED);
4361
4362 if (isp->isp_state != ISP_RUNSTATE && ccb->ccb_h.func_code == XPT_SCSI_IO) {
4363 isp_init(isp);
4364 if (isp->isp_state != ISP_INITSTATE) {
4365 /*
4366 * Lie. Say it was a selection timeout.

--- 16 unchanged lines hidden (view full) ---

4383 */
4384 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
4385 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
4386 ccb->ccb_h.status = CAM_REQ_INVALID;
4387 xpt_done(ccb);
4388 break;
4389 }
4390 }
4804 isp = (ispsoftc_t *)cam_sim_softc(sim);
4805 mtx_assert(&isp->isp_lock, MA_OWNED);
4806
4807 if (isp->isp_state != ISP_RUNSTATE && ccb->ccb_h.func_code == XPT_SCSI_IO) {
4808 isp_init(isp);
4809 if (isp->isp_state != ISP_INITSTATE) {
4810 /*
4811 * Lie. Say it was a selection timeout.

--- 16 unchanged lines hidden (view full) ---

4828 */
4829 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
4830 if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) {
4831 ccb->ccb_h.status = CAM_REQ_INVALID;
4832 xpt_done(ccb);
4833 break;
4834 }
4835 }
4836 ccb->csio.req_map = NULL;
4391#ifdef DIAGNOSTIC
4392 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
4393 xpt_print(ccb->ccb_h.path, "invalid target\n");
4394 ccb->ccb_h.status = CAM_PATH_INVALID;
4395 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
4396 xpt_print(ccb->ccb_h.path, "invalid lun\n");
4397 ccb->ccb_h.status = CAM_PATH_INVALID;
4398 }

--- 8 unchanged lines hidden (view full) ---

4407 cam_freeze_devq(ccb->ccb_h.path);
4408 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
4409 xpt_done(ccb);
4410 break;
4411 }
4412 error = isp_start((XS_T *) ccb);
4413 switch (error) {
4414 case CMD_QUEUED:
4837#ifdef DIAGNOSTIC
4838 if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) {
4839 xpt_print(ccb->ccb_h.path, "invalid target\n");
4840 ccb->ccb_h.status = CAM_PATH_INVALID;
4841 } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) {
4842 xpt_print(ccb->ccb_h.path, "invalid lun\n");
4843 ccb->ccb_h.status = CAM_PATH_INVALID;
4844 }

--- 8 unchanged lines hidden (view full) ---

4853 cam_freeze_devq(ccb->ccb_h.path);
4854 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 250, 0);
4855 xpt_done(ccb);
4856 break;
4857 }
4858 error = isp_start((XS_T *) ccb);
4859 switch (error) {
4860 case CMD_QUEUED:
4415 XS_CMD_S_CLEAR(ccb);
4416 ccb->ccb_h.status |= CAM_SIM_QUEUED;
4417 if (ccb->ccb_h.timeout == CAM_TIME_INFINITY) {
4418 break;
4419 }
4420 ts = ccb->ccb_h.timeout;
4421 if (ts == CAM_TIME_DEFAULT) {
4422 ts = 60*1000;
4423 }
4424 ts = isp_mstohz(ts);
4861 ccb->ccb_h.status |= CAM_SIM_QUEUED;
4862 if (ccb->ccb_h.timeout == CAM_TIME_INFINITY) {
4863 break;
4864 }
4865 ts = ccb->ccb_h.timeout;
4866 if (ts == CAM_TIME_DEFAULT) {
4867 ts = 60*1000;
4868 }
4869 ts = isp_mstohz(ts);
4425 XS_S_TACTIVE(ccb);
4426 callout_reset(&PISP_PCMD(ccb)->wdog, ts, isp_watchdog, ccb);
4427 break;
4428 case CMD_RQLATER:
4429 /*
4430 * We get this result for FC devices if the loop state isn't ready yet
4431 * or if the device in question has gone zombie on us.
4432 *
4433 * If we've never seen Loop UP at all, we requeue this request and wait

--- 10 unchanged lines hidden (view full) ---

4444 xpt_freeze_devq(ccb->ccb_h.path, 1);
4445 isp_free_pcmd(isp, ccb);
4446 xpt_done(ccb);
4447 break;
4448 }
4449 isp_prt(isp, ISP_LOGDEBUG0, "%d.%d retry later", XS_TGT(ccb), XS_LUN(ccb));
4450 cam_freeze_devq(ccb->ccb_h.path);
4451 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
4870 callout_reset(&PISP_PCMD(ccb)->wdog, ts, isp_watchdog, ccb);
4871 break;
4872 case CMD_RQLATER:
4873 /*
4874 * We get this result for FC devices if the loop state isn't ready yet
4875 * or if the device in question has gone zombie on us.
4876 *
4877 * If we've never seen Loop UP at all, we requeue this request and wait

--- 10 unchanged lines hidden (view full) ---

4888 xpt_freeze_devq(ccb->ccb_h.path, 1);
4889 isp_free_pcmd(isp, ccb);
4890 xpt_done(ccb);
4891 break;
4892 }
4893 isp_prt(isp, ISP_LOGDEBUG0, "%d.%d retry later", XS_TGT(ccb), XS_LUN(ccb));
4894 cam_freeze_devq(ccb->ccb_h.path);
4895 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
4452 XS_SETERR(ccb, CAM_REQUEUE_REQ);
4896 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4453 isp_free_pcmd(isp, ccb);
4454 xpt_done(ccb);
4455 break;
4456 case CMD_EAGAIN:
4457 isp_free_pcmd(isp, ccb);
4458 cam_freeze_devq(ccb->ccb_h.path);
4459 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 100, 0);
4897 isp_free_pcmd(isp, ccb);
4898 xpt_done(ccb);
4899 break;
4900 case CMD_EAGAIN:
4901 isp_free_pcmd(isp, ccb);
4902 cam_freeze_devq(ccb->ccb_h.path);
4903 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 100, 0);
4460 XS_SETERR(ccb, CAM_REQUEUE_REQ);
4904 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4461 xpt_done(ccb);
4462 break;
4463 case CMD_COMPLETE:
4464 isp_done((struct ccb_scsiio *) ccb);
4465 break;
4466 default:
4467 isp_prt(isp, ISP_LOGERR, "What's this? 0x%x at %d in file %s", error, __LINE__, __FILE__);
4905 xpt_done(ccb);
4906 break;
4907 case CMD_COMPLETE:
4908 isp_done((struct ccb_scsiio *) ccb);
4909 break;
4910 default:
4911 isp_prt(isp, ISP_LOGERR, "What's this? 0x%x at %d in file %s", error, __LINE__, __FILE__);
4468 XS_SETERR(ccb, CAM_REQ_CMP_ERR);
4912 ccb->ccb_h.status = CAM_REQUEUE_REQ;
4469 isp_free_pcmd(isp, ccb);
4470 xpt_done(ccb);
4471 }
4472 break;
4473
4474#ifdef ISP_TARGET_MODE
4475 case XPT_EN_LUN: /* Enable/Disable LUN as a target */
4476 if (ccb->cel.enable) {

--- 21 unchanged lines hidden (view full) ---

4498 tag = ccb->atio.tag_id;
4499 str = "XPT_ACCEPT_TARGET_IO";
4500 }
4501 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "%s: [0x%x] no state pointer found for %s\n", __func__, tag, str);
4502 dump_tstates(isp, XS_CHANNEL(ccb));
4503 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
4504 break;
4505 }
4913 isp_free_pcmd(isp, ccb);
4914 xpt_done(ccb);
4915 }
4916 break;
4917
4918#ifdef ISP_TARGET_MODE
4919 case XPT_EN_LUN: /* Enable/Disable LUN as a target */
4920 if (ccb->cel.enable) {

--- 21 unchanged lines hidden (view full) ---

4942 tag = ccb->atio.tag_id;
4943 str = "XPT_ACCEPT_TARGET_IO";
4944 }
4945 ISP_PATH_PRT(isp, ISP_LOGWARN, ccb->ccb_h.path, "%s: [0x%x] no state pointer found for %s\n", __func__, tag, str);
4946 dump_tstates(isp, XS_CHANNEL(ccb));
4947 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
4948 break;
4949 }
4506 ccb->ccb_h.sim_priv.entries[0].field = 0;
4507 ccb->ccb_h.sim_priv.entries[1].ptr = isp;
4950 ccb->ccb_h.spriv_field0 = 0;
4951 ccb->ccb_h.spriv_ptr1 = isp;
4508 ccb->ccb_h.flags = 0;
4509
4510 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
4511 if (ccb->atio.tag_id) {
4512 atio_private_data_t *atp = isp_get_atpd(isp, tptr, ccb->atio.tag_id);
4513 if (atp) {
4514 isp_put_atpd(isp, tptr, atp);
4515 }
4516 }
4517 tptr->atio_count++;
4518 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h, sim_links.sle);
4952 ccb->ccb_h.flags = 0;
4953
4954 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
4955 if (ccb->atio.tag_id) {
4956 atio_private_data_t *atp = isp_get_atpd(isp, tptr, ccb->atio.tag_id);
4957 if (atp) {
4958 isp_put_atpd(isp, tptr, atp);
4959 }
4960 }
4961 tptr->atio_count++;
4962 SLIST_INSERT_HEAD(&tptr->atios, &ccb->ccb_h, sim_links.sle);
4519 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "Put FREE ATIO (tag id 0x%x), count now %d\n",
4963 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE ATIO (tag id 0x%x), count now %d\n",
4520 ccb->atio.tag_id, tptr->atio_count);
4521 } else if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY) {
4522 if (ccb->cin1.tag_id) {
4523 inot_private_data_t *ntp = isp_find_ntpd(isp, tptr, ccb->cin1.tag_id, ccb->cin1.seq_id);
4524 if (ntp) {
4525 isp_put_ntpd(isp, tptr, ntp);
4526 }
4527 }
4528 tptr->inot_count++;
4529 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
4964 ccb->atio.tag_id, tptr->atio_count);
4965 } else if (ccb->ccb_h.func_code == XPT_IMMEDIATE_NOTIFY) {
4966 if (ccb->cin1.tag_id) {
4967 inot_private_data_t *ntp = isp_find_ntpd(isp, tptr, ccb->cin1.tag_id, ccb->cin1.seq_id);
4968 if (ntp) {
4969 isp_put_ntpd(isp, tptr, ntp);
4970 }
4971 }
4972 tptr->inot_count++;
4973 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
4530 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
4974 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
4531 ccb->cin1.seq_id, tptr->inot_count);
4532 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
4533 tptr->inot_count++;
4534 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
4975 ccb->cin1.seq_id, tptr->inot_count);
4976 } else if (ccb->ccb_h.func_code == XPT_IMMED_NOTIFY) {
4977 tptr->inot_count++;
4978 SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, sim_links.sle);
4535 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
4979 ISP_PATH_PRT(isp, ISP_LOGTDEBUG2, ccb->ccb_h.path, "Put FREE INOT, (seq id 0x%x) count now %d\n",
4536 ccb->cin1.seq_id, tptr->inot_count);
4537 }
4538 rls_lun_statep(isp, tptr);
4539 ccb->ccb_h.status = CAM_REQ_INPROG;
4540 break;
4541 }
4542 case XPT_NOTIFY_ACK:
4543 ccb->ccb_h.status = CAM_REQ_CMP_ERR;

--- 18 unchanged lines hidden (view full) ---

4562 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
4563 xpt_done(ccb);
4564 break;
4565 }
4566 if (isp_handle_platform_target_notify_ack(isp, &ntp->rd.nt)) {
4567 rls_lun_statep(isp, tptr);
4568 cam_freeze_devq(ccb->ccb_h.path);
4569 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
4980 ccb->cin1.seq_id, tptr->inot_count);
4981 }
4982 rls_lun_statep(isp, tptr);
4983 ccb->ccb_h.status = CAM_REQ_INPROG;
4984 break;
4985 }
4986 case XPT_NOTIFY_ACK:
4987 ccb->ccb_h.status = CAM_REQ_CMP_ERR;

--- 18 unchanged lines hidden (view full) ---

5006 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
5007 xpt_done(ccb);
5008 break;
5009 }
5010 if (isp_handle_platform_target_notify_ack(isp, &ntp->rd.nt)) {
5011 rls_lun_statep(isp, tptr);
5012 cam_freeze_devq(ccb->ccb_h.path);
5013 cam_release_devq(ccb->ccb_h.path, RELSIM_RELEASE_AFTER_TIMEOUT, 0, 1000, 0);
4570 XS_SETERR(ccb, CAM_REQUEUE_REQ);
5014 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
5015 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
4571 break;
4572 }
4573 isp_put_ntpd(isp, tptr, ntp);
4574 rls_lun_statep(isp, tptr);
4575 ccb->ccb_h.status = CAM_REQ_CMP;
4576 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: [0x%x] calling xpt_done for tag 0x%x\n", __func__, ccb->cna2.tag_id, ccb->cna2.seq_id);
4577 xpt_done(ccb);
4578 break;
4579 }
4580 case XPT_CONT_TARGET_IO:
5016 break;
5017 }
5018 isp_put_ntpd(isp, tptr, ntp);
5019 rls_lun_statep(isp, tptr);
5020 ccb->ccb_h.status = CAM_REQ_CMP;
5021 ISP_PATH_PRT(isp, ISP_LOGTDEBUG0, ccb->ccb_h.path, "%s: [0x%x] calling xpt_done for tag 0x%x\n", __func__, ccb->cna2.tag_id, ccb->cna2.seq_id);
5022 xpt_done(ccb);
5023 break;
5024 }
5025 case XPT_CONT_TARGET_IO:
4581 isp_target_start_ctio(isp, ccb);
5026 isp_target_start_ctio(isp, ccb, FROM_CAM);
4582 break;
4583#endif
4584 case XPT_RESET_DEV: /* BDR the specified SCSI device */
4585
4586 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
4587 tgt = ccb->ccb_h.target_id;
4588 tgt |= (bus << 16);
4589

--- 279 unchanged lines hidden (view full) ---

4869 */
4870 isp_prt(isp, ISP_LOGERR, "cannot support dual role at present");
4871 ccb->ccb_h.status = CAM_REQ_INVALID;
4872#endif
4873 break;
4874 }
4875 if (rchange) {
4876 ISP_PATH_PRT(isp, ISP_LOGCONFIG, ccb->ccb_h.path, "changing role on from %d to %d\n", fcp->role, newrole);
5027 break;
5028#endif
5029 case XPT_RESET_DEV: /* BDR the specified SCSI device */
5030
5031 bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
5032 tgt = ccb->ccb_h.target_id;
5033 tgt |= (bus << 16);
5034

--- 279 unchanged lines hidden (view full) ---

5314 */
5315 isp_prt(isp, ISP_LOGERR, "cannot support dual role at present");
5316 ccb->ccb_h.status = CAM_REQ_INVALID;
5317#endif
5318 break;
5319 }
5320 if (rchange) {
5321 ISP_PATH_PRT(isp, ISP_LOGCONFIG, ccb->ccb_h.path, "changing role on from %d to %d\n", fcp->role, newrole);
5322#ifdef ISP_TARGET_MODE
5323 ISP_SET_PC(isp, bus, tm_enabled, 0);
5324 ISP_SET_PC(isp, bus, tm_luns_enabled, 0);
5325#endif
4877 if (isp_fc_change_role(isp, bus, newrole) != 0) {
4878 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5326 if (isp_fc_change_role(isp, bus, newrole) != 0) {
5327 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
5328 xpt_done(ccb);
5329 break;
5330 }
4879#ifdef ISP_TARGET_MODE
5331#ifdef ISP_TARGET_MODE
4880 } else if (newrole == ISP_ROLE_TARGET || newrole == ISP_ROLE_BOTH) {
5332 if (newrole == ISP_ROLE_TARGET || newrole == ISP_ROLE_BOTH) {
5333 /*
5334 * Give the new role a chance to complain and settle
5335 */
5336 msleep(isp, &isp->isp_lock, PRIBIO, "taking a breather", 2);
4881 ccb->ccb_h.status = isp_enable_deferred_luns(isp, bus);
5337 ccb->ccb_h.status = isp_enable_deferred_luns(isp, bus);
4882#endif
4883 }
5338 }
5339#endif
4884 }
4885 }
4886 xpt_done(ccb);
4887 break;
4888 }
4889 case XPT_GET_SIM_KNOB: /* Get SIM knobs */
4890 {
4891 struct ccb_sim_knob *kp = &ccb->knob;

--- 129 unchanged lines hidden (view full) ---

5021 xpt_freeze_devq(sccb->ccb_h.path, 1);
5022 }
5023 }
5024
5025 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) && (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5026 xpt_print(sccb->ccb_h.path, "cam completion status 0x%x\n", sccb->ccb_h.status);
5027 }
5028
5340 }
5341 }
5342 xpt_done(ccb);
5343 break;
5344 }
5345 case XPT_GET_SIM_KNOB: /* Get SIM knobs */
5346 {
5347 struct ccb_sim_knob *kp = &ccb->knob;

--- 129 unchanged lines hidden (view full) ---

5477 xpt_freeze_devq(sccb->ccb_h.path, 1);
5478 }
5479 }
5480
5481 if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) && (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5482 xpt_print(sccb->ccb_h.path, "cam completion status 0x%x\n", sccb->ccb_h.status);
5483 }
5484
5029 XS_CMD_S_DONE(sccb);
5030 if (XS_TACTIVE_P(sccb))
5485 if (callout_active(&PISP_PCMD(sccb)->wdog))
5031 callout_stop(&PISP_PCMD(sccb)->wdog);
5486 callout_stop(&PISP_PCMD(sccb)->wdog);
5032 XS_CMD_S_CLEAR(sccb);
5033 isp_free_pcmd(isp, (union ccb *) sccb);
5034 xpt_done((union ccb *) sccb);
5035}
5036
5037void
5038isp_async(ispsoftc_t *isp, ispasync_t cmd, ...)
5039{
5040 int bus;
5487 isp_free_pcmd(isp, (union ccb *) sccb);
5488 xpt_done((union ccb *) sccb);
5489}
5490
5491void
5492isp_async(ispsoftc_t *isp, ispasync_t cmd, ...)
5493{
5494 int bus;
5041 static const char prom[] = "Chan %d PortID 0x%06x handle 0x%x role %s %s WWPN 0x%08x%08x";
5042 static const char prom2[] = "Chan %d PortID 0x%06x handle 0x%x role %s %s tgt %u WWPN 0x%08x%08x";
5495 static const char prom0[] = "Chan %d PortID 0x%06x handle 0x%x %s %s WWPN 0x%08x%08x";
5496 static const char prom2[] = "Chan %d PortID 0x%06x handle 0x%x %s %s tgt %u WWPN 0x%08x%08x";
5497 char buf[64];
5043 char *msg = NULL;
5044 target_id_t tgt;
5045 fcportdb_t *lp;
5046 struct isp_fc *fc;
5047 struct cam_path *tmppath;
5048 va_list ap;
5049
5050 switch (cmd) {

--- 92 unchanged lines hidden (view full) ---

5143 * We don't do any simq freezing if we are only in target mode
5144 */
5145 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5146 if (fc->path) {
5147 isp_freeze_loopdown(isp, bus, msg);
5148 }
5149 if (!callout_active(&fc->ldt)) {
5150 callout_reset(&fc->ldt, fc->loop_down_limit * hz, isp_ldt, fc);
5498 char *msg = NULL;
5499 target_id_t tgt;
5500 fcportdb_t *lp;
5501 struct isp_fc *fc;
5502 struct cam_path *tmppath;
5503 va_list ap;
5504
5505 switch (cmd) {

--- 92 unchanged lines hidden (view full) ---

5598 * We don't do any simq freezing if we are only in target mode
5599 */
5600 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5601 if (fc->path) {
5602 isp_freeze_loopdown(isp, bus, msg);
5603 }
5604 if (!callout_active(&fc->ldt)) {
5605 callout_reset(&fc->ldt, fc->loop_down_limit * hz, isp_ldt, fc);
5151 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Starting Loop Down Timer @ %lu", (unsigned long) time_uptime);
5606 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Starting Loop Down Timer @ %lu", (unsigned long) time_uptime);
5152 }
5153 }
5154 }
5155 isp_prt(isp, ISP_LOGINFO, "Chan %d: %s", bus, msg);
5156 break;
5157 }
5158 case ISPASYNC_LOOP_UP:
5159 va_start(ap, cmd);

--- 12 unchanged lines hidden (view full) ---

5172 isp_prt(isp, ISP_LOGINFO, "Chan %d Loop UP", bus);
5173 break;
5174 case ISPASYNC_DEV_ARRIVED:
5175 va_start(ap, cmd);
5176 bus = va_arg(ap, int);
5177 lp = va_arg(ap, fcportdb_t *);
5178 va_end(ap);
5179 fc = ISP_FC_PC(isp, bus);
5607 }
5608 }
5609 }
5610 isp_prt(isp, ISP_LOGINFO, "Chan %d: %s", bus, msg);
5611 break;
5612 }
5613 case ISPASYNC_LOOP_UP:
5614 va_start(ap, cmd);

--- 12 unchanged lines hidden (view full) ---

5627 isp_prt(isp, ISP_LOGINFO, "Chan %d Loop UP", bus);
5628 break;
5629 case ISPASYNC_DEV_ARRIVED:
5630 va_start(ap, cmd);
5631 bus = va_arg(ap, int);
5632 lp = va_arg(ap, fcportdb_t *);
5633 va_end(ap);
5634 fc = ISP_FC_PC(isp, bus);
5180 lp->reserved = 0;
5635 lp->announced = 0;
5181 lp->gone_timer = 0;
5636 lp->gone_timer = 0;
5182 if ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) && (lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT))) {
5637 if ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) && (lp->prli_word3 & PRLI_WD3_TARGET_FUNCTION)) {
5183 int dbidx = lp - FCPARAM(isp, bus)->portdb;
5184 int i;
5185
5186 for (i = 0; i < MAX_FC_TARG; i++) {
5187 if (i >= FL_ID && i <= SNS_ID) {
5188 continue;
5189 }
5190 if (FCPARAM(isp, bus)->isp_dev_map[i] == 0) {
5191 break;
5192 }
5193 }
5194 if (i < MAX_FC_TARG) {
5195 FCPARAM(isp, bus)->isp_dev_map[i] = dbidx + 1;
5196 lp->dev_map_idx = i + 1;
5197 } else {
5198 isp_prt(isp, ISP_LOGWARN, "out of target ids");
5199 isp_dump_portdb(isp, bus);
5200 }
5201 }
5638 int dbidx = lp - FCPARAM(isp, bus)->portdb;
5639 int i;
5640
5641 for (i = 0; i < MAX_FC_TARG; i++) {
5642 if (i >= FL_ID && i <= SNS_ID) {
5643 continue;
5644 }
5645 if (FCPARAM(isp, bus)->isp_dev_map[i] == 0) {
5646 break;
5647 }
5648 }
5649 if (i < MAX_FC_TARG) {
5650 FCPARAM(isp, bus)->isp_dev_map[i] = dbidx + 1;
5651 lp->dev_map_idx = i + 1;
5652 } else {
5653 isp_prt(isp, ISP_LOGWARN, "out of target ids");
5654 isp_dump_portdb(isp, bus);
5655 }
5656 }
5657 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5202 if (lp->dev_map_idx) {
5203 tgt = lp->dev_map_idx - 1;
5658 if (lp->dev_map_idx) {
5659 tgt = lp->dev_map_idx - 1;
5204 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, roles[lp->roles], "arrived at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5660 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "arrived at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5205 isp_make_here(isp, bus, tgt);
5206 } else {
5661 isp_make_here(isp, bus, tgt);
5662 } else {
5207 isp_prt(isp, ISP_LOGCONFIG, prom, bus, lp->portid, lp->handle, roles[lp->roles], "arrived", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5663 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "arrived", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5208 }
5209 break;
5210 case ISPASYNC_DEV_CHANGED:
5211 va_start(ap, cmd);
5212 bus = va_arg(ap, int);
5213 lp = va_arg(ap, fcportdb_t *);
5214 va_end(ap);
5215 fc = ISP_FC_PC(isp, bus);
5664 }
5665 break;
5666 case ISPASYNC_DEV_CHANGED:
5667 va_start(ap, cmd);
5668 bus = va_arg(ap, int);
5669 lp = va_arg(ap, fcportdb_t *);
5670 va_end(ap);
5671 fc = ISP_FC_PC(isp, bus);
5216 lp->reserved = 0;
5672 lp->announced = 0;
5217 lp->gone_timer = 0;
5218 if (isp_change_is_bad) {
5219 lp->state = FC_PORTDB_STATE_NIL;
5220 if (lp->dev_map_idx) {
5221 tgt = lp->dev_map_idx - 1;
5222 FCPARAM(isp, bus)->isp_dev_map[tgt] = 0;
5223 lp->dev_map_idx = 0;
5224 isp_prt(isp, ISP_LOGCONFIG, prom3, bus, lp->portid, tgt, "change is bad");
5225 isp_make_gone(isp, bus, tgt);
5226 } else {
5673 lp->gone_timer = 0;
5674 if (isp_change_is_bad) {
5675 lp->state = FC_PORTDB_STATE_NIL;
5676 if (lp->dev_map_idx) {
5677 tgt = lp->dev_map_idx - 1;
5678 FCPARAM(isp, bus)->isp_dev_map[tgt] = 0;
5679 lp->dev_map_idx = 0;
5680 isp_prt(isp, ISP_LOGCONFIG, prom3, bus, lp->portid, tgt, "change is bad");
5681 isp_make_gone(isp, bus, tgt);
5682 } else {
5227 isp_prt(isp, ISP_LOGCONFIG, prom, bus, lp->portid, lp->handle, roles[lp->roles], "changed and departed",
5683 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5684 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "changed and departed",
5228 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5229 }
5230 } else {
5231 lp->portid = lp->new_portid;
5685 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5686 }
5687 } else {
5688 lp->portid = lp->new_portid;
5232 lp->roles = lp->new_roles;
5689 lp->prli_word3 = lp->new_prli_word3;
5690 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5233 if (lp->dev_map_idx) {
5234 int t = lp->dev_map_idx - 1;
5235 FCPARAM(isp, bus)->isp_dev_map[t] = (lp - FCPARAM(isp, bus)->portdb) + 1;
5236 tgt = lp->dev_map_idx - 1;
5691 if (lp->dev_map_idx) {
5692 int t = lp->dev_map_idx - 1;
5693 FCPARAM(isp, bus)->isp_dev_map[t] = (lp - FCPARAM(isp, bus)->portdb) + 1;
5694 tgt = lp->dev_map_idx - 1;
5237 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, roles[lp->roles], "changed at", tgt,
5695 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "changed at", tgt,
5238 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5239 } else {
5696 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5697 } else {
5240 isp_prt(isp, ISP_LOGCONFIG, prom, bus, lp->portid, lp->handle, roles[lp->roles], "changed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5698 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "changed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5241 }
5242 }
5243 break;
5244 case ISPASYNC_DEV_STAYED:
5245 va_start(ap, cmd);
5246 bus = va_arg(ap, int);
5247 lp = va_arg(ap, fcportdb_t *);
5248 va_end(ap);
5699 }
5700 }
5701 break;
5702 case ISPASYNC_DEV_STAYED:
5703 va_start(ap, cmd);
5704 bus = va_arg(ap, int);
5705 lp = va_arg(ap, fcportdb_t *);
5706 va_end(ap);
5707 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5249 if (lp->dev_map_idx) {
5250 tgt = lp->dev_map_idx - 1;
5708 if (lp->dev_map_idx) {
5709 tgt = lp->dev_map_idx - 1;
5251 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, roles[lp->roles], "stayed at", tgt,
5710 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "stayed at", tgt,
5252 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5253 } else {
5711 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5712 } else {
5254 isp_prt(isp, ISP_LOGCONFIG, prom, bus, lp->portid, lp->handle, roles[lp->roles], "stayed",
5713 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "stayed",
5255 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5256 }
5257 break;
5258 case ISPASYNC_DEV_GONE:
5259 va_start(ap, cmd);
5260 bus = va_arg(ap, int);
5261 lp = va_arg(ap, fcportdb_t *);
5262 va_end(ap);
5263 fc = ISP_FC_PC(isp, bus);
5264 /*
5265 * If this has a virtual target and we haven't marked it
5266 * that we're going to have isp_gdt tell the OS it's gone,
5267 * set the isp_gdt timer running on it.
5268 *
5269 * If it isn't marked that isp_gdt is going to get rid of it,
5270 * announce that it's gone.
5271 *
5272 */
5714 (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5715 }
5716 break;
5717 case ISPASYNC_DEV_GONE:
5718 va_start(ap, cmd);
5719 bus = va_arg(ap, int);
5720 lp = va_arg(ap, fcportdb_t *);
5721 va_end(ap);
5722 fc = ISP_FC_PC(isp, bus);
5723 /*
5724 * If this has a virtual target and we haven't marked it
5725 * that we're going to have isp_gdt tell the OS it's gone,
5726 * set the isp_gdt timer running on it.
5727 *
5728 * If it isn't marked that isp_gdt is going to get rid of it,
5729 * announce that it's gone.
5730 *
5731 */
5273 if (lp->dev_map_idx && lp->reserved == 0) {
5274 lp->reserved = 1;
5732 isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
5733 if (lp->dev_map_idx && lp->announced == 0) {
5734 lp->announced = 1;
5275 lp->state = FC_PORTDB_STATE_ZOMBIE;
5276 lp->gone_timer = ISP_FC_PC(isp, bus)->gone_device_time;
5277 if (fc->ready && !callout_active(&fc->gdt)) {
5735 lp->state = FC_PORTDB_STATE_ZOMBIE;
5736 lp->gone_timer = ISP_FC_PC(isp, bus)->gone_device_time;
5737 if (fc->ready && !callout_active(&fc->gdt)) {
5278 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d Starting Gone Device Timer with %u seconds time now %lu", bus, lp->gone_timer, (unsigned long)time_uptime);
5738 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Chan %d Starting Gone Device Timer with %u seconds time now %lu", bus, lp->gone_timer, (unsigned long)time_uptime);
5279 callout_reset(&fc->gdt, hz, isp_gdt, fc);
5280 }
5281 tgt = lp->dev_map_idx - 1;
5739 callout_reset(&fc->gdt, hz, isp_gdt, fc);
5740 }
5741 tgt = lp->dev_map_idx - 1;
5282 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, roles[lp->roles], "gone zombie at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5283 } else if (lp->reserved == 0) {
5284 isp_prt(isp, ISP_LOGCONFIG, prom, bus, lp->portid, lp->handle, roles[lp->roles], "departed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5742 isp_prt(isp, ISP_LOGCONFIG, prom2, bus, lp->portid, lp->handle, buf, "gone zombie at", tgt, (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5743 } else if (lp->announced == 0) {
5744 isp_prt(isp, ISP_LOGCONFIG, prom0, bus, lp->portid, lp->handle, buf, "departed", (uint32_t) (lp->port_wwn >> 32), (uint32_t) lp->port_wwn);
5285 }
5286 break;
5287 case ISPASYNC_CHANGE_NOTIFY:
5288 {
5289 char *msg;
5290 int evt, nphdl, nlstate, reason;
5291
5292 va_start(ap, cmd);

--- 17 unchanged lines hidden (view full) ---

5310 } else {
5311 msg = "Chan %d Other Change Notify";
5312 }
5313
5314 /*
5315 * If the loop down timer is running, cancel it.
5316 */
5317 if (fc->ready && callout_active(&fc->ldt)) {
5745 }
5746 break;
5747 case ISPASYNC_CHANGE_NOTIFY:
5748 {
5749 char *msg;
5750 int evt, nphdl, nlstate, reason;
5751
5752 va_start(ap, cmd);

--- 17 unchanged lines hidden (view full) ---

5770 } else {
5771 msg = "Chan %d Other Change Notify";
5772 }
5773
5774 /*
5775 * If the loop down timer is running, cancel it.
5776 */
5777 if (fc->ready && callout_active(&fc->ldt)) {
5318 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Stopping Loop Down Timer @ %lu", (unsigned long) time_uptime);
5778 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGDEBUG0, "Stopping Loop Down Timer @ %lu", (unsigned long) time_uptime);
5319 callout_stop(&fc->ldt);
5320 }
5321 isp_prt(isp, ISP_LOGINFO, msg, bus);
5322 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5323 isp_freeze_loopdown(isp, bus, msg);
5324 }
5325 wakeup(fc);
5326 break;

--- 23 unchanged lines hidden (view full) ---

5350 case NT_LINK_DOWN:
5351 /*
5352 * No action need be taken here.
5353 */
5354 break;
5355 case NT_HBA_RESET:
5356 isp_del_all_wwn_entries(isp, ISP_NOCHAN);
5357 break;
5779 callout_stop(&fc->ldt);
5780 }
5781 isp_prt(isp, ISP_LOGINFO, msg, bus);
5782 if (FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) {
5783 isp_freeze_loopdown(isp, bus, msg);
5784 }
5785 wakeup(fc);
5786 break;

--- 23 unchanged lines hidden (view full) ---

5810 case NT_LINK_DOWN:
5811 /*
5812 * No action need be taken here.
5813 */
5814 break;
5815 case NT_HBA_RESET:
5816 isp_del_all_wwn_entries(isp, ISP_NOCHAN);
5817 break;
5818 case NT_GLOBAL_LOGOUT:
5358 case NT_LOGOUT:
5359 /*
5360 * This is device arrival/departure notification
5361 */
5362 isp_handle_platform_target_notify_ack(isp, notify);
5363 break;
5364 case NT_ARRIVED:
5365 {

--- 25 unchanged lines hidden (view full) ---

5391 }
5392 default:
5393 isp_prt(isp, ISP_LOGALL, "target notify code 0x%x", notify->nt_ncode);
5394 isp_handle_platform_target_notify_ack(isp, notify);
5395 break;
5396 }
5397 break;
5398 }
5819 case NT_LOGOUT:
5820 /*
5821 * This is device arrival/departure notification
5822 */
5823 isp_handle_platform_target_notify_ack(isp, notify);
5824 break;
5825 case NT_ARRIVED:
5826 {

--- 25 unchanged lines hidden (view full) ---

5852 }
5853 default:
5854 isp_prt(isp, ISP_LOGALL, "target notify code 0x%x", notify->nt_ncode);
5855 isp_handle_platform_target_notify_ack(isp, notify);
5856 break;
5857 }
5858 break;
5859 }
5860 case ISPASYNC_TARGET_NOTIFY_ACK:
5861 {
5862 void *inot;
5863 va_start(ap, cmd);
5864 inot = va_arg(ap, void *);
5865 va_end(ap);
5866 if (isp_notify_ack(isp, inot)) {
5867 isp_tna_t *tp = malloc(sizeof (*tp), M_DEVBUF, M_NOWAIT);
5868 if (tp) {
5869 tp->isp = isp;
5870 if (inot) {
5871 memcpy(tp->data, inot, sizeof (tp->data));
5872 tp->not = tp->data;
5873 } else {
5874 tp->not = NULL;
5875 }
5876 (void) timeout(isp_refire_notify_ack, tp, 5);
5877 } else {
5878 isp_prt(isp, ISP_LOGERR, "you lose- cannot allocate a notify refire");
5879 }
5880 }
5881 break;
5882 }
5399 case ISPASYNC_TARGET_ACTION:
5400 {
5401 isphdr_t *hp;
5402
5403 va_start(ap, cmd);
5404 hp = va_arg(ap, isphdr_t *);
5405 va_end(ap);
5406 switch (hp->rqs_entry_type) {

--- 216 unchanged lines hidden (view full) ---

5623 }
5624 return (seed);
5625}
5626
5627void
5628isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
5629{
5630 int loc;
5883 case ISPASYNC_TARGET_ACTION:
5884 {
5885 isphdr_t *hp;
5886
5887 va_start(ap, cmd);
5888 hp = va_arg(ap, isphdr_t *);
5889 va_end(ap);
5890 switch (hp->rqs_entry_type) {

--- 216 unchanged lines hidden (view full) ---

6107 }
6108 return (seed);
6109}
6110
6111void
6112isp_prt(ispsoftc_t *isp, int level, const char *fmt, ...)
6113{
6114 int loc;
5631 char lbuf[128];
6115 char lbuf[200];
5632 va_list ap;
5633
5634 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
5635 return;
5636 }
6116 va_list ap;
6117
6118 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
6119 return;
6120 }
5637 sprintf(lbuf, "%s: ", device_get_nameunit(isp->isp_dev));
6121 snprintf(lbuf, sizeof (lbuf), "%s: ", device_get_nameunit(isp->isp_dev));
5638 loc = strlen(lbuf);
5639 va_start(ap, fmt);
5640 vsnprintf(&lbuf[loc], sizeof (lbuf) - loc - 1, fmt, ap);
5641 va_end(ap);
5642 printf("%s\n", lbuf);
5643}
5644
5645void

--- 154 unchanged lines hidden (view full) ---

5800 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
5801 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTREAD);
5802 } else {
5803 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTWRITE);
5804 }
5805 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
5806}
5807
6122 loc = strlen(lbuf);
6123 va_start(ap, fmt);
6124 vsnprintf(&lbuf[loc], sizeof (lbuf) - loc - 1, fmt, ap);
6125 va_end(ap);
6126 printf("%s\n", lbuf);
6127}
6128
6129void

--- 154 unchanged lines hidden (view full) ---

6284 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
6285 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTREAD);
6286 } else {
6287 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_POSTWRITE);
6288 }
6289 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
6290}
6291
6292int
6293isp_fcp_next_crn(ispsoftc_t *isp, uint8_t *crnp, XS_T *cmd)
6294{
6295 uint32_t chan = XS_CHANNEL(cmd);
6296 uint32_t tgt = XS_TGT(cmd);
6297 uint32_t lun = XS_LUN(cmd);
6298 struct isp_fc *fc = &isp->isp_osinfo.pc.fc[chan];
6299 int idx = NEXUS_HASH(tgt, lun);
6300 struct isp_nexus *nxp = fc->nexus_hash[idx];
6301
6302 while (nxp) {
6303 if (nxp->tgt == tgt && nxp->lun == lun)
6304 break;
6305 nxp = nxp->next;
6306 }
6307 if (nxp == NULL) {
6308 nxp = fc->nexus_free_list;
6309 if (nxp == NULL) {
6310 nxp = malloc(sizeof (struct isp_nexus), M_DEVBUF, M_ZERO|M_NOWAIT);
6311 if (nxp == NULL) {
6312 return (-1);
6313 }
6314 } else {
6315 fc->nexus_free_list = nxp->next;
6316 }
6317 nxp->tgt = tgt;
6318 nxp->lun = lun;
6319 nxp->next = fc->nexus_hash[idx];
6320 fc->nexus_hash[idx] = nxp;
6321 }
6322 if (nxp) {
6323 if (nxp->crnseed == 0)
6324 nxp->crnseed = 1;
6325 if (cmd)
6326 PISP_PCMD(cmd)->crn = nxp->crnseed;
6327 *crnp = nxp->crnseed++;
6328 return (0);
6329 }
6330 return (-1);
6331}
6332
5808void
5809isp_timer(void *arg)
5810{
5811 ispsoftc_t *isp = arg;
5812#ifdef ISP_TARGET_MODE
5813 isp_tmcmd_restart(isp);
5814#endif
5815 callout_reset(&isp->isp_osinfo.tmo, hz, isp_timer, isp);
5816}
6333void
6334isp_timer(void *arg)
6335{
6336 ispsoftc_t *isp = arg;
6337#ifdef ISP_TARGET_MODE
6338 isp_tmcmd_restart(isp);
6339#endif
6340 callout_reset(&isp->isp_osinfo.tmo, hz, isp_timer, isp);
6341}
6342
6343isp_ecmd_t *
6344isp_get_ecmd(ispsoftc_t *isp)
6345{
6346 isp_ecmd_t *ecmd = isp->isp_osinfo.ecmd_free;
6347 if (ecmd) {
6348 isp->isp_osinfo.ecmd_free = ecmd->next;
6349 }
6350 return (ecmd);
6351}
6352
6353void
6354isp_put_ecmd(ispsoftc_t *isp, isp_ecmd_t *ecmd)
6355{
6356 ecmd->next = isp->isp_osinfo.ecmd_free;
6357 isp->isp_osinfo.ecmd_free = ecmd;
6358}