1c3aac50fSPeter Wemm /* $FreeBSD$ */ 26054c3f6SMatt Jacob /* 36054c3f6SMatt Jacob * Platform (FreeBSD) dependent common attachment code for Qlogic adapters. 46054c3f6SMatt Jacob * 55f5aafe1SMatt Jacob * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob 66054c3f6SMatt Jacob * 76054c3f6SMatt Jacob * Redistribution and use in source and binary forms, with or without 86054c3f6SMatt Jacob * modification, are permitted provided that the following conditions 96054c3f6SMatt Jacob * are met: 106054c3f6SMatt Jacob * 1. Redistributions of source code must retain the above copyright 116054c3f6SMatt Jacob * notice immediately at the beginning of the file, without modification, 126054c3f6SMatt Jacob * this list of conditions, and the following disclaimer. 13aa57fd6fSMatt Jacob * 2. The name of the author may not be used to endorse or promote products 14aa57fd6fSMatt Jacob * derived from this software without specific prior written permission. 156054c3f6SMatt Jacob * 166054c3f6SMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 176054c3f6SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 186054c3f6SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 196054c3f6SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 206054c3f6SMatt Jacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 216054c3f6SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 226054c3f6SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 236054c3f6SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 246054c3f6SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 256054c3f6SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 266054c3f6SMatt Jacob * SUCH DAMAGE. 276054c3f6SMatt Jacob */ 286054c3f6SMatt Jacob #include <dev/isp/isp_freebsd.h> 295d571944SMatt Jacob #include <sys/unistd.h> 305d571944SMatt Jacob #include <sys/kthread.h> 313ea883b4SMatt Jacob #include <machine/stdarg.h> /* for use by isp_prt below */ 325d571944SMatt Jacob #include <sys/conf.h> 335d571944SMatt Jacob #include <sys/ioccom.h> 345d571944SMatt Jacob #include <dev/isp/isp_ioctl.h> 356054c3f6SMatt Jacob 36a1bc34c6SMatt Jacob 375d571944SMatt Jacob static d_ioctl_t ispioctl; 38f6e75de2SMatt Jacob static void isp_intr_enable(void *); 390470d791SMatt Jacob static void isp_cam_async(void *, u_int32_t, struct cam_path *, void *); 400470d791SMatt Jacob static void isp_poll(struct cam_sim *); 415d571944SMatt Jacob #if 0 420470d791SMatt Jacob static void isp_relsim(void *); 435d571944SMatt Jacob #endif 44b85389e1SMatt Jacob static timeout_t isp_watchdog; 455d571944SMatt Jacob static void isp_kthread(void *); 46d81ba9d5SMatt Jacob static void isp_action(struct cam_sim *, union ccb *); 470470d791SMatt Jacob 48cc8df88bSMatt Jacob 495d571944SMatt Jacob #define ISP_CDEV_MAJOR 248 505d571944SMatt Jacob static struct cdevsw isp_cdevsw = { 515d571944SMatt Jacob /* open */ nullopen, 525d571944SMatt Jacob /* close */ nullclose, 535d571944SMatt Jacob /* read */ noread, 545d571944SMatt Jacob /* write */ nowrite, 555d571944SMatt Jacob /* ioctl */ ispioctl, 565d571944SMatt Jacob /* poll */ nopoll, 575d571944SMatt Jacob /* mmap */ nommap, 585d571944SMatt Jacob /* strategy */ nostrategy, 595d571944SMatt Jacob /* name */ "isp", 605d571944SMatt Jacob /* maj */ ISP_CDEV_MAJOR, 615d571944SMatt Jacob /* dump */ nodump, 625d571944SMatt Jacob /* psize */ nopsize, 635d571944SMatt Jacob /* flags */ D_TAPE, 645d571944SMatt Jacob }; 655d571944SMatt Jacob 66d81ba9d5SMatt Jacob static struct ispsoftc *isplist = NULL; 67478f8a96SJustin T. Gibbs 68478f8a96SJustin T. Gibbs void 69c3055363SMatt Jacob isp_attach(struct ispsoftc *isp) 70478f8a96SJustin T. Gibbs { 71ea6f23cdSMatt Jacob int primary, secondary; 72478f8a96SJustin T. Gibbs struct ccb_setasync csa; 73478f8a96SJustin T. Gibbs struct cam_devq *devq; 74ea6f23cdSMatt Jacob struct cam_sim *sim; 75ea6f23cdSMatt Jacob struct cam_path *path; 76478f8a96SJustin T. Gibbs 77478f8a96SJustin T. Gibbs /* 78ea6f23cdSMatt Jacob * Establish (in case of 12X0) which bus is the primary. 79ea6f23cdSMatt Jacob */ 80ea6f23cdSMatt Jacob 81ea6f23cdSMatt Jacob primary = 0; 82ea6f23cdSMatt Jacob secondary = 1; 83ea6f23cdSMatt Jacob 84ea6f23cdSMatt Jacob /* 85ea6f23cdSMatt Jacob * Create the device queue for our SIM(s). 86478f8a96SJustin T. Gibbs */ 87ab6c4b31SMatt Jacob devq = cam_simq_alloc(isp->isp_maxcmds); 88478f8a96SJustin T. Gibbs if (devq == NULL) { 89478f8a96SJustin T. Gibbs return; 90478f8a96SJustin T. Gibbs } 91478f8a96SJustin T. Gibbs 92478f8a96SJustin T. Gibbs /* 93ea6f23cdSMatt Jacob * Construct our SIM entry. 94478f8a96SJustin T. Gibbs */ 9545c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 96ea6f23cdSMatt Jacob sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp, 973c75bb14SMatt Jacob device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq); 98ea6f23cdSMatt Jacob if (sim == NULL) { 99478f8a96SJustin T. Gibbs cam_simq_free(devq); 10045c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 101478f8a96SJustin T. Gibbs return; 102478f8a96SJustin T. Gibbs } 10345c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 104f6e75de2SMatt Jacob 105f6e75de2SMatt Jacob isp->isp_osinfo.ehook.ich_func = isp_intr_enable; 106f6e75de2SMatt Jacob isp->isp_osinfo.ehook.ich_arg = isp; 10745c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 108f6e75de2SMatt Jacob if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) { 10945c9a36aSMatt Jacob cam_sim_free(sim, TRUE); 11045c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 111bfbab170SMatt Jacob isp_prt(isp, ISP_LOGERR, 112bfbab170SMatt Jacob "could not establish interrupt enable hook"); 113f6e75de2SMatt Jacob return; 114f6e75de2SMatt Jacob } 115f6e75de2SMatt Jacob 116ea6f23cdSMatt Jacob if (xpt_bus_register(sim, primary) != CAM_SUCCESS) { 117ea6f23cdSMatt Jacob cam_sim_free(sim, TRUE); 11845c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 119478f8a96SJustin T. Gibbs return; 120478f8a96SJustin T. Gibbs } 121478f8a96SJustin T. Gibbs 122ea6f23cdSMatt Jacob if (xpt_create_path(&path, NULL, cam_sim_path(sim), 123478f8a96SJustin T. Gibbs CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 124ea6f23cdSMatt Jacob xpt_bus_deregister(cam_sim_path(sim)); 125ea6f23cdSMatt Jacob cam_sim_free(sim, TRUE); 1265d571944SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 12745c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 128478f8a96SJustin T. Gibbs return; 129478f8a96SJustin T. Gibbs } 130478f8a96SJustin T. Gibbs 131ea6f23cdSMatt Jacob xpt_setup_ccb(&csa.ccb_h, path, 5); 132478f8a96SJustin T. Gibbs csa.ccb_h.func_code = XPT_SASYNC_CB; 133478f8a96SJustin T. Gibbs csa.event_enable = AC_LOST_DEVICE; 134cbf57b47SMatt Jacob csa.callback = isp_cam_async; 135ea6f23cdSMatt Jacob csa.callback_arg = sim; 136478f8a96SJustin T. Gibbs xpt_action((union ccb *)&csa); 13745c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 138ea6f23cdSMatt Jacob isp->isp_sim = sim; 139ea6f23cdSMatt Jacob isp->isp_path = path; 1405d571944SMatt Jacob /* 1415d571944SMatt Jacob * Create a kernel thread for fibre channel instances. We 1425d571944SMatt Jacob * don't have dual channel FC cards. 1435d571944SMatt Jacob */ 1445d571944SMatt Jacob if (IS_FC(isp)) { 14545c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 14645c9a36aSMatt Jacob /* XXX: LOCK VIOLATION */ 1475d571944SMatt Jacob cv_init(&isp->isp_osinfo.kthread_cv, "isp_kthread_cv"); 1485d571944SMatt Jacob if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kproc, 1495d571944SMatt Jacob RFHIGHPID, "%s: fc_thrd", 1505d571944SMatt Jacob device_get_nameunit(isp->isp_dev))) { 1515d571944SMatt Jacob xpt_bus_deregister(cam_sim_path(sim)); 1525d571944SMatt Jacob cam_sim_free(sim, TRUE); 1535d571944SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 15445c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 15545c9a36aSMatt Jacob isp_prt(isp, ISP_LOGERR, "could not create kthread"); 1565d571944SMatt Jacob return; 1575d571944SMatt Jacob } 1588e6a12fcSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1595d571944SMatt Jacob } 1605d571944SMatt Jacob 161478f8a96SJustin T. Gibbs 162ea6f23cdSMatt Jacob /* 163ea6f23cdSMatt Jacob * If we have a second channel, construct SIM entry for that. 164ea6f23cdSMatt Jacob */ 16522e1dc85SMatt Jacob if (IS_DUALBUS(isp)) { 16645c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 167ea6f23cdSMatt Jacob sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp, 1683c75bb14SMatt Jacob device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq); 169ea6f23cdSMatt Jacob if (sim == NULL) { 170ea6f23cdSMatt Jacob xpt_bus_deregister(cam_sim_path(isp->isp_sim)); 171ea6f23cdSMatt Jacob xpt_free_path(isp->isp_path); 172ea6f23cdSMatt Jacob cam_simq_free(devq); 1735d571944SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 174ea6f23cdSMatt Jacob return; 175ea6f23cdSMatt Jacob } 176ea6f23cdSMatt Jacob if (xpt_bus_register(sim, secondary) != CAM_SUCCESS) { 177ea6f23cdSMatt Jacob xpt_bus_deregister(cam_sim_path(isp->isp_sim)); 178ea6f23cdSMatt Jacob xpt_free_path(isp->isp_path); 179ea6f23cdSMatt Jacob cam_sim_free(sim, TRUE); 1805d571944SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 18145c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 182ea6f23cdSMatt Jacob return; 183ea6f23cdSMatt Jacob } 184ea6f23cdSMatt Jacob 185ea6f23cdSMatt Jacob if (xpt_create_path(&path, NULL, cam_sim_path(sim), 186ea6f23cdSMatt Jacob CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 187ea6f23cdSMatt Jacob xpt_bus_deregister(cam_sim_path(isp->isp_sim)); 188ea6f23cdSMatt Jacob xpt_free_path(isp->isp_path); 189ea6f23cdSMatt Jacob xpt_bus_deregister(cam_sim_path(sim)); 190ea6f23cdSMatt Jacob cam_sim_free(sim, TRUE); 1915d571944SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 19245c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 193ea6f23cdSMatt Jacob return; 194ea6f23cdSMatt Jacob } 195ea6f23cdSMatt Jacob 196ea6f23cdSMatt Jacob xpt_setup_ccb(&csa.ccb_h, path, 5); 197ea6f23cdSMatt Jacob csa.ccb_h.func_code = XPT_SASYNC_CB; 198ea6f23cdSMatt Jacob csa.event_enable = AC_LOST_DEVICE; 199ea6f23cdSMatt Jacob csa.callback = isp_cam_async; 200ea6f23cdSMatt Jacob csa.callback_arg = sim; 201ea6f23cdSMatt Jacob xpt_action((union ccb *)&csa); 20245c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 203ea6f23cdSMatt Jacob isp->isp_sim2 = sim; 204ea6f23cdSMatt Jacob isp->isp_path2 = path; 205ea6f23cdSMatt Jacob } 2065d571944SMatt Jacob 2075d571944SMatt Jacob /* 2085d571944SMatt Jacob * Create device nodes 2095d571944SMatt Jacob */ 2105d571944SMatt Jacob (void) make_dev(&isp_cdevsw, device_get_unit(isp->isp_dev), UID_ROOT, 2115d571944SMatt Jacob GID_OPERATOR, 0600, "%s", device_get_nameunit(isp->isp_dev)); 2125d571944SMatt Jacob 213d6e5500fSMatt Jacob if (isp->isp_role != ISP_ROLE_NONE) { 214478f8a96SJustin T. Gibbs isp->isp_state = ISP_RUNSTATE; 215b85389e1SMatt Jacob ENABLE_INTS(isp); 216d6e5500fSMatt Jacob } 217d81ba9d5SMatt Jacob if (isplist == NULL) { 218d81ba9d5SMatt Jacob isplist = isp; 219d81ba9d5SMatt Jacob } else { 220d81ba9d5SMatt Jacob struct ispsoftc *tmp = isplist; 221d81ba9d5SMatt Jacob while (tmp->isp_osinfo.next) { 222d81ba9d5SMatt Jacob tmp = tmp->isp_osinfo.next; 223d81ba9d5SMatt Jacob } 224d81ba9d5SMatt Jacob tmp->isp_osinfo.next = isp; 225478f8a96SJustin T. Gibbs } 2265d571944SMatt Jacob 2275d571944SMatt Jacob } 2285d571944SMatt Jacob 2295d571944SMatt Jacob static int 2305d571944SMatt Jacob ispioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) 2315d571944SMatt Jacob { 2325d571944SMatt Jacob struct ispsoftc *isp; 2335d571944SMatt Jacob int retval = ENOTTY; 2345d571944SMatt Jacob 2355d571944SMatt Jacob isp = isplist; 2365d571944SMatt Jacob while (isp) { 2375d571944SMatt Jacob if (minor(dev) == device_get_unit(isp->isp_dev)) { 2385d571944SMatt Jacob break; 2395d571944SMatt Jacob } 2405d571944SMatt Jacob isp = isp->isp_osinfo.next; 2415d571944SMatt Jacob } 2425d571944SMatt Jacob if (isp == NULL) 2435d571944SMatt Jacob return (ENXIO); 2445d571944SMatt Jacob 2455d571944SMatt Jacob switch (cmd) { 2465d571944SMatt Jacob case ISP_SDBLEV: 2475d571944SMatt Jacob { 2485d571944SMatt Jacob int olddblev = isp->isp_dblev; 2495d571944SMatt Jacob isp->isp_dblev = *(int *)addr; 2505d571944SMatt Jacob *(int *)addr = olddblev; 2515d571944SMatt Jacob retval = 0; 2525d571944SMatt Jacob break; 2535d571944SMatt Jacob } 2545d571944SMatt Jacob case ISP_RESETHBA: 2555d571944SMatt Jacob ISP_LOCK(isp); 2565d571944SMatt Jacob isp_reinit(isp); 2575d571944SMatt Jacob ISP_UNLOCK(isp); 2585d571944SMatt Jacob retval = 0; 2595d571944SMatt Jacob break; 2605d571944SMatt Jacob case ISP_FC_RESCAN: 2615d571944SMatt Jacob if (IS_FC(isp)) { 2625d571944SMatt Jacob ISP_LOCK(isp); 2635d571944SMatt Jacob if (isp_fc_runstate(isp, 5 * 1000000)) { 2645d571944SMatt Jacob retval = EIO; 2655d571944SMatt Jacob } else { 2665d571944SMatt Jacob retval = 0; 2675d571944SMatt Jacob } 2685d571944SMatt Jacob ISP_UNLOCK(isp); 2695d571944SMatt Jacob } 2705d571944SMatt Jacob break; 2715d571944SMatt Jacob case ISP_FC_LIP: 2725d571944SMatt Jacob if (IS_FC(isp)) { 2735d571944SMatt Jacob ISP_LOCK(isp); 2745d571944SMatt Jacob if (isp_control(isp, ISPCTL_SEND_LIP, 0)) { 2755d571944SMatt Jacob retval = EIO; 2765d571944SMatt Jacob } else { 2775d571944SMatt Jacob retval = 0; 2785d571944SMatt Jacob } 2795d571944SMatt Jacob ISP_UNLOCK(isp); 2805d571944SMatt Jacob } 2815d571944SMatt Jacob break; 2825d571944SMatt Jacob case ISP_FC_GETDINFO: 2835d571944SMatt Jacob { 2845d571944SMatt Jacob struct isp_fc_device *ifc = (struct isp_fc_device *) addr; 2855d571944SMatt Jacob struct lportdb *lp; 2865d571944SMatt Jacob 2875d571944SMatt Jacob if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) { 2885d571944SMatt Jacob retval = EINVAL; 2895d571944SMatt Jacob break; 2905d571944SMatt Jacob } 2915d571944SMatt Jacob ISP_LOCK(isp); 2925d571944SMatt Jacob lp = &FCPARAM(isp)->portdb[ifc->loopid]; 2935d571944SMatt Jacob if (lp->valid) { 2945d571944SMatt Jacob ifc->loopid = lp->loopid; 2955d571944SMatt Jacob ifc->portid = lp->portid; 2965d571944SMatt Jacob ifc->node_wwn = lp->node_wwn; 2975d571944SMatt Jacob ifc->port_wwn = lp->port_wwn; 2985d571944SMatt Jacob retval = 0; 2995d571944SMatt Jacob } else { 3005d571944SMatt Jacob retval = ENODEV; 3015d571944SMatt Jacob } 3025d571944SMatt Jacob ISP_UNLOCK(isp); 3035d571944SMatt Jacob break; 3045d571944SMatt Jacob } 3055d571944SMatt Jacob default: 3065d571944SMatt Jacob break; 3075d571944SMatt Jacob } 3085d571944SMatt Jacob return (retval); 3090470d791SMatt Jacob } 310478f8a96SJustin T. Gibbs 311f6e75de2SMatt Jacob static void 312f6e75de2SMatt Jacob isp_intr_enable(void *arg) 313f6e75de2SMatt Jacob { 314f6e75de2SMatt Jacob struct ispsoftc *isp = arg; 315d6e5500fSMatt Jacob if (isp->isp_role != ISP_ROLE_NONE) { 316f6e75de2SMatt Jacob ENABLE_INTS(isp); 317f6e75de2SMatt Jacob isp->isp_osinfo.intsok = 1; 318d6e5500fSMatt Jacob } 319f6e75de2SMatt Jacob /* Release our hook so that the boot can continue. */ 320f6e75de2SMatt Jacob config_intrhook_disestablish(&isp->isp_osinfo.ehook); 321f6e75de2SMatt Jacob } 322d81ba9d5SMatt Jacob 323d81ba9d5SMatt Jacob /* 324d81ba9d5SMatt Jacob * Put the target mode functions here, because some are inlines 325d81ba9d5SMatt Jacob */ 326d81ba9d5SMatt Jacob 327d81ba9d5SMatt Jacob #ifdef ISP_TARGET_MODE 328d81ba9d5SMatt Jacob 329a1bc34c6SMatt Jacob static __inline int is_lun_enabled(struct ispsoftc *, int, lun_id_t); 330a1bc34c6SMatt Jacob static __inline int are_any_luns_enabled(struct ispsoftc *, int); 331a1bc34c6SMatt Jacob static __inline tstate_t *get_lun_statep(struct ispsoftc *, int, lun_id_t); 332d81ba9d5SMatt Jacob static __inline void rls_lun_statep(struct ispsoftc *, tstate_t *); 333d81ba9d5SMatt Jacob static __inline int isp_psema_sig_rqe(struct ispsoftc *); 334d81ba9d5SMatt Jacob static __inline int isp_cv_wait_timed_rqe(struct ispsoftc *, int); 335d81ba9d5SMatt Jacob static __inline void isp_cv_signal_rqe(struct ispsoftc *, int); 336d81ba9d5SMatt Jacob static __inline void isp_vsema_rqe(struct ispsoftc *); 337d81ba9d5SMatt Jacob static cam_status 338a1bc34c6SMatt Jacob create_lun_state(struct ispsoftc *, int, struct cam_path *, tstate_t **); 339d81ba9d5SMatt Jacob static void destroy_lun_state(struct ispsoftc *, tstate_t *); 340d81ba9d5SMatt Jacob static void isp_en_lun(struct ispsoftc *, union ccb *); 341d81ba9d5SMatt Jacob static cam_status isp_abort_tgt_ccb(struct ispsoftc *, union ccb *); 342f48ce188SMatt Jacob static timeout_t isp_refire_putback_atio; 343a1bc34c6SMatt Jacob static void isp_complete_ctio(union ccb *); 344a1bc34c6SMatt Jacob static void isp_target_putback_atio(union ccb *); 345a1bc34c6SMatt Jacob static cam_status isp_target_start_ctio(struct ispsoftc *, union ccb *); 346d81ba9d5SMatt Jacob static int isp_handle_platform_atio(struct ispsoftc *, at_entry_t *); 347d81ba9d5SMatt Jacob static int isp_handle_platform_atio2(struct ispsoftc *, at2_entry_t *); 348d81ba9d5SMatt Jacob static int isp_handle_platform_ctio(struct ispsoftc *, void *); 349d81ba9d5SMatt Jacob 350d81ba9d5SMatt Jacob static __inline int 351a1bc34c6SMatt Jacob is_lun_enabled(struct ispsoftc *isp, int bus, lun_id_t lun) 352d81ba9d5SMatt Jacob { 353d81ba9d5SMatt Jacob tstate_t *tptr; 354a1bc34c6SMatt Jacob tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)]; 355a1bc34c6SMatt Jacob if (tptr == NULL) { 356f6e75de2SMatt Jacob ISP_UNLOCK(isp); 357d81ba9d5SMatt Jacob return (0); 358d81ba9d5SMatt Jacob } 359d81ba9d5SMatt Jacob do { 360a1bc34c6SMatt Jacob if (tptr->lun == (lun_id_t) lun && tptr->bus == bus) { 361f6e75de2SMatt Jacob ISP_UNLOCK(isp); 362d81ba9d5SMatt Jacob return (1); 363d81ba9d5SMatt Jacob } 364d81ba9d5SMatt Jacob } while ((tptr = tptr->next) != NULL); 365d81ba9d5SMatt Jacob return (0); 366d81ba9d5SMatt Jacob } 367d81ba9d5SMatt Jacob 368d81ba9d5SMatt Jacob static __inline int 369a1bc34c6SMatt Jacob are_any_luns_enabled(struct ispsoftc *isp, int port) 370d81ba9d5SMatt Jacob { 371a1bc34c6SMatt Jacob int lo, hi; 372a1bc34c6SMatt Jacob if (IS_DUALBUS(isp)) { 373a1bc34c6SMatt Jacob lo = (port * (LUN_HASH_SIZE >> 1)); 374a1bc34c6SMatt Jacob hi = lo + (LUN_HASH_SIZE >> 1); 375a1bc34c6SMatt Jacob } else { 376a1bc34c6SMatt Jacob lo = 0; 377a1bc34c6SMatt Jacob hi = LUN_HASH_SIZE; 378a1bc34c6SMatt Jacob } 379a1bc34c6SMatt Jacob for (lo = 0; lo < hi; lo++) { 380a1bc34c6SMatt Jacob if (isp->isp_osinfo.lun_hash[lo]) { 381d81ba9d5SMatt Jacob return (1); 382d81ba9d5SMatt Jacob } 383d81ba9d5SMatt Jacob } 384d81ba9d5SMatt Jacob return (0); 385d81ba9d5SMatt Jacob } 386d81ba9d5SMatt Jacob 387d81ba9d5SMatt Jacob static __inline tstate_t * 388a1bc34c6SMatt Jacob get_lun_statep(struct ispsoftc *isp, int bus, lun_id_t lun) 389d81ba9d5SMatt Jacob { 390d81ba9d5SMatt Jacob tstate_t *tptr; 391d81ba9d5SMatt Jacob 392d81ba9d5SMatt Jacob if (lun == CAM_LUN_WILDCARD) { 393a1bc34c6SMatt Jacob tptr = &isp->isp_osinfo.tsdflt[bus]; 394d81ba9d5SMatt Jacob tptr->hold++; 395d81ba9d5SMatt Jacob return (tptr); 396d81ba9d5SMatt Jacob } else { 397a1bc34c6SMatt Jacob tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)]; 398d81ba9d5SMatt Jacob } 399d81ba9d5SMatt Jacob if (tptr == NULL) { 400d81ba9d5SMatt Jacob return (NULL); 401d81ba9d5SMatt Jacob } 402d81ba9d5SMatt Jacob 403d81ba9d5SMatt Jacob do { 404a1bc34c6SMatt Jacob if (tptr->lun == lun && tptr->bus == bus) { 405d81ba9d5SMatt Jacob tptr->hold++; 406d81ba9d5SMatt Jacob return (tptr); 407d81ba9d5SMatt Jacob } 408d81ba9d5SMatt Jacob } while ((tptr = tptr->next) != NULL); 409d81ba9d5SMatt Jacob return (tptr); 410d81ba9d5SMatt Jacob } 411d81ba9d5SMatt Jacob 412d81ba9d5SMatt Jacob static __inline void 413d81ba9d5SMatt Jacob rls_lun_statep(struct ispsoftc *isp, tstate_t *tptr) 414d81ba9d5SMatt Jacob { 415d81ba9d5SMatt Jacob if (tptr->hold) 416d81ba9d5SMatt Jacob tptr->hold--; 417d81ba9d5SMatt Jacob } 418d81ba9d5SMatt Jacob 419d81ba9d5SMatt Jacob static __inline int 420d81ba9d5SMatt Jacob isp_psema_sig_rqe(struct ispsoftc *isp) 421d81ba9d5SMatt Jacob { 422d81ba9d5SMatt Jacob while (isp->isp_osinfo.tmflags & TM_BUSY) { 423d81ba9d5SMatt Jacob isp->isp_osinfo.tmflags |= TM_WANTED; 424d81ba9d5SMatt Jacob if (tsleep(&isp->isp_osinfo.tmflags, PRIBIO|PCATCH, "i0", 0)) { 425d81ba9d5SMatt Jacob return (-1); 426d81ba9d5SMatt Jacob } 427d81ba9d5SMatt Jacob isp->isp_osinfo.tmflags |= TM_BUSY; 428d81ba9d5SMatt Jacob } 429d81ba9d5SMatt Jacob return (0); 430d81ba9d5SMatt Jacob } 431d81ba9d5SMatt Jacob 432d81ba9d5SMatt Jacob static __inline int 433d81ba9d5SMatt Jacob isp_cv_wait_timed_rqe(struct ispsoftc *isp, int timo) 434d81ba9d5SMatt Jacob { 435d81ba9d5SMatt Jacob if (tsleep(&isp->isp_osinfo.rstatus, PRIBIO, "qt1", timo)) { 436f6e75de2SMatt Jacob ISP_UNLOCK(isp); 437d81ba9d5SMatt Jacob return (-1); 438d81ba9d5SMatt Jacob } 439d81ba9d5SMatt Jacob return (0); 440d81ba9d5SMatt Jacob } 441d81ba9d5SMatt Jacob 442d81ba9d5SMatt Jacob static __inline void 443d81ba9d5SMatt Jacob isp_cv_signal_rqe(struct ispsoftc *isp, int status) 444d81ba9d5SMatt Jacob { 445d81ba9d5SMatt Jacob isp->isp_osinfo.rstatus = status; 446d81ba9d5SMatt Jacob wakeup(&isp->isp_osinfo.rstatus); 447d81ba9d5SMatt Jacob } 448d81ba9d5SMatt Jacob 449d81ba9d5SMatt Jacob static __inline void 450d81ba9d5SMatt Jacob isp_vsema_rqe(struct ispsoftc *isp) 451d81ba9d5SMatt Jacob { 452d81ba9d5SMatt Jacob if (isp->isp_osinfo.tmflags & TM_WANTED) { 453d81ba9d5SMatt Jacob isp->isp_osinfo.tmflags &= ~TM_WANTED; 454d81ba9d5SMatt Jacob wakeup(&isp->isp_osinfo.tmflags); 455d81ba9d5SMatt Jacob } 456d81ba9d5SMatt Jacob isp->isp_osinfo.tmflags &= ~TM_BUSY; 457d81ba9d5SMatt Jacob } 458d81ba9d5SMatt Jacob 459d81ba9d5SMatt Jacob static cam_status 460a1bc34c6SMatt Jacob create_lun_state(struct ispsoftc *isp, int bus, 461a1bc34c6SMatt Jacob struct cam_path *path, tstate_t **rslt) 462d81ba9d5SMatt Jacob { 463d81ba9d5SMatt Jacob cam_status status; 464d81ba9d5SMatt Jacob lun_id_t lun; 465a1bc34c6SMatt Jacob int hfx; 466d81ba9d5SMatt Jacob tstate_t *tptr, *new; 467d81ba9d5SMatt Jacob 468d81ba9d5SMatt Jacob lun = xpt_path_lun_id(path); 469d81ba9d5SMatt Jacob if (lun < 0) { 470d81ba9d5SMatt Jacob return (CAM_LUN_INVALID); 471d81ba9d5SMatt Jacob } 472a1bc34c6SMatt Jacob if (is_lun_enabled(isp, bus, lun)) { 473d81ba9d5SMatt Jacob return (CAM_LUN_ALRDY_ENA); 474d81ba9d5SMatt Jacob } 475ea8b5a9aSDavid Malone new = (tstate_t *) malloc(sizeof (tstate_t), M_DEVBUF, M_NOWAIT|M_ZERO); 476d81ba9d5SMatt Jacob if (new == NULL) { 477d81ba9d5SMatt Jacob return (CAM_RESRC_UNAVAIL); 478d81ba9d5SMatt Jacob } 479d81ba9d5SMatt Jacob 480d81ba9d5SMatt Jacob status = xpt_create_path(&new->owner, NULL, xpt_path_path_id(path), 481d81ba9d5SMatt Jacob xpt_path_target_id(path), xpt_path_lun_id(path)); 482d81ba9d5SMatt Jacob if (status != CAM_REQ_CMP) { 483d81ba9d5SMatt Jacob free(new, M_DEVBUF); 484d81ba9d5SMatt Jacob return (status); 485d81ba9d5SMatt Jacob } 486a1bc34c6SMatt Jacob new->bus = bus; 487d81ba9d5SMatt Jacob new->lun = lun; 488d81ba9d5SMatt Jacob SLIST_INIT(&new->atios); 489d81ba9d5SMatt Jacob SLIST_INIT(&new->inots); 490d81ba9d5SMatt Jacob new->hold = 1; 491d81ba9d5SMatt Jacob 492a1bc34c6SMatt Jacob hfx = LUN_HASH_FUNC(isp, new->bus, new->lun); 493a1bc34c6SMatt Jacob tptr = isp->isp_osinfo.lun_hash[hfx]; 494a1bc34c6SMatt Jacob if (tptr == NULL) { 495a1bc34c6SMatt Jacob isp->isp_osinfo.lun_hash[hfx] = new; 496d81ba9d5SMatt Jacob } else { 497d81ba9d5SMatt Jacob while (tptr->next) 498d81ba9d5SMatt Jacob tptr = tptr->next; 499d81ba9d5SMatt Jacob tptr->next = new; 500d81ba9d5SMatt Jacob } 501d81ba9d5SMatt Jacob *rslt = new; 502d81ba9d5SMatt Jacob return (CAM_REQ_CMP); 503d81ba9d5SMatt Jacob } 504d81ba9d5SMatt Jacob 505d81ba9d5SMatt Jacob static __inline void 506d81ba9d5SMatt Jacob destroy_lun_state(struct ispsoftc *isp, tstate_t *tptr) 507d81ba9d5SMatt Jacob { 508a1bc34c6SMatt Jacob int hfx; 509d81ba9d5SMatt Jacob tstate_t *lw, *pw; 510d81ba9d5SMatt Jacob 511a1bc34c6SMatt Jacob hfx = LUN_HASH_FUNC(isp, tptr->bus, tptr->lun); 512d81ba9d5SMatt Jacob if (tptr->hold) { 513d81ba9d5SMatt Jacob return; 514d81ba9d5SMatt Jacob } 515a1bc34c6SMatt Jacob pw = isp->isp_osinfo.lun_hash[hfx]; 516d81ba9d5SMatt Jacob if (pw == NULL) { 517d81ba9d5SMatt Jacob return; 518a1bc34c6SMatt Jacob } else if (pw->lun == tptr->lun && pw->bus == tptr->bus) { 519a1bc34c6SMatt Jacob isp->isp_osinfo.lun_hash[hfx] = pw->next; 520d81ba9d5SMatt Jacob } else { 521d81ba9d5SMatt Jacob lw = pw; 522d81ba9d5SMatt Jacob pw = lw->next; 523d81ba9d5SMatt Jacob while (pw) { 524a1bc34c6SMatt Jacob if (pw->lun == tptr->lun && pw->bus == tptr->bus) { 525d81ba9d5SMatt Jacob lw->next = pw->next; 526d81ba9d5SMatt Jacob break; 527d81ba9d5SMatt Jacob } 528d81ba9d5SMatt Jacob lw = pw; 529d81ba9d5SMatt Jacob pw = pw->next; 530d81ba9d5SMatt Jacob } 531d81ba9d5SMatt Jacob if (pw == NULL) { 532f6e75de2SMatt Jacob ISP_UNLOCK(isp); 533d81ba9d5SMatt Jacob return; 534d81ba9d5SMatt Jacob } 535d81ba9d5SMatt Jacob } 536d81ba9d5SMatt Jacob free(tptr, M_DEVBUF); 537d81ba9d5SMatt Jacob } 538d81ba9d5SMatt Jacob 5395d571944SMatt Jacob /* 5405d571944SMatt Jacob * we enter with our locks held. 5415d571944SMatt Jacob */ 542d81ba9d5SMatt Jacob static void 543d81ba9d5SMatt Jacob isp_en_lun(struct ispsoftc *isp, union ccb *ccb) 544d81ba9d5SMatt Jacob { 545a1bc34c6SMatt Jacob const char lfmt[] = "Lun now %sabled for target mode on channel %d"; 546d81ba9d5SMatt Jacob struct ccb_en_lun *cel = &ccb->cel; 547d81ba9d5SMatt Jacob tstate_t *tptr; 548d81ba9d5SMatt Jacob u_int16_t rstat; 5495d571944SMatt Jacob int bus, cmd, frozen = 0; 550d81ba9d5SMatt Jacob lun_id_t lun; 551d81ba9d5SMatt Jacob target_id_t tgt; 552d81ba9d5SMatt Jacob 553d81ba9d5SMatt Jacob 554a1bc34c6SMatt Jacob bus = XS_CHANNEL(ccb) & 0x1; 555d81ba9d5SMatt Jacob tgt = ccb->ccb_h.target_id; 556d81ba9d5SMatt Jacob lun = ccb->ccb_h.target_lun; 557d81ba9d5SMatt Jacob 558d81ba9d5SMatt Jacob /* 559d81ba9d5SMatt Jacob * Do some sanity checking first. 560d81ba9d5SMatt Jacob */ 561d81ba9d5SMatt Jacob 562d6e5500fSMatt Jacob if ((lun != CAM_LUN_WILDCARD) && 563d6e5500fSMatt Jacob (lun < 0 || lun >= (lun_id_t) isp->isp_maxluns)) { 564d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_LUN_INVALID; 565d81ba9d5SMatt Jacob return; 566d81ba9d5SMatt Jacob } 5672ad50ca5SMatt Jacob if (IS_SCSI(isp)) { 568a1bc34c6SMatt Jacob sdparam *sdp = isp->isp_param; 569a1bc34c6SMatt Jacob sdp += bus; 570d81ba9d5SMatt Jacob if (tgt != CAM_TARGET_WILDCARD && 571a1bc34c6SMatt Jacob tgt != sdp->isp_initiator_id) { 572d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_TID_INVALID; 573d81ba9d5SMatt Jacob return; 574d81ba9d5SMatt Jacob } 575d81ba9d5SMatt Jacob } else { 576d81ba9d5SMatt Jacob if (tgt != CAM_TARGET_WILDCARD && 577d6e5500fSMatt Jacob tgt != FCPARAM(isp)->isp_iid) { 578d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_TID_INVALID; 579d81ba9d5SMatt Jacob return; 580d81ba9d5SMatt Jacob } 581d81ba9d5SMatt Jacob } 582d81ba9d5SMatt Jacob 583d6e5500fSMatt Jacob if (tgt == CAM_TARGET_WILDCARD) { 584d6e5500fSMatt Jacob if (lun != CAM_LUN_WILDCARD) { 585d6e5500fSMatt Jacob ccb->ccb_h.status = CAM_LUN_INVALID; 586d6e5500fSMatt Jacob return; 587d6e5500fSMatt Jacob } 588d6e5500fSMatt Jacob } 589d6e5500fSMatt Jacob 590b6b6ad2fSMatt Jacob /* 591b6b6ad2fSMatt Jacob * If Fibre Channel, stop and drain all activity to this bus. 592b6b6ad2fSMatt Jacob */ 593d6e5500fSMatt Jacob #if 0 594b6b6ad2fSMatt Jacob if (IS_FC(isp)) { 595b6b6ad2fSMatt Jacob ISP_LOCK(isp); 596b6b6ad2fSMatt Jacob frozen = 1; 597b6b6ad2fSMatt Jacob xpt_freeze_simq(isp->isp_sim, 1); 598b6b6ad2fSMatt Jacob isp->isp_osinfo.drain = 1; 599b6b6ad2fSMatt Jacob while (isp->isp_osinfo.drain) { 6005d571944SMatt Jacob (void) msleep(&isp->isp_osinfo.drain, &isp->isp_lock, 6015d571944SMatt Jacob PRIBIO, "ispdrain", 10 * hz); 602b6b6ad2fSMatt Jacob } 603b6b6ad2fSMatt Jacob ISP_UNLOCK(isp); 604b6b6ad2fSMatt Jacob } 605d6e5500fSMatt Jacob #endif 606b6b6ad2fSMatt Jacob 607b6b6ad2fSMatt Jacob /* 608b6b6ad2fSMatt Jacob * Check to see if we're enabling on fibre channel and 609b6b6ad2fSMatt Jacob * don't yet have a notion of who the heck we are (no 610b6b6ad2fSMatt Jacob * loop yet). 611b6b6ad2fSMatt Jacob */ 612b6b6ad2fSMatt Jacob if (IS_FC(isp) && cel->enable && 613b6b6ad2fSMatt Jacob (isp->isp_osinfo.tmflags & TM_TMODE_ENABLED) == 0) { 614b6b6ad2fSMatt Jacob fcparam *fcp = isp->isp_param; 615d6e5500fSMatt Jacob int rv; 616b6b6ad2fSMatt Jacob 617d6e5500fSMatt Jacob rv = isp_fc_runstate(isp, 2 * 1000000); 618d6e5500fSMatt Jacob if (fcp->isp_fwstate != FW_READY || 619d6e5500fSMatt Jacob fcp->isp_loopstate != LOOP_READY) { 620b6b6ad2fSMatt Jacob xpt_print_path(ccb->ccb_h.path); 6213c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 6223c75bb14SMatt Jacob "could not get a good port database read"); 623b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_REQ_CMP_ERR; 6245d571944SMatt Jacob if (frozen) { 6255d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 626b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6275d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6285d571944SMatt Jacob } 629b6b6ad2fSMatt Jacob return; 630b6b6ad2fSMatt Jacob } 631b6b6ad2fSMatt Jacob } 632b6b6ad2fSMatt Jacob 633b6b6ad2fSMatt Jacob 634b6b6ad2fSMatt Jacob /* 635b6b6ad2fSMatt Jacob * Next check to see whether this is a target/lun wildcard action. 636b6b6ad2fSMatt Jacob * 637b6b6ad2fSMatt Jacob * If so, we enable/disable target mode but don't do any lun enabling. 638b6b6ad2fSMatt Jacob */ 639b6b6ad2fSMatt Jacob if (lun == CAM_LUN_WILDCARD && tgt == CAM_TARGET_WILDCARD) { 640a1bc34c6SMatt Jacob int av = bus << 31; 641a1bc34c6SMatt Jacob tptr = &isp->isp_osinfo.tsdflt[bus]; 642b6b6ad2fSMatt Jacob if (cel->enable) { 643a1bc34c6SMatt Jacob if (isp->isp_osinfo.tmflags & (1 << bus)) { 644b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; 6455d571944SMatt Jacob if (frozen) { 6465d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 647b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6485d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6495d571944SMatt Jacob } 650b6b6ad2fSMatt Jacob return; 651b6b6ad2fSMatt Jacob } 652b6b6ad2fSMatt Jacob ccb->ccb_h.status = 653b6b6ad2fSMatt Jacob xpt_create_path(&tptr->owner, NULL, 654b6b6ad2fSMatt Jacob xpt_path_path_id(ccb->ccb_h.path), 655b6b6ad2fSMatt Jacob xpt_path_target_id(ccb->ccb_h.path), 656b6b6ad2fSMatt Jacob xpt_path_lun_id(ccb->ccb_h.path)); 657b6b6ad2fSMatt Jacob if (ccb->ccb_h.status != CAM_REQ_CMP) { 6585d571944SMatt Jacob if (frozen) { 6595d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 660b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6615d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6625d571944SMatt Jacob } 663b6b6ad2fSMatt Jacob return; 664b6b6ad2fSMatt Jacob } 665b6b6ad2fSMatt Jacob SLIST_INIT(&tptr->atios); 666b6b6ad2fSMatt Jacob SLIST_INIT(&tptr->inots); 667a1bc34c6SMatt Jacob av |= ENABLE_TARGET_FLAG; 668b6b6ad2fSMatt Jacob av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 669b6b6ad2fSMatt Jacob if (av) { 670b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 671b6b6ad2fSMatt Jacob xpt_free_path(tptr->owner); 6725d571944SMatt Jacob if (frozen) { 6735d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 674b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6755d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6765d571944SMatt Jacob } 677b6b6ad2fSMatt Jacob return; 678b6b6ad2fSMatt Jacob } 679a1bc34c6SMatt Jacob isp->isp_osinfo.tmflags |= (1 << bus); 680b6b6ad2fSMatt Jacob } else { 681a1bc34c6SMatt Jacob if ((isp->isp_osinfo.tmflags & (1 << bus)) == 0) { 682b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_LUN_INVALID; 6835d571944SMatt Jacob if (frozen) { 6845d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 685b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6865d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6875d571944SMatt Jacob } 688b6b6ad2fSMatt Jacob return; 689b6b6ad2fSMatt Jacob } 690a1bc34c6SMatt Jacob if (are_any_luns_enabled(isp, bus)) { 691b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_SCSI_BUSY; 6925d571944SMatt Jacob if (frozen) { 6935d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 694b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 6955d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 6965d571944SMatt Jacob } 697b6b6ad2fSMatt Jacob return; 698b6b6ad2fSMatt Jacob } 699b6b6ad2fSMatt Jacob av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 700b6b6ad2fSMatt Jacob if (av) { 701b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 7025d571944SMatt Jacob if (frozen) { 7035d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 704b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 7055d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 7065d571944SMatt Jacob } 707b6b6ad2fSMatt Jacob return; 708b6b6ad2fSMatt Jacob } 709a1bc34c6SMatt Jacob isp->isp_osinfo.tmflags &= ~(1 << bus); 710b6b6ad2fSMatt Jacob ccb->ccb_h.status = CAM_REQ_CMP; 711b6b6ad2fSMatt Jacob } 712b6b6ad2fSMatt Jacob xpt_print_path(ccb->ccb_h.path); 713a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGINFO, "Target Mode %sabled on channel %d", 714a1bc34c6SMatt Jacob (cel->enable) ? "en" : "dis", bus); 7155d571944SMatt Jacob if (frozen) { 7165d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 717b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 7185d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 7195d571944SMatt Jacob } 720b6b6ad2fSMatt Jacob return; 721b6b6ad2fSMatt Jacob } 722b6b6ad2fSMatt Jacob 723b6b6ad2fSMatt Jacob /* 724b6b6ad2fSMatt Jacob * We can move along now... 725b6b6ad2fSMatt Jacob */ 726b6b6ad2fSMatt Jacob 7275d571944SMatt Jacob if (frozen) { 7285d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 729b6b6ad2fSMatt Jacob xpt_release_simq(isp->isp_sim, 1); 7305d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 7315d571944SMatt Jacob } 732b6b6ad2fSMatt Jacob 733d81ba9d5SMatt Jacob 734d81ba9d5SMatt Jacob if (cel->enable) { 735d81ba9d5SMatt Jacob ccb->ccb_h.status = 736a1bc34c6SMatt Jacob create_lun_state(isp, bus, ccb->ccb_h.path, &tptr); 737d81ba9d5SMatt Jacob if (ccb->ccb_h.status != CAM_REQ_CMP) { 738d81ba9d5SMatt Jacob return; 739d81ba9d5SMatt Jacob } 740d81ba9d5SMatt Jacob } else { 741a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, bus, lun); 742d81ba9d5SMatt Jacob if (tptr == NULL) { 743d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_LUN_INVALID; 744d81ba9d5SMatt Jacob return; 745d81ba9d5SMatt Jacob } 746d81ba9d5SMatt Jacob } 747d81ba9d5SMatt Jacob 748d81ba9d5SMatt Jacob if (isp_psema_sig_rqe(isp)) { 749d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 750d81ba9d5SMatt Jacob if (cel->enable) 751d81ba9d5SMatt Jacob destroy_lun_state(isp, tptr); 752d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_REQ_CMP_ERR; 753d81ba9d5SMatt Jacob return; 754d81ba9d5SMatt Jacob } 755d81ba9d5SMatt Jacob 756d81ba9d5SMatt Jacob if (cel->enable) { 757d81ba9d5SMatt Jacob u_int32_t seq = isp->isp_osinfo.rollinfo++; 7585d571944SMatt Jacob int c, n, ulun = lun; 7595d571944SMatt Jacob 7605d571944SMatt Jacob cmd = RQSTYPE_ENABLE_LUN; 7615d571944SMatt Jacob c = DFLT_CMND_CNT; 7625d571944SMatt Jacob n = DFLT_INOT_CNT; 7635d571944SMatt Jacob if (IS_FC(isp) && lun != 0) { 7645d571944SMatt Jacob cmd = RQSTYPE_MODIFY_LUN; 7655d571944SMatt Jacob n = 0; 7665d571944SMatt Jacob /* 7675d571944SMatt Jacob * For SCC firmware, we only deal with setting 7685d571944SMatt Jacob * (enabling or modifying) lun 0. 7695d571944SMatt Jacob */ 7705d571944SMatt Jacob ulun = 0; 7715d571944SMatt Jacob } 772d81ba9d5SMatt Jacob rstat = LUN_ERR; 7735d571944SMatt Jacob if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq)) { 774d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 7753c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, "isp_lun_cmd failed"); 776d81ba9d5SMatt Jacob goto out; 777d81ba9d5SMatt Jacob } 778d81ba9d5SMatt Jacob if (isp_cv_wait_timed_rqe(isp, 30 * hz)) { 779d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 7803c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, 7815d571944SMatt Jacob "wait for ENABLE/MODIFY LUN timed out"); 782d81ba9d5SMatt Jacob goto out; 783d81ba9d5SMatt Jacob } 784d81ba9d5SMatt Jacob rstat = isp->isp_osinfo.rstatus; 785d81ba9d5SMatt Jacob if (rstat != LUN_OK) { 786d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 7873c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, 7885d571944SMatt Jacob "ENABLE/MODIFY LUN returned 0x%x", rstat); 789d81ba9d5SMatt Jacob goto out; 790d81ba9d5SMatt Jacob } 791d81ba9d5SMatt Jacob } else { 7925d571944SMatt Jacob int c, n, ulun = lun; 793d81ba9d5SMatt Jacob u_int32_t seq; 794d81ba9d5SMatt Jacob 795d81ba9d5SMatt Jacob rstat = LUN_ERR; 7965d571944SMatt Jacob seq = isp->isp_osinfo.rollinfo++; 7975d571944SMatt Jacob cmd = -RQSTYPE_MODIFY_LUN; 798d81ba9d5SMatt Jacob 7995d571944SMatt Jacob c = DFLT_CMND_CNT; 8005d571944SMatt Jacob n = DFLT_INOT_CNT; 8015d571944SMatt Jacob if (IS_FC(isp) && lun != 0) { 8025d571944SMatt Jacob n = 0; 8035d571944SMatt Jacob /* 8045d571944SMatt Jacob * For SCC firmware, we only deal with setting 8055d571944SMatt Jacob * (enabling or modifying) lun 0. 8065d571944SMatt Jacob */ 8075d571944SMatt Jacob ulun = 0; 8085d571944SMatt Jacob } 8095d571944SMatt Jacob if (isp_lun_cmd(isp, cmd, bus, tgt, ulun, c, n, seq)) { 810d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8113c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, "isp_lun_cmd failed"); 812d81ba9d5SMatt Jacob goto out; 813d81ba9d5SMatt Jacob } 814d81ba9d5SMatt Jacob if (isp_cv_wait_timed_rqe(isp, 30 * hz)) { 815d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8163c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, 8173c75bb14SMatt Jacob "wait for MODIFY LUN timed out"); 818d81ba9d5SMatt Jacob goto out; 819d81ba9d5SMatt Jacob } 820d81ba9d5SMatt Jacob rstat = isp->isp_osinfo.rstatus; 821d81ba9d5SMatt Jacob if (rstat != LUN_OK) { 822d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8233c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, 8243c75bb14SMatt Jacob "MODIFY LUN returned 0x%x", rstat); 825d81ba9d5SMatt Jacob goto out; 826d81ba9d5SMatt Jacob } 8275d571944SMatt Jacob if (IS_FC(isp) && lun) { 8285d571944SMatt Jacob goto out; 8295d571944SMatt Jacob } 8305d571944SMatt Jacob 831d81ba9d5SMatt Jacob seq = isp->isp_osinfo.rollinfo++; 832d81ba9d5SMatt Jacob 8335d571944SMatt Jacob rstat = LUN_ERR; 8345d571944SMatt Jacob cmd = -RQSTYPE_ENABLE_LUN; 8355d571944SMatt Jacob if (isp_lun_cmd(isp, cmd, bus, tgt, lun, 0, 0, seq)) { 836d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8373c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, "isp_lun_cmd failed"); 838d81ba9d5SMatt Jacob goto out; 839d81ba9d5SMatt Jacob } 840d81ba9d5SMatt Jacob if (isp_cv_wait_timed_rqe(isp, 30 * hz)) { 841d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8423c75bb14SMatt Jacob isp_prt(isp, ISP_LOGERR, 8435d571944SMatt Jacob "wait for DISABLE LUN timed out"); 844d81ba9d5SMatt Jacob goto out; 845d81ba9d5SMatt Jacob } 846d81ba9d5SMatt Jacob rstat = isp->isp_osinfo.rstatus; 847d81ba9d5SMatt Jacob if (rstat != LUN_OK) { 848d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8493c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 8505d571944SMatt Jacob "DISABLE LUN returned 0x%x", rstat); 851d81ba9d5SMatt Jacob goto out; 852d81ba9d5SMatt Jacob } 853d81ba9d5SMatt Jacob } 854d81ba9d5SMatt Jacob out: 855d81ba9d5SMatt Jacob isp_vsema_rqe(isp); 856d81ba9d5SMatt Jacob 857d81ba9d5SMatt Jacob if (rstat != LUN_OK) { 858d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 8593c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 8603c75bb14SMatt Jacob "lun %sable failed", (cel->enable) ? "en" : "dis"); 861d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_REQ_CMP_ERR; 862d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 863d81ba9d5SMatt Jacob if (cel->enable) 864d81ba9d5SMatt Jacob destroy_lun_state(isp, tptr); 865d81ba9d5SMatt Jacob } else { 866d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 867a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGINFO, lfmt, 868a1bc34c6SMatt Jacob (cel->enable) ? "en" : "dis", bus); 869d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 870d81ba9d5SMatt Jacob if (cel->enable == 0) { 871d81ba9d5SMatt Jacob destroy_lun_state(isp, tptr); 872d81ba9d5SMatt Jacob } 873d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_REQ_CMP; 874d81ba9d5SMatt Jacob } 875d81ba9d5SMatt Jacob } 876d81ba9d5SMatt Jacob 877d81ba9d5SMatt Jacob static cam_status 878d81ba9d5SMatt Jacob isp_abort_tgt_ccb(struct ispsoftc *isp, union ccb *ccb) 879d81ba9d5SMatt Jacob { 880d81ba9d5SMatt Jacob tstate_t *tptr; 881d81ba9d5SMatt Jacob struct ccb_hdr_slist *lp; 882d81ba9d5SMatt Jacob struct ccb_hdr *curelm; 883d81ba9d5SMatt Jacob int found; 884d81ba9d5SMatt Jacob union ccb *accb = ccb->cab.abort_ccb; 885d81ba9d5SMatt Jacob 886d81ba9d5SMatt Jacob if (accb->ccb_h.target_id != CAM_TARGET_WILDCARD) { 887d81ba9d5SMatt Jacob if (IS_FC(isp) && (accb->ccb_h.target_id != 888d81ba9d5SMatt Jacob ((fcparam *) isp->isp_param)->isp_loopid)) { 889d81ba9d5SMatt Jacob return (CAM_PATH_INVALID); 890d81ba9d5SMatt Jacob } else if (IS_SCSI(isp) && (accb->ccb_h.target_id != 891d81ba9d5SMatt Jacob ((sdparam *) isp->isp_param)->isp_initiator_id)) { 892d81ba9d5SMatt Jacob return (CAM_PATH_INVALID); 893d81ba9d5SMatt Jacob } 894d81ba9d5SMatt Jacob } 895a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, XS_CHANNEL(ccb), accb->ccb_h.target_lun); 896d81ba9d5SMatt Jacob if (tptr == NULL) { 897d81ba9d5SMatt Jacob return (CAM_PATH_INVALID); 898d81ba9d5SMatt Jacob } 899d81ba9d5SMatt Jacob if (accb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) { 900d81ba9d5SMatt Jacob lp = &tptr->atios; 901d81ba9d5SMatt Jacob } else if (accb->ccb_h.func_code == XPT_IMMED_NOTIFY) { 902d81ba9d5SMatt Jacob lp = &tptr->inots; 903d81ba9d5SMatt Jacob } else { 904d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 905d81ba9d5SMatt Jacob return (CAM_UA_ABORT); 906d81ba9d5SMatt Jacob } 907d81ba9d5SMatt Jacob curelm = SLIST_FIRST(lp); 908d81ba9d5SMatt Jacob found = 0; 909d81ba9d5SMatt Jacob if (curelm == &accb->ccb_h) { 910d81ba9d5SMatt Jacob found = 1; 911d81ba9d5SMatt Jacob SLIST_REMOVE_HEAD(lp, sim_links.sle); 912d81ba9d5SMatt Jacob } else { 913d81ba9d5SMatt Jacob while(curelm != NULL) { 914d81ba9d5SMatt Jacob struct ccb_hdr *nextelm; 915d81ba9d5SMatt Jacob 916d81ba9d5SMatt Jacob nextelm = SLIST_NEXT(curelm, sim_links.sle); 917d81ba9d5SMatt Jacob if (nextelm == &accb->ccb_h) { 918d81ba9d5SMatt Jacob found = 1; 919d81ba9d5SMatt Jacob SLIST_NEXT(curelm, sim_links.sle) = 920d81ba9d5SMatt Jacob SLIST_NEXT(nextelm, sim_links.sle); 921d81ba9d5SMatt Jacob break; 922d81ba9d5SMatt Jacob } 923d81ba9d5SMatt Jacob curelm = nextelm; 924d81ba9d5SMatt Jacob } 925d81ba9d5SMatt Jacob } 926d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 927d81ba9d5SMatt Jacob if (found) { 928d81ba9d5SMatt Jacob accb->ccb_h.status = CAM_REQ_ABORTED; 929d81ba9d5SMatt Jacob return (CAM_REQ_CMP); 930d81ba9d5SMatt Jacob } 931d81ba9d5SMatt Jacob return(CAM_PATH_INVALID); 932d81ba9d5SMatt Jacob } 933d81ba9d5SMatt Jacob 934d81ba9d5SMatt Jacob static cam_status 935d81ba9d5SMatt Jacob isp_target_start_ctio(struct ispsoftc *isp, union ccb *ccb) 936d81ba9d5SMatt Jacob { 937d81ba9d5SMatt Jacob void *qe; 93800a8e174SMatt Jacob struct ccb_scsiio *cso = &ccb->csio; 9395f5aafe1SMatt Jacob u_int16_t *hp, save_handle; 940d81ba9d5SMatt Jacob u_int16_t iptr, optr; 941d81ba9d5SMatt Jacob 942f48ce188SMatt Jacob 943d81ba9d5SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, &qe)) { 94492a1e549SMatt Jacob xpt_print_path(ccb->ccb_h.path); 94592a1e549SMatt Jacob printf("Request Queue Overflow in isp_target_start_ctio\n"); 946d81ba9d5SMatt Jacob return (CAM_RESRC_UNAVAIL); 947d81ba9d5SMatt Jacob } 94892a1e549SMatt Jacob bzero(qe, QENTRY_LEN); 949d81ba9d5SMatt Jacob 950d81ba9d5SMatt Jacob /* 951d81ba9d5SMatt Jacob * We're either moving data or completing a command here. 952d81ba9d5SMatt Jacob */ 953d81ba9d5SMatt Jacob 954d81ba9d5SMatt Jacob if (IS_FC(isp)) { 955f48ce188SMatt Jacob struct ccb_accept_tio *atiop; 956d81ba9d5SMatt Jacob ct2_entry_t *cto = qe; 95700a8e174SMatt Jacob 958d81ba9d5SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 959d81ba9d5SMatt Jacob cto->ct_header.rqs_entry_count = 1; 96000a8e174SMatt Jacob cto->ct_iid = cso->init_id; 9612ad50ca5SMatt Jacob if (isp->isp_maxluns <= 16) { 962d81ba9d5SMatt Jacob cto->ct_lun = ccb->ccb_h.target_lun; 9632ad50ca5SMatt Jacob } 964f48ce188SMatt Jacob /* 965f48ce188SMatt Jacob * Start with a residual based on what the original datalength 966f48ce188SMatt Jacob * was supposed to be. Basically, we ignore what CAM has set 967f48ce188SMatt Jacob * for residuals. The data transfer routines will knock off 968f48ce188SMatt Jacob * the residual for each byte actually moved- and also will 969f48ce188SMatt Jacob * be responsible for setting the underrun flag. 970f48ce188SMatt Jacob */ 971f48ce188SMatt Jacob /* HACK! HACK! */ 972f48ce188SMatt Jacob if ((atiop = ccb->ccb_h.periph_priv.entries[1].ptr) != NULL) { 973f48ce188SMatt Jacob cto->ct_resid = atiop->ccb_h.spriv_field0; 974f48ce188SMatt Jacob } 975f48ce188SMatt Jacob 97600a8e174SMatt Jacob cto->ct_rxid = cso->tag_id; 97700a8e174SMatt Jacob if (cso->dxfer_len == 0) { 97800a8e174SMatt Jacob cto->ct_flags |= CT2_FLAG_MODE1 | CT2_NO_DATA; 979f48ce188SMatt Jacob if (ccb->ccb_h.flags & CAM_SEND_STATUS) { 98000a8e174SMatt Jacob cto->ct_flags |= CT2_SENDSTATUS; 981f48ce188SMatt Jacob cto->rsp.m1.ct_scsi_status = cso->scsi_status; 982f48ce188SMatt Jacob } 98300a8e174SMatt Jacob if ((ccb->ccb_h.flags & CAM_SEND_SENSE) != 0) { 98400a8e174SMatt Jacob int m = min(cso->sense_len, MAXRESPLEN); 98500a8e174SMatt Jacob bcopy(&cso->sense_data, cto->rsp.m1.ct_resp, m); 98600a8e174SMatt Jacob cto->rsp.m1.ct_senselen = m; 98700a8e174SMatt Jacob cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID; 98800a8e174SMatt Jacob } 98900a8e174SMatt Jacob } else { 99000a8e174SMatt Jacob cto->ct_flags |= CT2_FLAG_MODE0; 99100a8e174SMatt Jacob if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 99200a8e174SMatt Jacob cto->ct_flags |= CT2_DATA_IN; 99300a8e174SMatt Jacob } else { 99400a8e174SMatt Jacob cto->ct_flags |= CT2_DATA_OUT; 995d81ba9d5SMatt Jacob } 996d81ba9d5SMatt Jacob if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) { 997d81ba9d5SMatt Jacob cto->ct_flags |= CT2_SENDSTATUS; 99800a8e174SMatt Jacob cto->rsp.m0.ct_scsi_status = cso->scsi_status; 999d81ba9d5SMatt Jacob } 1000f48ce188SMatt Jacob /* 1001f48ce188SMatt Jacob * If we're sending data and status back together, 1002f48ce188SMatt Jacob * we can't also send back sense data as well. 1003f48ce188SMatt Jacob */ 100400a8e174SMatt Jacob ccb->ccb_h.flags &= ~CAM_SEND_SENSE; 100500a8e174SMatt Jacob } 1006290dc24bSMatt Jacob if (cto->ct_flags & CT2_SENDSTATUS) { 1007a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 10085f5aafe1SMatt Jacob "CTIO2[%x] SCSI STATUS 0x%x datalength %u", 1009b09b0095SMatt Jacob cto->ct_rxid, cso->scsi_status, cto->ct_resid); 1010d81ba9d5SMatt Jacob } 1011a1bc34c6SMatt Jacob if (cto->ct_flags & CT2_SENDSTATUS) 1012a1bc34c6SMatt Jacob cto->ct_flags |= CT2_CCINCR; 1013a1bc34c6SMatt Jacob cto->ct_timeout = 10; 10145f5aafe1SMatt Jacob hp = &cto->ct_syshandle; 1015d81ba9d5SMatt Jacob } else { 1016d81ba9d5SMatt Jacob ct_entry_t *cto = qe; 101700a8e174SMatt Jacob 1018d81ba9d5SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO; 1019d81ba9d5SMatt Jacob cto->ct_header.rqs_entry_count = 1; 102000a8e174SMatt Jacob cto->ct_iid = cso->init_id; 1021a1bc34c6SMatt Jacob cto->ct_iid |= XS_CHANNEL(ccb) << 7; 1022d81ba9d5SMatt Jacob cto->ct_tgt = ccb->ccb_h.target_id; 1023d81ba9d5SMatt Jacob cto->ct_lun = ccb->ccb_h.target_lun; 1024a1bc34c6SMatt Jacob cto->ct_fwhandle = AT_GET_HANDLE(cso->tag_id); 1025a1bc34c6SMatt Jacob if (AT_HAS_TAG(cso->tag_id)) { 1026a1bc34c6SMatt Jacob cto->ct_tag_val = (u_int8_t) AT_GET_TAG(cso->tag_id); 1027f48ce188SMatt Jacob cto->ct_flags |= CT_TQAE; 1028f48ce188SMatt Jacob } 1029f48ce188SMatt Jacob if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) { 1030f48ce188SMatt Jacob cto->ct_flags |= CT_NODISC; 1031f48ce188SMatt Jacob } 1032f48ce188SMatt Jacob if (cso->dxfer_len == 0) { 1033d81ba9d5SMatt Jacob cto->ct_flags |= CT_NO_DATA; 103400a8e174SMatt Jacob } else if ((cso->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 103500a8e174SMatt Jacob cto->ct_flags |= CT_DATA_IN; 103600a8e174SMatt Jacob } else { 103700a8e174SMatt Jacob cto->ct_flags |= CT_DATA_OUT; 1038d81ba9d5SMatt Jacob } 1039f48ce188SMatt Jacob if (ccb->ccb_h.flags & CAM_SEND_STATUS) { 1040d81ba9d5SMatt Jacob cto->ct_flags |= CT_SENDSTATUS; 104100a8e174SMatt Jacob cto->ct_scsi_status = cso->scsi_status; 104200a8e174SMatt Jacob cto->ct_resid = cso->resid; 1043d81ba9d5SMatt Jacob } 1044290dc24bSMatt Jacob if (cto->ct_flags & CT_SENDSTATUS) { 1045a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 1046a1bc34c6SMatt Jacob "CTIO[%x] SCSI STATUS 0x%x resid %d tag_id %x", 1047a1bc34c6SMatt Jacob cto->ct_fwhandle, cso->scsi_status, cso->resid, 1048a1bc34c6SMatt Jacob cso->tag_id); 104992a1e549SMatt Jacob } 1050a1bc34c6SMatt Jacob cto->ct_timeout = 10; 10515f5aafe1SMatt Jacob hp = &cto->ct_syshandle; 105200a8e174SMatt Jacob ccb->ccb_h.flags &= ~CAM_SEND_SENSE; 1053a1bc34c6SMatt Jacob if (cto->ct_flags & CT_SENDSTATUS) 1054a1bc34c6SMatt Jacob cto->ct_flags |= CT_CCINCR; 1055d81ba9d5SMatt Jacob } 1056d81ba9d5SMatt Jacob 1057b09b0095SMatt Jacob if (isp_save_xs(isp, (XS_T *)ccb, hp)) { 105892a1e549SMatt Jacob xpt_print_path(ccb->ccb_h.path); 105992a1e549SMatt Jacob printf("No XFLIST pointers for isp_target_start_ctio\n"); 1060d81ba9d5SMatt Jacob return (CAM_RESRC_UNAVAIL); 1061d81ba9d5SMatt Jacob } 1062d81ba9d5SMatt Jacob 1063d81ba9d5SMatt Jacob 1064d81ba9d5SMatt Jacob /* 1065d81ba9d5SMatt Jacob * Call the dma setup routines for this entry (and any subsequent 1066d81ba9d5SMatt Jacob * CTIOs) if there's data to move, and then tell the f/w it's got 1067b09b0095SMatt Jacob * new things to play with. As with isp_start's usage of DMA setup, 1068d81ba9d5SMatt Jacob * any swizzling is done in the machine dependent layer. Because 1069d81ba9d5SMatt Jacob * of this, we put the request onto the queue area first in native 1070d81ba9d5SMatt Jacob * format. 1071d81ba9d5SMatt Jacob */ 1072d81ba9d5SMatt Jacob 1073d81ba9d5SMatt Jacob save_handle = *hp; 1074a1bc34c6SMatt Jacob 107500a8e174SMatt Jacob switch (ISP_DMASETUP(isp, cso, qe, &iptr, optr)) { 1076d81ba9d5SMatt Jacob case CMD_QUEUED: 1077d81ba9d5SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 1078d81ba9d5SMatt Jacob return (CAM_REQ_INPROG); 1079d81ba9d5SMatt Jacob 1080d81ba9d5SMatt Jacob case CMD_EAGAIN: 1081d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 1082d81ba9d5SMatt Jacob isp_destroy_handle(isp, save_handle); 1083d81ba9d5SMatt Jacob return (CAM_RESRC_UNAVAIL); 1084d81ba9d5SMatt Jacob 1085d81ba9d5SMatt Jacob default: 1086d81ba9d5SMatt Jacob isp_destroy_handle(isp, save_handle); 1087b85389e1SMatt Jacob return (XS_ERR(ccb)); 1088d81ba9d5SMatt Jacob } 1089d81ba9d5SMatt Jacob } 1090d81ba9d5SMatt Jacob 1091a1bc34c6SMatt Jacob static void 1092a1bc34c6SMatt Jacob isp_refire_putback_atio(void *arg) 1093f48ce188SMatt Jacob { 1094a1bc34c6SMatt Jacob int s = splcam(); 1095a1bc34c6SMatt Jacob isp_target_putback_atio(arg); 1096a1bc34c6SMatt Jacob splx(s); 1097a1bc34c6SMatt Jacob } 1098a1bc34c6SMatt Jacob 1099a1bc34c6SMatt Jacob static void 1100a1bc34c6SMatt Jacob isp_target_putback_atio(union ccb *ccb) 1101a1bc34c6SMatt Jacob { 1102a1bc34c6SMatt Jacob struct ispsoftc *isp; 1103a1bc34c6SMatt Jacob struct ccb_scsiio *cso; 1104f48ce188SMatt Jacob u_int16_t iptr, optr; 1105a1bc34c6SMatt Jacob void *qe; 1106a1bc34c6SMatt Jacob 1107a1bc34c6SMatt Jacob isp = XS_ISP(ccb); 1108f48ce188SMatt Jacob 1109f48ce188SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, &qe)) { 1110a1bc34c6SMatt Jacob (void) timeout(isp_refire_putback_atio, ccb, 10); 1111a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGWARN, 1112a1bc34c6SMatt Jacob "isp_target_putback_atio: Request Queue Overflow"); 1113a1bc34c6SMatt Jacob return; 1114f48ce188SMatt Jacob } 1115f48ce188SMatt Jacob bzero(qe, QENTRY_LEN); 1116a1bc34c6SMatt Jacob cso = &ccb->csio; 1117f48ce188SMatt Jacob if (IS_FC(isp)) { 1118f48ce188SMatt Jacob at2_entry_t *at = qe; 1119f48ce188SMatt Jacob at->at_header.rqs_entry_type = RQSTYPE_ATIO2; 1120f48ce188SMatt Jacob at->at_header.rqs_entry_count = 1; 1121f48ce188SMatt Jacob if (isp->isp_maxluns > 16) { 1122a1bc34c6SMatt Jacob at->at_scclun = (uint16_t) ccb->ccb_h.target_lun; 1123f48ce188SMatt Jacob } else { 1124a1bc34c6SMatt Jacob at->at_lun = (uint8_t) ccb->ccb_h.target_lun; 1125f48ce188SMatt Jacob } 1126f48ce188SMatt Jacob at->at_status = CT_OK; 1127a1bc34c6SMatt Jacob at->at_rxid = cso->tag_id; 1128f48ce188SMatt Jacob ISP_SWIZ_ATIO2(isp, qe, qe); 1129f48ce188SMatt Jacob } else { 1130f48ce188SMatt Jacob at_entry_t *at = qe; 1131f48ce188SMatt Jacob at->at_header.rqs_entry_type = RQSTYPE_ATIO; 1132f48ce188SMatt Jacob at->at_header.rqs_entry_count = 1; 1133a1bc34c6SMatt Jacob at->at_iid = cso->init_id; 1134a1bc34c6SMatt Jacob at->at_iid |= XS_CHANNEL(ccb) << 7; 1135a1bc34c6SMatt Jacob at->at_tgt = cso->ccb_h.target_id; 1136a1bc34c6SMatt Jacob at->at_lun = cso->ccb_h.target_lun; 1137f48ce188SMatt Jacob at->at_status = CT_OK; 1138a1bc34c6SMatt Jacob at->at_tag_val = AT_GET_TAG(cso->tag_id); 1139a1bc34c6SMatt Jacob at->at_handle = AT_GET_HANDLE(cso->tag_id); 1140f48ce188SMatt Jacob ISP_SWIZ_ATIO(isp, qe, qe); 1141f48ce188SMatt Jacob } 1142f48ce188SMatt Jacob ISP_TDQE(isp, "isp_target_putback_atio", (int) optr, qe); 1143f48ce188SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 1144a1bc34c6SMatt Jacob isp_complete_ctio(ccb); 1145f48ce188SMatt Jacob } 1146f48ce188SMatt Jacob 1147f48ce188SMatt Jacob static void 1148a1bc34c6SMatt Jacob isp_complete_ctio(union ccb *ccb) 1149f48ce188SMatt Jacob { 1150a1bc34c6SMatt Jacob struct ispsoftc *isp = XS_ISP(ccb); 1151a1bc34c6SMatt Jacob if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) { 1152a1bc34c6SMatt Jacob ccb->ccb_h.status |= CAM_REQ_CMP; 1153f48ce188SMatt Jacob } 1154a1bc34c6SMatt Jacob ccb->ccb_h.status &= ~CAM_SIM_QUEUED; 1155a1bc34c6SMatt Jacob if (isp->isp_osinfo.simqfrozen & SIMQFRZ_RESOURCE) { 1156a1bc34c6SMatt Jacob isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_RESOURCE; 1157a1bc34c6SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 1158a1bc34c6SMatt Jacob if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { 1159a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, "ctio->relsimq"); 1160a1bc34c6SMatt Jacob ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 1161a1bc34c6SMatt Jacob } else { 1162a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGWARN, "ctio->devqfrozen"); 1163a1bc34c6SMatt Jacob } 1164a1bc34c6SMatt Jacob } else { 1165a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGWARN, 1166a1bc34c6SMatt Jacob "ctio->simqfrozen(%x)", isp->isp_osinfo.simqfrozen); 1167a1bc34c6SMatt Jacob } 1168a1bc34c6SMatt Jacob } 1169a1bc34c6SMatt Jacob xpt_done(ccb); 1170f48ce188SMatt Jacob } 1171f48ce188SMatt Jacob 1172d81ba9d5SMatt Jacob /* 1173d81ba9d5SMatt Jacob * Handle ATIO stuff that the generic code can't. 1174d81ba9d5SMatt Jacob * This means handling CDBs. 1175d81ba9d5SMatt Jacob */ 1176d81ba9d5SMatt Jacob 1177d81ba9d5SMatt Jacob static int 1178d81ba9d5SMatt Jacob isp_handle_platform_atio(struct ispsoftc *isp, at_entry_t *aep) 1179d81ba9d5SMatt Jacob { 1180d81ba9d5SMatt Jacob tstate_t *tptr; 1181a1bc34c6SMatt Jacob int status, bus; 1182d81ba9d5SMatt Jacob struct ccb_accept_tio *atiop; 1183d81ba9d5SMatt Jacob 1184d81ba9d5SMatt Jacob /* 1185d81ba9d5SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) 1186d81ba9d5SMatt Jacob * indicates why this ATIO was sent to us. 1187d81ba9d5SMatt Jacob * 1188d81ba9d5SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 1189d81ba9d5SMatt Jacob * 1190d81ba9d5SMatt Jacob * If the DISCONNECTS DISABLED bit is set in the flags field, 11915d571944SMatt Jacob * we're still connected on the SCSI bus. 1192d81ba9d5SMatt Jacob */ 1193d81ba9d5SMatt Jacob status = aep->at_status; 1194d81ba9d5SMatt Jacob if ((status & ~QLTM_SVALID) == AT_PHASE_ERROR) { 1195d81ba9d5SMatt Jacob /* 1196d81ba9d5SMatt Jacob * Bus Phase Sequence error. We should have sense data 1197d81ba9d5SMatt Jacob * suggested by the f/w. I'm not sure quite yet what 1198d81ba9d5SMatt Jacob * to do about this for CAM. 1199d81ba9d5SMatt Jacob */ 12003c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, "PHASE ERROR"); 1201d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1202d81ba9d5SMatt Jacob return (0); 1203d81ba9d5SMatt Jacob } 1204d81ba9d5SMatt Jacob if ((status & ~QLTM_SVALID) != AT_CDB) { 12055d571944SMatt Jacob isp_prt(isp, ISP_LOGWARN, "bad atio (0x%x) leaked to platform", 12063c75bb14SMatt Jacob status); 1207d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1208d81ba9d5SMatt Jacob return (0); 1209d81ba9d5SMatt Jacob } 1210d81ba9d5SMatt Jacob 12115d571944SMatt Jacob bus = GET_BUS_VAL(aep->at_iid); 1212a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, bus, aep->at_lun); 1213d81ba9d5SMatt Jacob if (tptr == NULL) { 1214a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, bus, CAM_LUN_WILDCARD); 1215d81ba9d5SMatt Jacob } 1216d81ba9d5SMatt Jacob 1217d81ba9d5SMatt Jacob if (tptr == NULL) { 1218d81ba9d5SMatt Jacob /* 1219d81ba9d5SMatt Jacob * Because we can't autofeed sense data back with 1220d81ba9d5SMatt Jacob * a command for parallel SCSI, we can't give back 1221d81ba9d5SMatt Jacob * a CHECK CONDITION. We'll give back a BUSY status 1222d81ba9d5SMatt Jacob * instead. This works out okay because the only 1223d81ba9d5SMatt Jacob * time we should, in fact, get this, is in the 1224d81ba9d5SMatt Jacob * case that somebody configured us without the 1225d81ba9d5SMatt Jacob * blackhole driver, so they get what they deserve. 1226d81ba9d5SMatt Jacob */ 1227d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1228d81ba9d5SMatt Jacob return (0); 1229d81ba9d5SMatt Jacob } 1230d81ba9d5SMatt Jacob 1231d81ba9d5SMatt Jacob atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios); 1232d81ba9d5SMatt Jacob if (atiop == NULL) { 1233d81ba9d5SMatt Jacob /* 1234d81ba9d5SMatt Jacob * Because we can't autofeed sense data back with 1235d81ba9d5SMatt Jacob * a command for parallel SCSI, we can't give back 1236d81ba9d5SMatt Jacob * a CHECK CONDITION. We'll give back a QUEUE FULL status 1237d81ba9d5SMatt Jacob * instead. This works out okay because the only time we 1238d81ba9d5SMatt Jacob * should, in fact, get this, is in the case that we've 1239d81ba9d5SMatt Jacob * run out of ATIOS. 1240d81ba9d5SMatt Jacob */ 1241d81ba9d5SMatt Jacob xpt_print_path(tptr->owner); 12423c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 1243a1bc34c6SMatt Jacob "no ATIOS for lun %d from initiator %d on channel %d", 12445d571944SMatt Jacob aep->at_lun, GET_IID_VAL(aep->at_iid), bus); 1245d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 1246d81ba9d5SMatt Jacob if (aep->at_flags & AT_TQAE) 1247d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0); 1248d81ba9d5SMatt Jacob else 1249d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1250d81ba9d5SMatt Jacob return (0); 1251d81ba9d5SMatt Jacob } 1252d81ba9d5SMatt Jacob SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle); 1253a1bc34c6SMatt Jacob if (tptr == &isp->isp_osinfo.tsdflt[bus]) { 1254d81ba9d5SMatt Jacob atiop->ccb_h.target_id = aep->at_tgt; 1255d81ba9d5SMatt Jacob atiop->ccb_h.target_lun = aep->at_lun; 1256d81ba9d5SMatt Jacob } 1257d81ba9d5SMatt Jacob if (aep->at_flags & AT_NODISC) { 1258f48ce188SMatt Jacob atiop->ccb_h.flags = CAM_DIS_DISCONNECT; 1259f48ce188SMatt Jacob } else { 1260f48ce188SMatt Jacob atiop->ccb_h.flags = 0; 1261d81ba9d5SMatt Jacob } 1262d81ba9d5SMatt Jacob 1263f48ce188SMatt Jacob if (status & QLTM_SVALID) { 1264f48ce188SMatt Jacob size_t amt = imin(QLTM_SENSELEN, sizeof (atiop->sense_data)); 1265f48ce188SMatt Jacob atiop->sense_len = amt; 1266f48ce188SMatt Jacob MEMCPY(&atiop->sense_data, aep->at_sense, amt); 1267f48ce188SMatt Jacob } else { 1268f48ce188SMatt Jacob atiop->sense_len = 0; 1269f48ce188SMatt Jacob } 1270d81ba9d5SMatt Jacob 12715d571944SMatt Jacob atiop->init_id = GET_IID_VAL(aep->at_iid); 1272d81ba9d5SMatt Jacob atiop->cdb_len = aep->at_cdblen; 1273d81ba9d5SMatt Jacob MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, aep->at_cdblen); 1274d81ba9d5SMatt Jacob atiop->ccb_h.status = CAM_CDB_RECVD; 1275a1bc34c6SMatt Jacob /* 1276a1bc34c6SMatt Jacob * Construct a tag 'id' based upon tag value (which may be 0..255) 1277a1bc34c6SMatt Jacob * and the handle (which we have to preserve). 1278a1bc34c6SMatt Jacob */ 1279a1bc34c6SMatt Jacob AT_MAKE_TAGID(atiop->tag_id, aep); 1280a1bc34c6SMatt Jacob if (aep->at_flags & AT_TQAE) { 1281a1bc34c6SMatt Jacob atiop->tag_action = aep->at_tag_type; 1282d81ba9d5SMatt Jacob atiop->ccb_h.status |= CAM_TAG_ACTION_VALID; 1283d81ba9d5SMatt Jacob } 1284d81ba9d5SMatt Jacob xpt_done((union ccb*)atiop); 1285a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 12865d571944SMatt Jacob "ATIO[%x] CDB=0x%x bus %d iid%d->lun%d tag 0x%x ttype 0x%x %s", 12875d571944SMatt Jacob aep->at_handle, aep->at_cdb[0] & 0xff, GET_BUS_VAL(aep->at_iid), 12885d571944SMatt Jacob GET_IID_VAL(aep->at_iid), aep->at_lun, aep->at_tag_val & 0xff, 12895d571944SMatt Jacob aep->at_tag_type, (aep->at_flags & AT_NODISC)? 12905d571944SMatt Jacob "nondisc" : "disconnecting"); 1291d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 1292d81ba9d5SMatt Jacob return (0); 1293d81ba9d5SMatt Jacob } 1294d81ba9d5SMatt Jacob 1295d81ba9d5SMatt Jacob static int 1296d81ba9d5SMatt Jacob isp_handle_platform_atio2(struct ispsoftc *isp, at2_entry_t *aep) 1297d81ba9d5SMatt Jacob { 129892a1e549SMatt Jacob lun_id_t lun; 1299d81ba9d5SMatt Jacob tstate_t *tptr; 1300d81ba9d5SMatt Jacob struct ccb_accept_tio *atiop; 1301d81ba9d5SMatt Jacob 1302d81ba9d5SMatt Jacob /* 1303d81ba9d5SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) 1304d81ba9d5SMatt Jacob * indicates why this ATIO was sent to us. 1305d81ba9d5SMatt Jacob * 1306d81ba9d5SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 1307d81ba9d5SMatt Jacob */ 1308d81ba9d5SMatt Jacob if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) { 13093c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 13103c75bb14SMatt Jacob "bogus atio (0x%x) leaked to platform", aep->at_status); 1311d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1312d81ba9d5SMatt Jacob return (0); 1313d81ba9d5SMatt Jacob } 1314d81ba9d5SMatt Jacob 13152ad50ca5SMatt Jacob if (isp->isp_maxluns > 16) { 131692a1e549SMatt Jacob lun = aep->at_scclun; 13172ad50ca5SMatt Jacob } else { 131892a1e549SMatt Jacob lun = aep->at_lun; 13192ad50ca5SMatt Jacob } 1320a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, 0, lun); 1321d81ba9d5SMatt Jacob if (tptr == NULL) { 1322a1bc34c6SMatt Jacob tptr = get_lun_statep(isp, 0, CAM_LUN_WILDCARD); 1323d81ba9d5SMatt Jacob } 1324d81ba9d5SMatt Jacob 1325d81ba9d5SMatt Jacob if (tptr == NULL) { 132652df5dfdSMatt Jacob /* 132752df5dfdSMatt Jacob * What we'd like to know is whether or not we have a listener 132852df5dfdSMatt Jacob * upstream that really hasn't configured yet. If we do, then 132952df5dfdSMatt Jacob * we can give a more sensible reply here. If not, then we can 133052df5dfdSMatt Jacob * reject this out of hand. 133152df5dfdSMatt Jacob * 133252df5dfdSMatt Jacob * Choices for what to send were 133352df5dfdSMatt Jacob * 133452df5dfdSMatt Jacob * Not Ready, Unit Not Self-Configured Yet 133552df5dfdSMatt Jacob * (0x2,0x3e,0x00) 133652df5dfdSMatt Jacob * 133752df5dfdSMatt Jacob * for the former and 133852df5dfdSMatt Jacob * 133952df5dfdSMatt Jacob * Illegal Request, Logical Unit Not Supported 134052df5dfdSMatt Jacob * (0x5,0x25,0x00) 134152df5dfdSMatt Jacob * 134252df5dfdSMatt Jacob * for the latter. 134352df5dfdSMatt Jacob * 134452df5dfdSMatt Jacob * We used to decide whether there was at least one listener 134552df5dfdSMatt Jacob * based upon whether the black hole driver was configured. 134652df5dfdSMatt Jacob * However, recent config(8) changes have made this hard to do 134752df5dfdSMatt Jacob * at this time. 134852df5dfdSMatt Jacob * 134952df5dfdSMatt Jacob */ 1350d81ba9d5SMatt Jacob u_int32_t ccode = SCSI_STATUS_BUSY; 1351d81ba9d5SMatt Jacob 1352d81ba9d5SMatt Jacob /* 1353d81ba9d5SMatt Jacob * Because we can't autofeed sense data back with 1354d81ba9d5SMatt Jacob * a command for parallel SCSI, we can't give back 1355d81ba9d5SMatt Jacob * a CHECK CONDITION. We'll give back a BUSY status 1356d81ba9d5SMatt Jacob * instead. This works out okay because the only 1357d81ba9d5SMatt Jacob * time we should, in fact, get this, is in the 1358d81ba9d5SMatt Jacob * case that somebody configured us without the 1359d81ba9d5SMatt Jacob * blackhole driver, so they get what they deserve. 1360d81ba9d5SMatt Jacob */ 1361d81ba9d5SMatt Jacob isp_endcmd(isp, aep, ccode, 0); 1362d81ba9d5SMatt Jacob return (0); 1363d81ba9d5SMatt Jacob } 1364d81ba9d5SMatt Jacob 1365d81ba9d5SMatt Jacob atiop = (struct ccb_accept_tio *) SLIST_FIRST(&tptr->atios); 1366d81ba9d5SMatt Jacob if (atiop == NULL) { 1367d81ba9d5SMatt Jacob /* 1368d81ba9d5SMatt Jacob * Because we can't autofeed sense data back with 1369d81ba9d5SMatt Jacob * a command for parallel SCSI, we can't give back 1370d81ba9d5SMatt Jacob * a CHECK CONDITION. We'll give back a QUEUE FULL status 1371d81ba9d5SMatt Jacob * instead. This works out okay because the only time we 1372d81ba9d5SMatt Jacob * should, in fact, get this, is in the case that we've 1373d81ba9d5SMatt Jacob * run out of ATIOS. 1374d81ba9d5SMatt Jacob */ 1375d81ba9d5SMatt Jacob xpt_print_path(tptr->owner); 13763c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 13773c75bb14SMatt Jacob "no ATIOS for lun %d from initiator %d", lun, aep->at_iid); 1378d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 1379d81ba9d5SMatt Jacob if (aep->at_flags & AT_TQAE) 1380d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_QUEUE_FULL, 0); 1381d81ba9d5SMatt Jacob else 1382d81ba9d5SMatt Jacob isp_endcmd(isp, aep, SCSI_STATUS_BUSY, 0); 1383d81ba9d5SMatt Jacob return (0); 1384d81ba9d5SMatt Jacob } 1385d81ba9d5SMatt Jacob SLIST_REMOVE_HEAD(&tptr->atios, sim_links.sle); 1386f48ce188SMatt Jacob 1387a1bc34c6SMatt Jacob if (tptr == &isp->isp_osinfo.tsdflt[0]) { 1388d81ba9d5SMatt Jacob atiop->ccb_h.target_id = 1389d81ba9d5SMatt Jacob ((fcparam *)isp->isp_param)->isp_loopid; 139092a1e549SMatt Jacob atiop->ccb_h.target_lun = lun; 1391d81ba9d5SMatt Jacob } 1392b0a3ba7eSMatt Jacob /* 1393b0a3ba7eSMatt Jacob * We don't get 'suggested' sense data as we do with SCSI cards. 1394b0a3ba7eSMatt Jacob */ 1395f48ce188SMatt Jacob atiop->sense_len = 0; 1396f48ce188SMatt Jacob 1397d81ba9d5SMatt Jacob atiop->init_id = aep->at_iid; 1398d81ba9d5SMatt Jacob atiop->cdb_len = ATIO2_CDBLEN; 1399d81ba9d5SMatt Jacob MEMCPY(atiop->cdb_io.cdb_bytes, aep->at_cdb, ATIO2_CDBLEN); 1400d81ba9d5SMatt Jacob atiop->ccb_h.status = CAM_CDB_RECVD; 1401d81ba9d5SMatt Jacob atiop->tag_id = aep->at_rxid; 1402d81ba9d5SMatt Jacob switch (aep->at_taskflags & ATIO2_TC_ATTR_MASK) { 1403d81ba9d5SMatt Jacob case ATIO2_TC_ATTR_SIMPLEQ: 1404d81ba9d5SMatt Jacob atiop->tag_action = MSG_SIMPLE_Q_TAG; 1405d81ba9d5SMatt Jacob break; 1406d81ba9d5SMatt Jacob case ATIO2_TC_ATTR_HEADOFQ: 1407d81ba9d5SMatt Jacob atiop->tag_action = MSG_HEAD_OF_Q_TAG; 1408d81ba9d5SMatt Jacob break; 1409d81ba9d5SMatt Jacob case ATIO2_TC_ATTR_ORDERED: 1410d81ba9d5SMatt Jacob atiop->tag_action = MSG_ORDERED_Q_TAG; 1411d81ba9d5SMatt Jacob break; 1412d81ba9d5SMatt Jacob case ATIO2_TC_ATTR_ACAQ: /* ?? */ 1413d81ba9d5SMatt Jacob case ATIO2_TC_ATTR_UNTAGGED: 1414d81ba9d5SMatt Jacob default: 1415d81ba9d5SMatt Jacob atiop->tag_action = 0; 1416d81ba9d5SMatt Jacob break; 1417d81ba9d5SMatt Jacob } 1418d81ba9d5SMatt Jacob if (atiop->tag_action != 0) { 1419d81ba9d5SMatt Jacob atiop->ccb_h.status |= CAM_TAG_ACTION_VALID; 1420d81ba9d5SMatt Jacob } 1421f48ce188SMatt Jacob 1422f48ce188SMatt Jacob /* 1423f48ce188SMatt Jacob * Preserve overall command datalength in private field. 1424f48ce188SMatt Jacob */ 1425f48ce188SMatt Jacob atiop->ccb_h.spriv_field0 = aep->at_datalen; 1426f48ce188SMatt Jacob 1427d81ba9d5SMatt Jacob xpt_done((union ccb*)atiop); 1428a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 14295f5aafe1SMatt Jacob "ATIO2[%x] CDB=0x%x iid%d->lun%d tattr 0x%x datalen %u", 14305f5aafe1SMatt Jacob aep->at_rxid, aep->at_cdb[0] & 0xff, aep->at_iid, 1431b09b0095SMatt Jacob lun, aep->at_taskflags, aep->at_datalen); 1432d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 1433d81ba9d5SMatt Jacob return (0); 1434d81ba9d5SMatt Jacob } 1435d81ba9d5SMatt Jacob 1436d81ba9d5SMatt Jacob static int 1437d81ba9d5SMatt Jacob isp_handle_platform_ctio(struct ispsoftc *isp, void *arg) 1438d81ba9d5SMatt Jacob { 1439d81ba9d5SMatt Jacob union ccb *ccb; 1440a1bc34c6SMatt Jacob int sentstatus, ok, notify_cam, resid = 0; 1441d81ba9d5SMatt Jacob 1442d81ba9d5SMatt Jacob /* 1443d81ba9d5SMatt Jacob * CTIO and CTIO2 are close enough.... 1444d81ba9d5SMatt Jacob */ 1445d81ba9d5SMatt Jacob 14465f5aafe1SMatt Jacob ccb = (union ccb *) isp_find_xs(isp, ((ct_entry_t *)arg)->ct_syshandle); 1447d81ba9d5SMatt Jacob KASSERT((ccb != NULL), ("null ccb in isp_handle_platform_ctio")); 14485f5aafe1SMatt Jacob isp_destroy_handle(isp, ((ct_entry_t *)arg)->ct_syshandle); 1449d81ba9d5SMatt Jacob 1450d81ba9d5SMatt Jacob if (IS_FC(isp)) { 1451d81ba9d5SMatt Jacob ct2_entry_t *ct = arg; 1452d81ba9d5SMatt Jacob sentstatus = ct->ct_flags & CT2_SENDSTATUS; 1453d81ba9d5SMatt Jacob ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK; 1454a1bc34c6SMatt Jacob if (ok && sentstatus && (ccb->ccb_h.flags & CAM_SEND_SENSE)) { 145500a8e174SMatt Jacob ccb->ccb_h.status |= CAM_SENT_SENSE; 145600a8e174SMatt Jacob } 1457a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 1458a1bc34c6SMatt Jacob "CTIO2[%x] sts 0x%x flg 0x%x sns %d %s", 1459b09b0095SMatt Jacob ct->ct_rxid, ct->ct_status, ct->ct_flags, 1460a1bc34c6SMatt Jacob (ccb->ccb_h.status & CAM_SENT_SENSE) != 0, 1461a1bc34c6SMatt Jacob sentstatus? "FIN" : "MID"); 1462a1bc34c6SMatt Jacob notify_cam = ct->ct_header.rqs_seqno & 0x1; 14635d571944SMatt Jacob if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 1464a1bc34c6SMatt Jacob resid = ct->ct_resid; 14655d571944SMatt Jacob } 1466d81ba9d5SMatt Jacob } else { 1467d81ba9d5SMatt Jacob ct_entry_t *ct = arg; 1468d81ba9d5SMatt Jacob sentstatus = ct->ct_flags & CT_SENDSTATUS; 1469d81ba9d5SMatt Jacob ok = (ct->ct_status & ~QLTM_SVALID) == CT_OK; 1470a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, 1471a1bc34c6SMatt Jacob "CTIO[%x] tag %x iid %x tgt %d lun %d sts 0x%x flg %x %s", 1472a1bc34c6SMatt Jacob ct->ct_fwhandle, ct->ct_tag_val, ct->ct_iid, ct->ct_tgt, 1473a1bc34c6SMatt Jacob ct->ct_lun, ct->ct_status, ct->ct_flags, 1474a1bc34c6SMatt Jacob sentstatus? "FIN" : "MID"); 1475d81ba9d5SMatt Jacob 1476d81ba9d5SMatt Jacob /* 1477a1bc34c6SMatt Jacob * We *ought* to be able to get back to the original ATIO 1478a1bc34c6SMatt Jacob * here, but for some reason this gets lost. It's just as 1479a1bc34c6SMatt Jacob * well because it's squirrelled away as part of periph 1480a1bc34c6SMatt Jacob * private data. 1481a1bc34c6SMatt Jacob * 1482a1bc34c6SMatt Jacob * We can live without it as long as we continue to use 1483a1bc34c6SMatt Jacob * the auto-replenish feature for CTIOs. 1484a1bc34c6SMatt Jacob */ 1485a1bc34c6SMatt Jacob notify_cam = ct->ct_header.rqs_seqno & 0x1; 1486a1bc34c6SMatt Jacob if (ct->ct_status & QLTM_SVALID) { 1487a1bc34c6SMatt Jacob char *sp = (char *)ct; 1488a1bc34c6SMatt Jacob sp += CTIO_SENSE_OFFSET; 1489a1bc34c6SMatt Jacob ccb->csio.sense_len = 1490a1bc34c6SMatt Jacob min(sizeof (ccb->csio.sense_data), QLTM_SENSELEN); 1491a1bc34c6SMatt Jacob MEMCPY(&ccb->csio.sense_data, sp, ccb->csio.sense_len); 1492a1bc34c6SMatt Jacob ccb->ccb_h.status |= CAM_AUTOSNS_VALID; 1493a1bc34c6SMatt Jacob } 14945d571944SMatt Jacob if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) { 1495a1bc34c6SMatt Jacob resid = ct->ct_resid; 1496a1bc34c6SMatt Jacob } 14975d571944SMatt Jacob } 1498a1bc34c6SMatt Jacob ccb->csio.resid += resid; 1499a1bc34c6SMatt Jacob 1500a1bc34c6SMatt Jacob /* 1501a1bc34c6SMatt Jacob * We're here either because intermediate data transfers are done 1502a1bc34c6SMatt Jacob * and/or the final status CTIO (which may have joined with a 1503a1bc34c6SMatt Jacob * Data Transfer) is done. 1504d81ba9d5SMatt Jacob * 1505d81ba9d5SMatt Jacob * In any case, for this platform, the upper layers figure out 1506d81ba9d5SMatt Jacob * what to do next, so all we do here is collect status and 1507a1bc34c6SMatt Jacob * pass information along. Any DMA handles have already been 1508a1bc34c6SMatt Jacob * freed. 1509d81ba9d5SMatt Jacob */ 1510f48ce188SMatt Jacob if (notify_cam == 0) { 1511a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, " INTER CTIO done"); 1512f48ce188SMatt Jacob return (0); 1513f48ce188SMatt Jacob } 1514d81ba9d5SMatt Jacob 1515a1bc34c6SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s CTIO done (resid %d)", 1516a1bc34c6SMatt Jacob (sentstatus)? " FINAL " : "MIDTERM ", ccb->csio.resid); 1517a1bc34c6SMatt Jacob 1518a1bc34c6SMatt Jacob if (!ok) { 1519a1bc34c6SMatt Jacob isp_target_putback_atio(ccb); 1520d81ba9d5SMatt Jacob } else { 1521a1bc34c6SMatt Jacob isp_complete_ctio(ccb); 1522a1bc34c6SMatt Jacob 1523d81ba9d5SMatt Jacob } 1524a1bc34c6SMatt Jacob return (0); 1525d81ba9d5SMatt Jacob } 1526d81ba9d5SMatt Jacob #endif 1527d81ba9d5SMatt Jacob 1528478f8a96SJustin T. Gibbs static void 1529cbf57b47SMatt Jacob isp_cam_async(void *cbarg, u_int32_t code, struct cam_path *path, void *arg) 1530478f8a96SJustin T. Gibbs { 1531478f8a96SJustin T. Gibbs struct cam_sim *sim; 1532478f8a96SJustin T. Gibbs struct ispsoftc *isp; 1533478f8a96SJustin T. Gibbs 1534478f8a96SJustin T. Gibbs sim = (struct cam_sim *)cbarg; 1535478f8a96SJustin T. Gibbs isp = (struct ispsoftc *) cam_sim_softc(sim); 1536478f8a96SJustin T. Gibbs switch (code) { 1537478f8a96SJustin T. Gibbs case AC_LOST_DEVICE: 1538ab6c4b31SMatt Jacob if (IS_SCSI(isp)) { 1539478f8a96SJustin T. Gibbs u_int16_t oflags, nflags; 1540478f8a96SJustin T. Gibbs sdparam *sdp = isp->isp_param; 1541a1bc34c6SMatt Jacob int tgt; 1542478f8a96SJustin T. Gibbs 1543f9e908dcSMatt Jacob tgt = xpt_path_target_id(path); 1544f6e75de2SMatt Jacob ISP_LOCK(isp); 1545ea6f23cdSMatt Jacob sdp += cam_sim_bus(sim); 15469ce9bdafSMatt Jacob nflags = sdp->isp_devparam[tgt].nvrm_flags; 1547a1bc34c6SMatt Jacob #ifndef ISP_TARGET_MODE 15489ce9bdafSMatt Jacob nflags &= DPARM_SAFE_DFLT; 1549a1bc34c6SMatt Jacob if (isp->isp_loaded_fw) { 1550478f8a96SJustin T. Gibbs nflags |= DPARM_NARROW | DPARM_ASYNC; 1551478f8a96SJustin T. Gibbs } 1552a1bc34c6SMatt Jacob #else 1553a1bc34c6SMatt Jacob nflags = DPARM_DEFAULT; 1554a1bc34c6SMatt Jacob #endif 15559ce9bdafSMatt Jacob oflags = sdp->isp_devparam[tgt].goal_flags; 15569ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_flags = nflags; 1557478f8a96SJustin T. Gibbs sdp->isp_devparam[tgt].dev_update = 1; 1558a1bc34c6SMatt Jacob isp->isp_update |= (1 << cam_sim_bus(sim)); 1559478f8a96SJustin T. Gibbs (void) isp_control(isp, ISPCTL_UPDATE_PARAMS, NULL); 15609ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_flags = oflags; 1561f6e75de2SMatt Jacob ISP_UNLOCK(isp); 1562478f8a96SJustin T. Gibbs } 1563478f8a96SJustin T. Gibbs break; 1564478f8a96SJustin T. Gibbs default: 15653c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, "isp_cam_async: Code 0x%x", code); 1566478f8a96SJustin T. Gibbs break; 1567478f8a96SJustin T. Gibbs } 1568478f8a96SJustin T. Gibbs } 1569478f8a96SJustin T. Gibbs 1570478f8a96SJustin T. Gibbs static void 1571c3055363SMatt Jacob isp_poll(struct cam_sim *sim) 1572478f8a96SJustin T. Gibbs { 1573c40e096eSMatt Jacob struct ispsoftc *isp = cam_sim_softc(sim); 1574c40e096eSMatt Jacob ISP_LOCK(isp); 1575c40e096eSMatt Jacob (void) isp_intr(isp); 1576c40e096eSMatt Jacob ISP_UNLOCK(isp); 1577478f8a96SJustin T. Gibbs } 1578478f8a96SJustin T. Gibbs 15795d571944SMatt Jacob #if 0 15800470d791SMatt Jacob static void 15810470d791SMatt Jacob isp_relsim(void *arg) 15820470d791SMatt Jacob { 15830470d791SMatt Jacob struct ispsoftc *isp = arg; 1584f6e75de2SMatt Jacob ISP_LOCK(isp); 15850470d791SMatt Jacob if (isp->isp_osinfo.simqfrozen & SIMQFRZ_TIMED) { 15860470d791SMatt Jacob int wasfrozen = isp->isp_osinfo.simqfrozen & SIMQFRZ_TIMED; 15870470d791SMatt Jacob isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_TIMED; 15880470d791SMatt Jacob if (wasfrozen && isp->isp_osinfo.simqfrozen == 0) { 15890470d791SMatt Jacob xpt_release_simq(isp->isp_sim, 1); 1590b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, "timed relsimq"); 15910470d791SMatt Jacob } 15920470d791SMatt Jacob } 1593f6e75de2SMatt Jacob ISP_UNLOCK(isp); 15940470d791SMatt Jacob } 15955d571944SMatt Jacob #endif 1596ab6c4b31SMatt Jacob 1597478f8a96SJustin T. Gibbs static void 1598b85389e1SMatt Jacob isp_watchdog(void *arg) 1599cc8df88bSMatt Jacob { 1600b09b0095SMatt Jacob XS_T *xs = arg; 1601cc8df88bSMatt Jacob struct ispsoftc *isp = XS_ISP(xs); 1602cc8df88bSMatt Jacob u_int32_t handle; 1603b85389e1SMatt Jacob 1604cc8df88bSMatt Jacob /* 1605b85389e1SMatt Jacob * We've decided this command is dead. Make sure we're not trying 1606b85389e1SMatt Jacob * to kill a command that's already dead by getting it's handle and 1607b85389e1SMatt Jacob * and seeing whether it's still alive. 1608cc8df88bSMatt Jacob */ 1609f6e75de2SMatt Jacob ISP_LOCK(isp); 1610cc8df88bSMatt Jacob handle = isp_find_handle(isp, xs); 1611cc8df88bSMatt Jacob if (handle) { 1612b85389e1SMatt Jacob u_int16_t r; 1613b85389e1SMatt Jacob 1614b85389e1SMatt Jacob if (XS_CMD_DONE_P(xs)) { 1615b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG1, 1616b09b0095SMatt Jacob "watchdog found done cmd (handle 0x%x)", handle); 1617f6e75de2SMatt Jacob ISP_UNLOCK(isp); 1618b85389e1SMatt Jacob return; 1619b85389e1SMatt Jacob } 1620b85389e1SMatt Jacob 1621b85389e1SMatt Jacob if (XS_CMD_WDOG_P(xs)) { 1622b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 1623b09b0095SMatt Jacob "recursive watchdog (handle 0x%x)", handle); 1624f6e75de2SMatt Jacob ISP_UNLOCK(isp); 1625b85389e1SMatt Jacob return; 1626b85389e1SMatt Jacob } 1627b85389e1SMatt Jacob 1628b85389e1SMatt Jacob XS_CMD_S_WDOG(xs); 1629b85389e1SMatt Jacob 1630b85389e1SMatt Jacob r = ISP_READ(isp, BIU_ISR); 1631b85389e1SMatt Jacob 1632b85389e1SMatt Jacob if (INT_PENDING(isp, r) && isp_intr(isp) && XS_CMD_DONE_P(xs)) { 1633b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 1634b09b0095SMatt Jacob "watchdog cleanup (%x, %x)", handle, r); 1635b85389e1SMatt Jacob xpt_done((union ccb *) xs); 1636b85389e1SMatt Jacob } else if (XS_CMD_GRACE_P(xs)) { 16371fcf5debSMatt Jacob /* 16381fcf5debSMatt Jacob * Make sure the command is *really* dead before we 16391fcf5debSMatt Jacob * release the handle (and DMA resources) for reuse. 16401fcf5debSMatt Jacob */ 16411fcf5debSMatt Jacob (void) isp_control(isp, ISPCTL_ABORT_CMD, arg); 16421fcf5debSMatt Jacob 16431fcf5debSMatt Jacob /* 16441fcf5debSMatt Jacob * After this point, the comamnd is really dead. 16451fcf5debSMatt Jacob */ 1646f6e75de2SMatt Jacob if (XS_XFRLEN(xs)) { 1647f6e75de2SMatt Jacob ISP_DMAFREE(isp, xs, handle); 1648f6e75de2SMatt Jacob } 1649cc8df88bSMatt Jacob isp_destroy_handle(isp, handle); 1650cc8df88bSMatt Jacob xpt_print_path(xs->ccb_h.path); 16513c75bb14SMatt Jacob isp_prt(isp, ISP_LOGWARN, 16523c75bb14SMatt Jacob "watchdog timeout (%x, %x)", handle, r); 1653cc8df88bSMatt Jacob XS_SETERR(xs, CAM_CMD_TIMEOUT); 1654b85389e1SMatt Jacob XS_CMD_C_WDOG(xs); 1655cc8df88bSMatt Jacob isp_done(xs); 1656b85389e1SMatt Jacob } else { 1657b85389e1SMatt Jacob u_int16_t iptr, optr; 1658b85389e1SMatt Jacob ispreq_t *mp; 1659b85389e1SMatt Jacob 1660b85389e1SMatt Jacob XS_CMD_C_WDOG(xs); 1661b85389e1SMatt Jacob xs->ccb_h.timeout_ch = timeout(isp_watchdog, xs, hz); 1662b85389e1SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, (void **) &mp)) { 1663f6e75de2SMatt Jacob ISP_UNLOCK(isp); 1664b85389e1SMatt Jacob return; 1665b85389e1SMatt Jacob } 1666b85389e1SMatt Jacob XS_CMD_S_GRACE(xs); 1667b85389e1SMatt Jacob MEMZERO((void *) mp, sizeof (*mp)); 1668b85389e1SMatt Jacob mp->req_header.rqs_entry_count = 1; 1669b85389e1SMatt Jacob mp->req_header.rqs_entry_type = RQSTYPE_MARKER; 1670b85389e1SMatt Jacob mp->req_modifier = SYNC_ALL; 1671b85389e1SMatt Jacob mp->req_target = XS_CHANNEL(xs) << 7; 1672b85389e1SMatt Jacob ISP_SWIZZLE_REQUEST(isp, mp); 1673b85389e1SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 1674b85389e1SMatt Jacob } 1675b85389e1SMatt Jacob } else { 1676b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, "watchdog with no command"); 1677cc8df88bSMatt Jacob } 1678f6e75de2SMatt Jacob ISP_UNLOCK(isp); 1679cc8df88bSMatt Jacob } 1680cc8df88bSMatt Jacob 1681f44257c2SMatt Jacob static int isp_ktmature = 0; 1682f44257c2SMatt Jacob 16835d571944SMatt Jacob static void 16845d571944SMatt Jacob isp_kthread(void *arg) 16855d571944SMatt Jacob { 16865d571944SMatt Jacob int wasfrozen; 16875d571944SMatt Jacob struct ispsoftc *isp = arg; 16885d571944SMatt Jacob 16895d571944SMatt Jacob mtx_lock(&isp->isp_lock); 16905d571944SMatt Jacob for (;;) { 16915d571944SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, "kthread checking FC state"); 16925d571944SMatt Jacob while (isp_fc_runstate(isp, 2 * 1000000) != 0) { 1693f44257c2SMatt Jacob if (FCPARAM(isp)->isp_fwstate != FW_READY || 1694f44257c2SMatt Jacob FCPARAM(isp)->isp_loopstate < LOOP_PDB_RCVD) { 1695f44257c2SMatt Jacob if (FCPARAM(isp)->loop_seen_once == 0 || 1696f44257c2SMatt Jacob isp_ktmature == 0) { 1697f44257c2SMatt Jacob break; 1698f44257c2SMatt Jacob } 1699f44257c2SMatt Jacob } 17005d571944SMatt Jacob msleep(isp_kthread, &isp->isp_lock, 17015d571944SMatt Jacob PRIBIO, "isp_fcthrd", hz); 17025d571944SMatt Jacob } 1703f44257c2SMatt Jacob /* 1704f44257c2SMatt Jacob * Even if we didn't get good loop state we may be 1705f44257c2SMatt Jacob * unfreezing the SIMQ so that we can kill off 1706f44257c2SMatt Jacob * commands (if we've never seen loop before, e.g.) 1707f44257c2SMatt Jacob */ 1708f44257c2SMatt Jacob isp_ktmature = 1; 17095d571944SMatt Jacob wasfrozen = isp->isp_osinfo.simqfrozen & SIMQFRZ_LOOPDOWN; 17105d571944SMatt Jacob isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_LOOPDOWN; 17115d571944SMatt Jacob if (wasfrozen && isp->isp_osinfo.simqfrozen == 0) { 17125d571944SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, "kthread up release simq"); 17135d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 17145d571944SMatt Jacob xpt_release_simq(isp->isp_sim, 1); 17155d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 17165d571944SMatt Jacob } 17175d571944SMatt Jacob cv_wait(&isp->isp_osinfo.kthread_cv, &isp->isp_lock); 17185d571944SMatt Jacob } 17195d571944SMatt Jacob } 17205d571944SMatt Jacob 1721cc8df88bSMatt Jacob static void 1722c3055363SMatt Jacob isp_action(struct cam_sim *sim, union ccb *ccb) 1723478f8a96SJustin T. Gibbs { 1724f6e75de2SMatt Jacob int bus, tgt, error; 1725478f8a96SJustin T. Gibbs struct ispsoftc *isp; 17264663e367SJustin T. Gibbs struct ccb_trans_settings *cts; 1727478f8a96SJustin T. Gibbs 1728478f8a96SJustin T. Gibbs CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("isp_action\n")); 1729478f8a96SJustin T. Gibbs 1730478f8a96SJustin T. Gibbs isp = (struct ispsoftc *)cam_sim_softc(sim); 1731478f8a96SJustin T. Gibbs ccb->ccb_h.sim_priv.entries[0].field = 0; 1732478f8a96SJustin T. Gibbs ccb->ccb_h.sim_priv.entries[1].ptr = isp; 17330470d791SMatt Jacob if (isp->isp_state != ISP_RUNSTATE && 17340470d791SMatt Jacob ccb->ccb_h.func_code == XPT_SCSI_IO) { 17355d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 173657c801f5SMatt Jacob isp_init(isp); 173757c801f5SMatt Jacob if (isp->isp_state != ISP_INITSTATE) { 1738f6e75de2SMatt Jacob ISP_UNLOCK(isp); 173957c801f5SMatt Jacob /* 174057c801f5SMatt Jacob * Lie. Say it was a selection timeout. 174157c801f5SMatt Jacob */ 1742b85389e1SMatt Jacob ccb->ccb_h.status = CAM_SEL_TIMEOUT | CAM_DEV_QFRZN; 17430470d791SMatt Jacob xpt_freeze_devq(ccb->ccb_h.path, 1); 174457c801f5SMatt Jacob xpt_done(ccb); 174557c801f5SMatt Jacob return; 174657c801f5SMatt Jacob } 174757c801f5SMatt Jacob isp->isp_state = ISP_RUNSTATE; 17485d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 174957c801f5SMatt Jacob } 1750b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code); 1751478f8a96SJustin T. Gibbs 17525d571944SMatt Jacob 1753478f8a96SJustin T. Gibbs switch (ccb->ccb_h.func_code) { 1754478f8a96SJustin T. Gibbs case XPT_SCSI_IO: /* Execute the requested I/O operation */ 1755478f8a96SJustin T. Gibbs /* 1756478f8a96SJustin T. Gibbs * Do a couple of preliminary checks... 1757478f8a96SJustin T. Gibbs */ 1758478f8a96SJustin T. Gibbs if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) { 1759478f8a96SJustin T. Gibbs if ((ccb->ccb_h.flags & CAM_CDB_PHYS) != 0) { 1760478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_INVALID; 1761478f8a96SJustin T. Gibbs xpt_done(ccb); 1762478f8a96SJustin T. Gibbs break; 1763478f8a96SJustin T. Gibbs } 1764478f8a96SJustin T. Gibbs } 17650470d791SMatt Jacob #ifdef DIAGNOSTIC 17660470d791SMatt Jacob if (ccb->ccb_h.target_id > (ISP_MAX_TARGETS(isp) - 1)) { 1767478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_PATH_INVALID; 17680470d791SMatt Jacob } else if (ccb->ccb_h.target_lun > (ISP_MAX_LUNS(isp) - 1)) { 1769478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_PATH_INVALID; 1770478f8a96SJustin T. Gibbs } 1771478f8a96SJustin T. Gibbs if (ccb->ccb_h.status == CAM_PATH_INVALID) { 1772bfbab170SMatt Jacob isp_prt(isp, ISP_LOGERR, 1773bfbab170SMatt Jacob "invalid tgt/lun (%d.%d) in XPT_SCSI_IO", 1774bfbab170SMatt Jacob ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 1775478f8a96SJustin T. Gibbs xpt_done(ccb); 1776478f8a96SJustin T. Gibbs break; 1777478f8a96SJustin T. Gibbs } 17780470d791SMatt Jacob #endif 17790470d791SMatt Jacob ((struct ccb_scsiio *) ccb)->scsi_status = SCSI_STATUS_OK; 17805d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1781b09b0095SMatt Jacob error = isp_start((XS_T *) ccb); 17820470d791SMatt Jacob switch (error) { 1783478f8a96SJustin T. Gibbs case CMD_QUEUED: 1784478f8a96SJustin T. Gibbs ccb->ccb_h.status |= CAM_SIM_QUEUED; 1785cc8df88bSMatt Jacob if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) { 1786d69a5f7dSMatt Jacob u_int64_t ticks = (u_int64_t) hz; 1787cc8df88bSMatt Jacob if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT) 1788d69a5f7dSMatt Jacob ticks = 60 * 1000 * ticks; 1789b85389e1SMatt Jacob else 1790b85389e1SMatt Jacob ticks = ccb->ccb_h.timeout * hz; 1791b85389e1SMatt Jacob ticks = ((ticks + 999) / 1000) + hz + hz; 1792d69a5f7dSMatt Jacob if (ticks >= 0x80000000) { 1793d69a5f7dSMatt Jacob isp_prt(isp, ISP_LOGERR, 1794d69a5f7dSMatt Jacob "timeout overflow"); 1795d69a5f7dSMatt Jacob ticks = 0x80000000; 1796d69a5f7dSMatt Jacob } 1797d69a5f7dSMatt Jacob ccb->ccb_h.timeout_ch = timeout(isp_watchdog, 1798d69a5f7dSMatt Jacob (caddr_t)ccb, (int)ticks); 1799b85389e1SMatt Jacob } else { 1800b85389e1SMatt Jacob callout_handle_init(&ccb->ccb_h.timeout_ch); 1801cc8df88bSMatt Jacob } 18025d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1803478f8a96SJustin T. Gibbs break; 18040470d791SMatt Jacob case CMD_RQLATER: 1805f44257c2SMatt Jacob /* 1806f44257c2SMatt Jacob * This can only happen for Fibre Channel 1807f44257c2SMatt Jacob */ 1808f44257c2SMatt Jacob KASSERT((IS_FC(isp)), ("CMD_RQLATER for FC only")); 1809f44257c2SMatt Jacob if (FCPARAM(isp)->loop_seen_once == 0 && isp_ktmature) { 1810f44257c2SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1811f44257c2SMatt Jacob XS_SETERR(ccb, CAM_SEL_TIMEOUT); 1812f44257c2SMatt Jacob xpt_done(ccb); 1813f44257c2SMatt Jacob break; 1814f44257c2SMatt Jacob } 18155d571944SMatt Jacob cv_signal(&isp->isp_osinfo.kthread_cv); 18160470d791SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 1817b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 1818b09b0095SMatt Jacob "RQLATER freeze simq"); 18195d571944SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN; 18205d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1821478f8a96SJustin T. Gibbs xpt_freeze_simq(sim, 1); 18225d571944SMatt Jacob } else { 18235d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 182400f50ce8SMatt Jacob } 1825b85389e1SMatt Jacob XS_SETERR(ccb, CAM_REQUEUE_REQ); 1826478f8a96SJustin T. Gibbs xpt_done(ccb); 1827478f8a96SJustin T. Gibbs break; 18280470d791SMatt Jacob case CMD_EAGAIN: 18290470d791SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 18300470d791SMatt Jacob xpt_freeze_simq(sim, 1); 1831b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 1832b09b0095SMatt Jacob "EAGAIN freeze simq"); 1833478f8a96SJustin T. Gibbs } 18340470d791SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_RESOURCE; 1835b85389e1SMatt Jacob XS_SETERR(ccb, CAM_REQUEUE_REQ); 18365d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1837478f8a96SJustin T. Gibbs xpt_done(ccb); 1838478f8a96SJustin T. Gibbs break; 18390470d791SMatt Jacob case CMD_COMPLETE: 18400470d791SMatt Jacob isp_done((struct ccb_scsiio *) ccb); 18415d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 18420470d791SMatt Jacob break; 18430470d791SMatt Jacob default: 1844bfbab170SMatt Jacob isp_prt(isp, ISP_LOGERR, 1845bfbab170SMatt Jacob "What's this? 0x%x at %d in file %s", 184691f1caa2SMatt Jacob error, __LINE__, __FILE__); 1847b85389e1SMatt Jacob XS_SETERR(ccb, CAM_REQ_CMP_ERR); 18480470d791SMatt Jacob xpt_done(ccb); 18495d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1850478f8a96SJustin T. Gibbs } 1851478f8a96SJustin T. Gibbs break; 1852478f8a96SJustin T. Gibbs 1853d81ba9d5SMatt Jacob #ifdef ISP_TARGET_MODE 1854478f8a96SJustin T. Gibbs case XPT_EN_LUN: /* Enable LUN as a target */ 18555d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1856d81ba9d5SMatt Jacob isp_en_lun(isp, ccb); 18575d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1858478f8a96SJustin T. Gibbs xpt_done(ccb); 1859478f8a96SJustin T. Gibbs break; 1860478f8a96SJustin T. Gibbs 1861d81ba9d5SMatt Jacob case XPT_NOTIFY_ACK: /* recycle notify ack */ 1862d81ba9d5SMatt Jacob case XPT_IMMED_NOTIFY: /* Add Immediate Notify Resource */ 1863d81ba9d5SMatt Jacob case XPT_ACCEPT_TARGET_IO: /* Add Accept Target IO Resource */ 1864d81ba9d5SMatt Jacob { 1865a1bc34c6SMatt Jacob tstate_t *tptr = 1866a1bc34c6SMatt Jacob get_lun_statep(isp, XS_CHANNEL(ccb), ccb->ccb_h.target_lun); 1867d81ba9d5SMatt Jacob if (tptr == NULL) { 1868d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_LUN_INVALID; 1869d81ba9d5SMatt Jacob xpt_done(ccb); 1870d81ba9d5SMatt Jacob break; 1871d81ba9d5SMatt Jacob } 1872f48ce188SMatt Jacob ccb->ccb_h.sim_priv.entries[0].field = 0; 1873f48ce188SMatt Jacob ccb->ccb_h.sim_priv.entries[1].ptr = isp; 18745d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1875d81ba9d5SMatt Jacob if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) { 1876d81ba9d5SMatt Jacob SLIST_INSERT_HEAD(&tptr->atios, 1877d81ba9d5SMatt Jacob &ccb->ccb_h, sim_links.sle); 1878d81ba9d5SMatt Jacob } else { 1879d81ba9d5SMatt Jacob SLIST_INSERT_HEAD(&tptr->inots, &ccb->ccb_h, 1880d81ba9d5SMatt Jacob sim_links.sle); 1881d81ba9d5SMatt Jacob } 1882d81ba9d5SMatt Jacob rls_lun_statep(isp, tptr); 1883d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_REQ_INPROG; 18845d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1885d81ba9d5SMatt Jacob break; 1886d81ba9d5SMatt Jacob } 1887d81ba9d5SMatt Jacob case XPT_CONT_TARGET_IO: 1888d81ba9d5SMatt Jacob { 18895d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1890d81ba9d5SMatt Jacob ccb->ccb_h.status = isp_target_start_ctio(isp, ccb); 1891d81ba9d5SMatt Jacob if (ccb->ccb_h.status != CAM_REQ_INPROG) { 1892d81ba9d5SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 1893d81ba9d5SMatt Jacob xpt_freeze_simq(sim, 1); 1894d81ba9d5SMatt Jacob xpt_print_path(ccb->ccb_h.path); 18953c75bb14SMatt Jacob isp_prt(isp, ISP_LOGINFO, 18963c75bb14SMatt Jacob "XPT_CONT_TARGET_IO freeze simq"); 1897d81ba9d5SMatt Jacob } 1898d81ba9d5SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_RESOURCE; 1899b85389e1SMatt Jacob XS_SETERR(ccb, CAM_REQUEUE_REQ); 19005d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1901d81ba9d5SMatt Jacob xpt_done(ccb); 1902d81ba9d5SMatt Jacob } else { 19035d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1904d81ba9d5SMatt Jacob ccb->ccb_h.status |= CAM_SIM_QUEUED; 1905d81ba9d5SMatt Jacob } 1906d81ba9d5SMatt Jacob break; 1907d81ba9d5SMatt Jacob } 1908d81ba9d5SMatt Jacob #endif 1909478f8a96SJustin T. Gibbs case XPT_RESET_DEV: /* BDR the specified SCSI device */ 1910d81ba9d5SMatt Jacob 1911d81ba9d5SMatt Jacob bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)); 1912d81ba9d5SMatt Jacob tgt = ccb->ccb_h.target_id; 1913d81ba9d5SMatt Jacob tgt |= (bus << 16); 1914d81ba9d5SMatt Jacob 19155d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1916ea6f23cdSMatt Jacob error = isp_control(isp, ISPCTL_RESET_DEV, &tgt); 19175d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1918478f8a96SJustin T. Gibbs if (error) { 1919478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP_ERR; 1920478f8a96SJustin T. Gibbs } else { 1921478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 1922478f8a96SJustin T. Gibbs } 1923478f8a96SJustin T. Gibbs xpt_done(ccb); 1924478f8a96SJustin T. Gibbs break; 1925478f8a96SJustin T. Gibbs case XPT_ABORT: /* Abort the specified CCB */ 1926d81ba9d5SMatt Jacob { 1927d81ba9d5SMatt Jacob union ccb *accb = ccb->cab.abort_ccb; 19285d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1929d81ba9d5SMatt Jacob switch (accb->ccb_h.func_code) { 1930d81ba9d5SMatt Jacob #ifdef ISP_TARGET_MODE 1931d81ba9d5SMatt Jacob case XPT_ACCEPT_TARGET_IO: 1932d81ba9d5SMatt Jacob case XPT_IMMED_NOTIFY: 1933d81ba9d5SMatt Jacob ccb->ccb_h.status = isp_abort_tgt_ccb(isp, ccb); 1934d81ba9d5SMatt Jacob break; 1935d81ba9d5SMatt Jacob case XPT_CONT_TARGET_IO: 1936b09b0095SMatt Jacob isp_prt(isp, ISP_LOGERR, "cannot abort CTIOs yet"); 1937d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_UA_ABORT; 1938d81ba9d5SMatt Jacob break; 1939d81ba9d5SMatt Jacob #endif 1940d81ba9d5SMatt Jacob case XPT_SCSI_IO: 1941478f8a96SJustin T. Gibbs error = isp_control(isp, ISPCTL_ABORT_CMD, ccb); 1942478f8a96SJustin T. Gibbs if (error) { 1943d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_UA_ABORT; 1944478f8a96SJustin T. Gibbs } else { 1945478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 1946478f8a96SJustin T. Gibbs } 1947d81ba9d5SMatt Jacob break; 1948d81ba9d5SMatt Jacob default: 1949d81ba9d5SMatt Jacob ccb->ccb_h.status = CAM_REQ_INVALID; 1950d81ba9d5SMatt Jacob break; 1951d81ba9d5SMatt Jacob } 19525d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 1953478f8a96SJustin T. Gibbs xpt_done(ccb); 1954478f8a96SJustin T. Gibbs break; 1955d81ba9d5SMatt Jacob } 1956ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 1957ab163f5fSMatt Jacob #define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS) 1958ab163f5fSMatt Jacob #else 1959ab163f5fSMatt Jacob #define IS_CURRENT_SETTINGS(c) (c->flags & CCB_TRANS_CURRENT_SETTINGS) 1960ab163f5fSMatt Jacob #endif 1961478f8a96SJustin T. Gibbs case XPT_SET_TRAN_SETTINGS: /* Nexus Settings */ 1962478f8a96SJustin T. Gibbs cts = &ccb->cts; 19639ce9bdafSMatt Jacob if (!IS_CURRENT_SETTINGS(cts)) { 19649ce9bdafSMatt Jacob ccb->ccb_h.status = CAM_REQ_INVALID; 19659ce9bdafSMatt Jacob xpt_done(ccb); 19669ce9bdafSMatt Jacob break; 19679ce9bdafSMatt Jacob } 1968478f8a96SJustin T. Gibbs tgt = cts->ccb_h.target_id; 19695d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 1970ab6c4b31SMatt Jacob if (IS_SCSI(isp)) { 1971ab163f5fSMatt Jacob #ifndef CAM_NEW_TRAN_CODE 1972478f8a96SJustin T. Gibbs sdparam *sdp = isp->isp_param; 1973478f8a96SJustin T. Gibbs u_int16_t *dptr; 1974d81ba9d5SMatt Jacob 1975d81ba9d5SMatt Jacob bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path)); 1976478f8a96SJustin T. Gibbs 1977ea6f23cdSMatt Jacob sdp += bus; 1978478f8a96SJustin T. Gibbs /* 19799ce9bdafSMatt Jacob * We always update (internally) from goal_flags 1980478f8a96SJustin T. Gibbs * so any request to change settings just gets 1981478f8a96SJustin T. Gibbs * vectored to that location. 1982478f8a96SJustin T. Gibbs */ 19839ce9bdafSMatt Jacob dptr = &sdp->isp_devparam[tgt].goal_flags; 1984478f8a96SJustin T. Gibbs 1985478f8a96SJustin T. Gibbs /* 1986478f8a96SJustin T. Gibbs * Note that these operations affect the 19879ce9bdafSMatt Jacob * the goal flags (goal_flags)- not 1988478f8a96SJustin T. Gibbs * the current state flags. Then we mark 1989478f8a96SJustin T. Gibbs * things so that the next operation to 1990478f8a96SJustin T. Gibbs * this HBA will cause the update to occur. 1991478f8a96SJustin T. Gibbs */ 1992478f8a96SJustin T. Gibbs if (cts->valid & CCB_TRANS_DISC_VALID) { 1993478f8a96SJustin T. Gibbs if ((cts->flags & CCB_TRANS_DISC_ENB) != 0) { 1994478f8a96SJustin T. Gibbs *dptr |= DPARM_DISC; 1995478f8a96SJustin T. Gibbs } else { 1996478f8a96SJustin T. Gibbs *dptr &= ~DPARM_DISC; 1997478f8a96SJustin T. Gibbs } 1998478f8a96SJustin T. Gibbs } 1999478f8a96SJustin T. Gibbs if (cts->valid & CCB_TRANS_TQ_VALID) { 2000478f8a96SJustin T. Gibbs if ((cts->flags & CCB_TRANS_TAG_ENB) != 0) { 2001478f8a96SJustin T. Gibbs *dptr |= DPARM_TQING; 2002478f8a96SJustin T. Gibbs } else { 2003478f8a96SJustin T. Gibbs *dptr &= ~DPARM_TQING; 2004478f8a96SJustin T. Gibbs } 2005478f8a96SJustin T. Gibbs } 2006478f8a96SJustin T. Gibbs if (cts->valid & CCB_TRANS_BUS_WIDTH_VALID) { 2007478f8a96SJustin T. Gibbs switch (cts->bus_width) { 2008478f8a96SJustin T. Gibbs case MSG_EXT_WDTR_BUS_16_BIT: 2009478f8a96SJustin T. Gibbs *dptr |= DPARM_WIDE; 2010478f8a96SJustin T. Gibbs break; 2011478f8a96SJustin T. Gibbs default: 2012478f8a96SJustin T. Gibbs *dptr &= ~DPARM_WIDE; 2013478f8a96SJustin T. Gibbs } 2014478f8a96SJustin T. Gibbs } 2015478f8a96SJustin T. Gibbs /* 2016478f8a96SJustin T. Gibbs * Any SYNC RATE of nonzero and SYNC_OFFSET 2017478f8a96SJustin T. Gibbs * of nonzero will cause us to go to the 2018478f8a96SJustin T. Gibbs * selected (from NVRAM) maximum value for 2019478f8a96SJustin T. Gibbs * this device. At a later point, we'll 2020478f8a96SJustin T. Gibbs * allow finer control. 2021478f8a96SJustin T. Gibbs */ 2022478f8a96SJustin T. Gibbs if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) && 2023478f8a96SJustin T. Gibbs (cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) && 2024478f8a96SJustin T. Gibbs (cts->sync_offset > 0)) { 2025478f8a96SJustin T. Gibbs *dptr |= DPARM_SYNC; 2026478f8a96SJustin T. Gibbs } else { 2027478f8a96SJustin T. Gibbs *dptr &= ~DPARM_SYNC; 2028478f8a96SJustin T. Gibbs } 2029ab6c4b31SMatt Jacob *dptr |= DPARM_SAFE_DFLT; 2030ab163f5fSMatt Jacob #else 2031ab163f5fSMatt Jacob struct ccb_trans_settings_scsi *scsi = 2032ab163f5fSMatt Jacob &cts->proto_specific.scsi; 2033ab163f5fSMatt Jacob struct ccb_trans_settings_spi *spi = 2034ab163f5fSMatt Jacob &cts->xport_specific.spi; 2035ab163f5fSMatt Jacob sdparam *sdp = isp->isp_param; 2036ab163f5fSMatt Jacob u_int16_t *dptr; 2037ab163f5fSMatt Jacob 2038ab163f5fSMatt Jacob bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path)); 2039ab163f5fSMatt Jacob sdp += bus; 2040ab163f5fSMatt Jacob /* 20419ce9bdafSMatt Jacob * We always update (internally) from goal_flags 2042ab163f5fSMatt Jacob * so any request to change settings just gets 2043ab163f5fSMatt Jacob * vectored to that location. 2044ab163f5fSMatt Jacob */ 20459ce9bdafSMatt Jacob dptr = &sdp->isp_devparam[tgt].goal_flags; 2046ab163f5fSMatt Jacob 2047ab163f5fSMatt Jacob if ((spi->valid & CTS_SPI_VALID_DISC) != 0) { 2048ab163f5fSMatt Jacob if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0) 2049ab163f5fSMatt Jacob *dptr |= DPARM_DISC; 2050ab163f5fSMatt Jacob else 2051ab163f5fSMatt Jacob *dptr &= ~DPARM_DISC; 2052ab163f5fSMatt Jacob } 2053ab163f5fSMatt Jacob 2054ab163f5fSMatt Jacob if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) { 2055ab163f5fSMatt Jacob if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) 2056ab163f5fSMatt Jacob *dptr |= DPARM_TQING; 2057ab163f5fSMatt Jacob else 2058ab163f5fSMatt Jacob *dptr &= ~DPARM_TQING; 2059ab163f5fSMatt Jacob } 2060ab163f5fSMatt Jacob 2061ab163f5fSMatt Jacob if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) { 2062ab163f5fSMatt Jacob if (spi->bus_width == MSG_EXT_WDTR_BUS_16_BIT) 2063ab163f5fSMatt Jacob *dptr |= DPARM_WIDE; 2064ab163f5fSMatt Jacob else 2065ab163f5fSMatt Jacob *dptr &= ~DPARM_WIDE; 2066ab163f5fSMatt Jacob } 2067ab163f5fSMatt Jacob 2068ab163f5fSMatt Jacob /* 2069ab163f5fSMatt Jacob * XXX: FIX ME 2070ab163f5fSMatt Jacob */ 2071ab163f5fSMatt Jacob if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) && 20729ce9bdafSMatt Jacob (spi->valid & CTS_SPI_VALID_SYNC_RATE) && 20739ce9bdafSMatt Jacob (spi->sync_period && spi->sync_offset)) { 2074ab163f5fSMatt Jacob *dptr |= DPARM_SYNC; 20759ce9bdafSMatt Jacob /* 20769ce9bdafSMatt Jacob * XXX: CHECK FOR LEGALITY 20779ce9bdafSMatt Jacob */ 20789ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_period = 20799ce9bdafSMatt Jacob spi->sync_period; 20809ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_offset = 20819ce9bdafSMatt Jacob spi->sync_offset; 2082ab163f5fSMatt Jacob } else { 2083ab163f5fSMatt Jacob *dptr &= ~DPARM_SYNC; 2084ab163f5fSMatt Jacob } 2085ab163f5fSMatt Jacob #endif 2086bfbab170SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, 20879ce9bdafSMatt Jacob "SET bus %d targ %d to flags %x off %x per %x", 20889ce9bdafSMatt Jacob bus, tgt, sdp->isp_devparam[tgt].goal_flags, 20899ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_offset, 20909ce9bdafSMatt Jacob sdp->isp_devparam[tgt].goal_period); 2091478f8a96SJustin T. Gibbs sdp->isp_devparam[tgt].dev_update = 1; 2092ea6f23cdSMatt Jacob isp->isp_update |= (1 << bus); 2093478f8a96SJustin T. Gibbs } 20945d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2095478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 2096478f8a96SJustin T. Gibbs xpt_done(ccb); 2097478f8a96SJustin T. Gibbs break; 2098478f8a96SJustin T. Gibbs case XPT_GET_TRAN_SETTINGS: 2099478f8a96SJustin T. Gibbs cts = &ccb->cts; 2100478f8a96SJustin T. Gibbs tgt = cts->ccb_h.target_id; 2101ab163f5fSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2102ab6c4b31SMatt Jacob if (IS_FC(isp)) { 2103ab163f5fSMatt Jacob #ifndef CAM_NEW_TRAN_CODE 2104478f8a96SJustin T. Gibbs /* 2105478f8a96SJustin T. Gibbs * a lot of normal SCSI things don't make sense. 2106478f8a96SJustin T. Gibbs */ 2107478f8a96SJustin T. Gibbs cts->flags = CCB_TRANS_TAG_ENB | CCB_TRANS_DISC_ENB; 2108478f8a96SJustin T. Gibbs cts->valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID; 2109478f8a96SJustin T. Gibbs /* 2110478f8a96SJustin T. Gibbs * How do you measure the width of a high 2111478f8a96SJustin T. Gibbs * speed serial bus? Well, in bytes. 2112478f8a96SJustin T. Gibbs * 2113478f8a96SJustin T. Gibbs * Offset and period make no sense, though, so we set 2114478f8a96SJustin T. Gibbs * (above) a 'base' transfer speed to be gigabit. 2115478f8a96SJustin T. Gibbs */ 2116478f8a96SJustin T. Gibbs cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 2117ab163f5fSMatt Jacob #else 2118ab163f5fSMatt Jacob fcparam *fcp = isp->isp_param; 2119ab163f5fSMatt Jacob struct ccb_trans_settings_fc *fc = 2120ab163f5fSMatt Jacob &cts->xport_specific.fc; 2121478f8a96SJustin T. Gibbs 2122ab163f5fSMatt Jacob cts->protocol = PROTO_SCSI; 2123ab163f5fSMatt Jacob cts->protocol_version = SCSI_REV_2; 2124ab163f5fSMatt Jacob cts->transport = XPORT_FC; 2125ab163f5fSMatt Jacob cts->transport_version = 0; 2126ab163f5fSMatt Jacob 2127ab163f5fSMatt Jacob fc->valid = CTS_FC_VALID_SPEED; 2128ab163f5fSMatt Jacob fc->bitrate = 100000; 2129ab163f5fSMatt Jacob if (tgt > 0 && tgt < MAX_FC_TARG) { 2130ab163f5fSMatt Jacob struct lportdb *lp = &fcp->portdb[tgt]; 2131ab163f5fSMatt Jacob fc->wwnn = lp->node_wwn; 2132ab163f5fSMatt Jacob fc->wwpn = lp->port_wwn; 2133ab163f5fSMatt Jacob fc->port = lp->portid; 2134ab163f5fSMatt Jacob fc->valid |= CTS_FC_VALID_WWNN | 2135ab163f5fSMatt Jacob CTS_FC_VALID_WWPN | CTS_FC_VALID_PORT; 2136ab163f5fSMatt Jacob } 2137ab163f5fSMatt Jacob #endif 2138ab163f5fSMatt Jacob } else { 2139ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2140ab163f5fSMatt Jacob struct ccb_trans_settings_scsi *scsi = 2141ab163f5fSMatt Jacob &cts->proto_specific.scsi; 2142ab163f5fSMatt Jacob struct ccb_trans_settings_spi *spi = 2143ab163f5fSMatt Jacob &cts->xport_specific.spi; 2144ab163f5fSMatt Jacob #endif 2145ab163f5fSMatt Jacob sdparam *sdp = isp->isp_param; 2146ab163f5fSMatt Jacob int bus = cam_sim_bus(xpt_path_sim(cts->ccb_h.path)); 2147ab163f5fSMatt Jacob u_int16_t dval, pval, oval; 2148ab163f5fSMatt Jacob 2149ea6f23cdSMatt Jacob sdp += bus; 2150ab163f5fSMatt Jacob 2151ab163f5fSMatt Jacob if (IS_CURRENT_SETTINGS(cts)) { 215283ae4407SMatt Jacob sdp->isp_devparam[tgt].dev_refresh = 1; 215383ae4407SMatt Jacob isp->isp_update |= (1 << bus); 215483ae4407SMatt Jacob (void) isp_control(isp, ISPCTL_UPDATE_PARAMS, 215583ae4407SMatt Jacob NULL); 21569ce9bdafSMatt Jacob dval = sdp->isp_devparam[tgt].actv_flags; 21579ce9bdafSMatt Jacob oval = sdp->isp_devparam[tgt].actv_offset; 21589ce9bdafSMatt Jacob pval = sdp->isp_devparam[tgt].actv_period; 21594394c92fSMatt Jacob } else { 21609ce9bdafSMatt Jacob dval = sdp->isp_devparam[tgt].nvrm_flags; 21619ce9bdafSMatt Jacob oval = sdp->isp_devparam[tgt].nvrm_offset; 21629ce9bdafSMatt Jacob pval = sdp->isp_devparam[tgt].nvrm_period; 21634394c92fSMatt Jacob } 2164478f8a96SJustin T. Gibbs 2165ab163f5fSMatt Jacob #ifndef CAM_NEW_TRAN_CODE 2166478f8a96SJustin T. Gibbs cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB); 2167478f8a96SJustin T. Gibbs 2168478f8a96SJustin T. Gibbs if (dval & DPARM_DISC) { 2169478f8a96SJustin T. Gibbs cts->flags |= CCB_TRANS_DISC_ENB; 2170478f8a96SJustin T. Gibbs } 2171478f8a96SJustin T. Gibbs if (dval & DPARM_TQING) { 2172478f8a96SJustin T. Gibbs cts->flags |= CCB_TRANS_TAG_ENB; 2173478f8a96SJustin T. Gibbs } 2174478f8a96SJustin T. Gibbs if (dval & DPARM_WIDE) { 2175478f8a96SJustin T. Gibbs cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT; 2176478f8a96SJustin T. Gibbs } else { 2177478f8a96SJustin T. Gibbs cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 2178478f8a96SJustin T. Gibbs } 2179478f8a96SJustin T. Gibbs cts->valid = CCB_TRANS_BUS_WIDTH_VALID | 2180478f8a96SJustin T. Gibbs CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID; 2181478f8a96SJustin T. Gibbs 21824394c92fSMatt Jacob if ((dval & DPARM_SYNC) && oval != 0) { 21834394c92fSMatt Jacob cts->sync_period = pval; 21844394c92fSMatt Jacob cts->sync_offset = oval; 2185478f8a96SJustin T. Gibbs cts->valid |= 2186478f8a96SJustin T. Gibbs CCB_TRANS_SYNC_RATE_VALID | 2187478f8a96SJustin T. Gibbs CCB_TRANS_SYNC_OFFSET_VALID; 2188478f8a96SJustin T. Gibbs } 2189ab163f5fSMatt Jacob #else 2190ab163f5fSMatt Jacob cts->protocol = PROTO_SCSI; 2191ab163f5fSMatt Jacob cts->protocol_version = SCSI_REV_2; 2192ab163f5fSMatt Jacob cts->transport = XPORT_SPI; 2193ab163f5fSMatt Jacob cts->transport_version = 2; 2194ab163f5fSMatt Jacob 2195ab163f5fSMatt Jacob scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 2196ab163f5fSMatt Jacob spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB; 2197ab163f5fSMatt Jacob if (dval & DPARM_DISC) { 2198ab163f5fSMatt Jacob spi->flags |= CTS_SPI_FLAGS_DISC_ENB; 2199ab163f5fSMatt Jacob } 2200ab163f5fSMatt Jacob if (dval & DPARM_TQING) { 2201ab163f5fSMatt Jacob scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB; 2202ab163f5fSMatt Jacob } 22039ce9bdafSMatt Jacob if ((dval & DPARM_SYNC) && oval && pval) { 2204ab163f5fSMatt Jacob spi->sync_offset = oval; 2205ab163f5fSMatt Jacob spi->sync_period = pval; 2206ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_SYNC_OFFSET; 2207ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_SYNC_RATE; 2208ab163f5fSMatt Jacob } 2209ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_BUS_WIDTH; 2210ab163f5fSMatt Jacob if (dval & DPARM_WIDE) { 2211ab163f5fSMatt Jacob spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT; 2212ab163f5fSMatt Jacob } else { 2213ab163f5fSMatt Jacob spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 2214ab163f5fSMatt Jacob } 2215ab163f5fSMatt Jacob if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) { 2216ab163f5fSMatt Jacob scsi->valid = CTS_SCSI_VALID_TQ; 2217ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_DISC; 2218ab163f5fSMatt Jacob } else { 2219ab163f5fSMatt Jacob scsi->valid = 0; 2220ab163f5fSMatt Jacob } 2221ab163f5fSMatt Jacob #endif 2222bfbab170SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, 22239ce9bdafSMatt Jacob "GET %s bus %d targ %d to flags %x off %x per %x", 22249ce9bdafSMatt Jacob IS_CURRENT_SETTINGS(cts)? "ACTIVE" : "NVRAM", 22259ce9bdafSMatt Jacob bus, tgt, dval, oval, pval); 2226478f8a96SJustin T. Gibbs } 2227ab163f5fSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2228478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 2229478f8a96SJustin T. Gibbs xpt_done(ccb); 2230478f8a96SJustin T. Gibbs break; 2231478f8a96SJustin T. Gibbs 2232478f8a96SJustin T. Gibbs case XPT_CALC_GEOMETRY: 2233478f8a96SJustin T. Gibbs { 2234478f8a96SJustin T. Gibbs struct ccb_calc_geometry *ccg; 2235478f8a96SJustin T. Gibbs u_int32_t secs_per_cylinder; 2236478f8a96SJustin T. Gibbs u_int32_t size_mb; 2237478f8a96SJustin T. Gibbs 2238478f8a96SJustin T. Gibbs ccg = &ccb->ccg; 2239478f8a96SJustin T. Gibbs if (ccg->block_size == 0) { 2240bfbab170SMatt Jacob isp_prt(isp, ISP_LOGERR, 2241bfbab170SMatt Jacob "%d.%d XPT_CALC_GEOMETRY block size 0?", 2242bfbab170SMatt Jacob ccg->ccb_h.target_id, ccg->ccb_h.target_lun); 2243478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_INVALID; 2244478f8a96SJustin T. Gibbs xpt_done(ccb); 2245478f8a96SJustin T. Gibbs break; 2246478f8a96SJustin T. Gibbs } 2247478f8a96SJustin T. Gibbs size_mb = ccg->volume_size /((1024L * 1024L) / ccg->block_size); 2248478f8a96SJustin T. Gibbs if (size_mb > 1024) { 2249478f8a96SJustin T. Gibbs ccg->heads = 255; 2250478f8a96SJustin T. Gibbs ccg->secs_per_track = 63; 2251478f8a96SJustin T. Gibbs } else { 2252478f8a96SJustin T. Gibbs ccg->heads = 64; 2253478f8a96SJustin T. Gibbs ccg->secs_per_track = 32; 2254478f8a96SJustin T. Gibbs } 2255478f8a96SJustin T. Gibbs secs_per_cylinder = ccg->heads * ccg->secs_per_track; 2256478f8a96SJustin T. Gibbs ccg->cylinders = ccg->volume_size / secs_per_cylinder; 2257478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 2258478f8a96SJustin T. Gibbs xpt_done(ccb); 2259478f8a96SJustin T. Gibbs break; 2260478f8a96SJustin T. Gibbs } 2261478f8a96SJustin T. Gibbs case XPT_RESET_BUS: /* Reset the specified bus */ 2262ab6c4b31SMatt Jacob bus = cam_sim_bus(sim); 22635d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2264ab6c4b31SMatt Jacob error = isp_control(isp, ISPCTL_RESET_BUS, &bus); 22655d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2266478f8a96SJustin T. Gibbs if (error) 2267478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP_ERR; 22682b052931SMatt Jacob else { 2269ea6f23cdSMatt Jacob if (cam_sim_bus(sim) && isp->isp_path2 != NULL) 2270ea6f23cdSMatt Jacob xpt_async(AC_BUS_RESET, isp->isp_path2, NULL); 2271ea6f23cdSMatt Jacob else if (isp->isp_path != NULL) 22722b052931SMatt Jacob xpt_async(AC_BUS_RESET, isp->isp_path, NULL); 2273478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_CMP; 22742b052931SMatt Jacob } 2275478f8a96SJustin T. Gibbs xpt_done(ccb); 2276478f8a96SJustin T. Gibbs break; 2277478f8a96SJustin T. Gibbs 2278478f8a96SJustin T. Gibbs case XPT_TERM_IO: /* Terminate the I/O process */ 2279478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_INVALID; 2280478f8a96SJustin T. Gibbs xpt_done(ccb); 2281478f8a96SJustin T. Gibbs break; 2282478f8a96SJustin T. Gibbs 2283478f8a96SJustin T. Gibbs case XPT_PATH_INQ: /* Path routing inquiry */ 2284478f8a96SJustin T. Gibbs { 2285478f8a96SJustin T. Gibbs struct ccb_pathinq *cpi = &ccb->cpi; 2286478f8a96SJustin T. Gibbs 2287478f8a96SJustin T. Gibbs cpi->version_num = 1; 2288d81ba9d5SMatt Jacob #ifdef ISP_TARGET_MODE 2289a1bc34c6SMatt Jacob cpi->target_sprt = PIT_PROCESSOR | PIT_DISCONNECT | PIT_TERM_IO; 2290d81ba9d5SMatt Jacob #else 2291478f8a96SJustin T. Gibbs cpi->target_sprt = 0; 2292d81ba9d5SMatt Jacob #endif 2293478f8a96SJustin T. Gibbs cpi->hba_eng_cnt = 0; 22940470d791SMatt Jacob cpi->max_target = ISP_MAX_TARGETS(isp) - 1; 22950470d791SMatt Jacob cpi->max_lun = ISP_MAX_LUNS(isp) - 1; 22960470d791SMatt Jacob cpi->bus_id = cam_sim_bus(sim); 22974394c92fSMatt Jacob if (IS_FC(isp)) { 22984394c92fSMatt Jacob cpi->hba_misc = PIM_NOBUSRESET; 22990470d791SMatt Jacob /* 23000470d791SMatt Jacob * Because our loop ID can shift from time to time, 23010470d791SMatt Jacob * make our initiator ID out of range of our bus. 23020470d791SMatt Jacob */ 23030470d791SMatt Jacob cpi->initiator_id = cpi->max_target + 1; 23040470d791SMatt Jacob 23059deea857SKenneth D. Merry /* 23069deea857SKenneth D. Merry * Set base transfer capabilities for Fibre Channel. 23079deea857SKenneth D. Merry * Technically not correct because we don't know 23089deea857SKenneth D. Merry * what media we're running on top of- but we'll 23099deea857SKenneth D. Merry * look good if we always say 100MB/s. 23109deea857SKenneth D. Merry */ 23119deea857SKenneth D. Merry cpi->base_transfer_speed = 100000; 23120470d791SMatt Jacob cpi->hba_inquiry = PI_TAG_ABLE; 2313ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2314ab163f5fSMatt Jacob cpi->transport = XPORT_FC; 2315ab163f5fSMatt Jacob cpi->transport_version = 0; /* WHAT'S THIS FOR? */ 2316ab163f5fSMatt Jacob #endif 2317478f8a96SJustin T. Gibbs } else { 2318ea6f23cdSMatt Jacob sdparam *sdp = isp->isp_param; 2319ea6f23cdSMatt Jacob sdp += cam_sim_bus(xpt_path_sim(cpi->ccb_h.path)); 23200470d791SMatt Jacob cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16; 23214394c92fSMatt Jacob cpi->hba_misc = 0; 2322ea6f23cdSMatt Jacob cpi->initiator_id = sdp->isp_initiator_id; 23239deea857SKenneth D. Merry cpi->base_transfer_speed = 3300; 2324ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2325ab163f5fSMatt Jacob cpi->transport = XPORT_SPI; 2326ab163f5fSMatt Jacob cpi->transport_version = 2; /* WHAT'S THIS FOR? */ 2327ab163f5fSMatt Jacob #endif 2328478f8a96SJustin T. Gibbs } 2329ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2330ab163f5fSMatt Jacob cpi->protocol = PROTO_SCSI; 2331ab163f5fSMatt Jacob cpi->protocol_version = SCSI_REV_2; 2332ab163f5fSMatt Jacob #endif 2333478f8a96SJustin T. Gibbs strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 2334478f8a96SJustin T. Gibbs strncpy(cpi->hba_vid, "Qlogic", HBA_IDLEN); 2335478f8a96SJustin T. Gibbs strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 2336478f8a96SJustin T. Gibbs cpi->unit_number = cam_sim_unit(sim); 2337478f8a96SJustin T. Gibbs cpi->ccb_h.status = CAM_REQ_CMP; 2338478f8a96SJustin T. Gibbs xpt_done(ccb); 2339478f8a96SJustin T. Gibbs break; 2340478f8a96SJustin T. Gibbs } 2341478f8a96SJustin T. Gibbs default: 2342478f8a96SJustin T. Gibbs ccb->ccb_h.status = CAM_REQ_INVALID; 2343478f8a96SJustin T. Gibbs xpt_done(ccb); 2344478f8a96SJustin T. Gibbs break; 2345478f8a96SJustin T. Gibbs } 2346478f8a96SJustin T. Gibbs } 2347d3a9eb2eSMatt Jacob 2348d3a9eb2eSMatt Jacob #define ISPDDB (CAM_DEBUG_INFO|CAM_DEBUG_TRACE|CAM_DEBUG_CDB) 2349d3a9eb2eSMatt Jacob void 2350c3055363SMatt Jacob isp_done(struct ccb_scsiio *sccb) 2351d3a9eb2eSMatt Jacob { 2352d3a9eb2eSMatt Jacob struct ispsoftc *isp = XS_ISP(sccb); 2353d3a9eb2eSMatt Jacob 2354d3a9eb2eSMatt Jacob if (XS_NOERR(sccb)) 2355d3a9eb2eSMatt Jacob XS_SETERR(sccb, CAM_REQ_CMP); 2356b85389e1SMatt Jacob 2357d3a9eb2eSMatt Jacob if ((sccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP && 2358d3a9eb2eSMatt Jacob (sccb->scsi_status != SCSI_STATUS_OK)) { 2359d3a9eb2eSMatt Jacob sccb->ccb_h.status &= ~CAM_STATUS_MASK; 236092a1e549SMatt Jacob if ((sccb->scsi_status == SCSI_STATUS_CHECK_COND) && 236192a1e549SMatt Jacob (sccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0) { 236292a1e549SMatt Jacob sccb->ccb_h.status |= CAM_AUTOSENSE_FAIL; 236392a1e549SMatt Jacob } else { 2364d3a9eb2eSMatt Jacob sccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR; 2365d3a9eb2eSMatt Jacob } 236692a1e549SMatt Jacob } 2367b85389e1SMatt Jacob 23680470d791SMatt Jacob sccb->ccb_h.status &= ~CAM_SIM_QUEUED; 2369d3a9eb2eSMatt Jacob if ((sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 2370d3a9eb2eSMatt Jacob if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { 2371d3a9eb2eSMatt Jacob sccb->ccb_h.status |= CAM_DEV_QFRZN; 23720470d791SMatt Jacob xpt_freeze_devq(sccb->ccb_h.path, 1); 23730470d791SMatt Jacob if (sccb->scsi_status != SCSI_STATUS_OK) 2374b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2375b09b0095SMatt Jacob "freeze devq %d.%d %x %x", 2376b09b0095SMatt Jacob sccb->ccb_h.target_id, 23770470d791SMatt Jacob sccb->ccb_h.target_lun, sccb->ccb_h.status, 2378b09b0095SMatt Jacob sccb->scsi_status); 2379d3a9eb2eSMatt Jacob } 2380d3a9eb2eSMatt Jacob } 2381b85389e1SMatt Jacob 23820470d791SMatt Jacob /* 23830470d791SMatt Jacob * If we were frozen waiting resources, clear that we were frozen 23840470d791SMatt Jacob * waiting for resources. If we are no longer frozen, and the devq 23850470d791SMatt Jacob * isn't frozen, mark the completing CCB to have the XPT layer 23860470d791SMatt Jacob * release the simq. 23870470d791SMatt Jacob */ 238857c801f5SMatt Jacob if (isp->isp_osinfo.simqfrozen & SIMQFRZ_RESOURCE) { 238957c801f5SMatt Jacob isp->isp_osinfo.simqfrozen &= ~SIMQFRZ_RESOURCE; 23900470d791SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 23910470d791SMatt Jacob if ((sccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { 2392b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2393b09b0095SMatt Jacob "isp_done->relsimq"); 2394d3a9eb2eSMatt Jacob sccb->ccb_h.status |= CAM_RELEASE_SIMQ; 23950470d791SMatt Jacob } else { 2396b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2397b09b0095SMatt Jacob "isp_done->devq frozen"); 2398d3a9eb2eSMatt Jacob } 23990470d791SMatt Jacob } else { 2400b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2401b09b0095SMatt Jacob "isp_done -> simqfrozen = %x", 2402b09b0095SMatt Jacob isp->isp_osinfo.simqfrozen); 24030470d791SMatt Jacob } 24040470d791SMatt Jacob } 2405b85389e1SMatt Jacob if ((CAM_DEBUGGED(sccb->ccb_h.path, ISPDDB)) && 2406d3a9eb2eSMatt Jacob (sccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 2407d3a9eb2eSMatt Jacob xpt_print_path(sccb->ccb_h.path); 24083c75bb14SMatt Jacob isp_prt(isp, ISP_LOGINFO, 24093c75bb14SMatt Jacob "cam completion status 0x%x", sccb->ccb_h.status); 2410d3a9eb2eSMatt Jacob } 2411b85389e1SMatt Jacob 2412b85389e1SMatt Jacob XS_CMD_S_DONE(sccb); 2413b85389e1SMatt Jacob if (XS_CMD_WDOG_P(sccb) == 0) { 2414b85389e1SMatt Jacob untimeout(isp_watchdog, (caddr_t)sccb, sccb->ccb_h.timeout_ch); 2415b85389e1SMatt Jacob if (XS_CMD_GRACE_P(sccb)) { 2416b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2417b09b0095SMatt Jacob "finished command on borrowed time"); 2418b85389e1SMatt Jacob } 2419b85389e1SMatt Jacob XS_CMD_S_CLEAR(sccb); 24205d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2421d3a9eb2eSMatt Jacob xpt_done((union ccb *) sccb); 24225d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2423d3a9eb2eSMatt Jacob } 2424b85389e1SMatt Jacob } 2425d3a9eb2eSMatt Jacob 2426cbf57b47SMatt Jacob int 24270470d791SMatt Jacob isp_async(struct ispsoftc *isp, ispasync_t cmd, void *arg) 2428cbf57b47SMatt Jacob { 2429ea6f23cdSMatt Jacob int bus, rv = 0; 2430cbf57b47SMatt Jacob switch (cmd) { 2431cbf57b47SMatt Jacob case ISPASYNC_NEW_TGT_PARAMS: 24320470d791SMatt Jacob { 2433ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2434ab163f5fSMatt Jacob struct ccb_trans_settings_scsi *scsi; 2435ab163f5fSMatt Jacob struct ccb_trans_settings_spi *spi; 2436ab163f5fSMatt Jacob #endif 2437cbf57b47SMatt Jacob int flags, tgt; 2438cbf57b47SMatt Jacob sdparam *sdp = isp->isp_param; 2439ab163f5fSMatt Jacob struct ccb_trans_settings cts; 2440cbf57b47SMatt Jacob struct cam_path *tmppath; 2441cbf57b47SMatt Jacob 2442ab163f5fSMatt Jacob bzero(&cts, sizeof (struct ccb_trans_settings)); 2443ab163f5fSMatt Jacob 2444cbf57b47SMatt Jacob tgt = *((int *)arg); 2445ea6f23cdSMatt Jacob bus = (tgt >> 16) & 0xffff; 2446ea6f23cdSMatt Jacob tgt &= 0xffff; 2447ea6f23cdSMatt Jacob sdp += bus; 244845c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2449cbf57b47SMatt Jacob if (xpt_create_path(&tmppath, NULL, 2450ea6f23cdSMatt Jacob cam_sim_path(bus? isp->isp_sim2 : isp->isp_sim), 2451ea6f23cdSMatt Jacob tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 245245c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2453bfbab170SMatt Jacob isp_prt(isp, ISP_LOGWARN, 2454bfbab170SMatt Jacob "isp_async cannot make temp path for %d.%d", 2455bfbab170SMatt Jacob tgt, bus); 2456cbf57b47SMatt Jacob rv = -1; 2457cbf57b47SMatt Jacob break; 2458cbf57b47SMatt Jacob } 245945c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 24609ce9bdafSMatt Jacob flags = sdp->isp_devparam[tgt].actv_flags; 2461ab163f5fSMatt Jacob #ifdef CAM_NEW_TRAN_CODE 2462ab163f5fSMatt Jacob cts.type = CTS_TYPE_CURRENT_SETTINGS; 2463ab163f5fSMatt Jacob cts.protocol = PROTO_SCSI; 2464ab163f5fSMatt Jacob cts.transport = XPORT_SPI; 2465ab163f5fSMatt Jacob 2466ab163f5fSMatt Jacob scsi = &cts.proto_specific.scsi; 2467ab163f5fSMatt Jacob spi = &cts.xport_specific.spi; 2468ab163f5fSMatt Jacob 2469ab163f5fSMatt Jacob if (flags & DPARM_TQING) { 2470ab163f5fSMatt Jacob scsi->valid |= CTS_SCSI_VALID_TQ; 2471ab163f5fSMatt Jacob scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB; 2472ab163f5fSMatt Jacob spi->flags |= CTS_SPI_FLAGS_TAG_ENB; 2473ab163f5fSMatt Jacob } 2474ab163f5fSMatt Jacob 2475cbf57b47SMatt Jacob if (flags & DPARM_DISC) { 2476ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_DISC; 2477ab163f5fSMatt Jacob spi->flags |= CTS_SPI_FLAGS_DISC_ENB; 2478ab163f5fSMatt Jacob } 2479ab163f5fSMatt Jacob spi->flags |= CTS_SPI_VALID_BUS_WIDTH; 2480ab163f5fSMatt Jacob if (flags & DPARM_WIDE) { 2481ab163f5fSMatt Jacob spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT; 2482ab163f5fSMatt Jacob } else { 2483ab163f5fSMatt Jacob spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 2484ab163f5fSMatt Jacob } 2485ab163f5fSMatt Jacob if (flags & DPARM_SYNC) { 2486ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_SYNC_RATE; 2487ab163f5fSMatt Jacob spi->valid |= CTS_SPI_VALID_SYNC_OFFSET; 24889ce9bdafSMatt Jacob spi->sync_period = sdp->isp_devparam[tgt].actv_period; 24899ce9bdafSMatt Jacob spi->sync_offset = sdp->isp_devparam[tgt].actv_offset; 2490ab163f5fSMatt Jacob } 2491ab163f5fSMatt Jacob #else 2492ab163f5fSMatt Jacob cts.flags = CCB_TRANS_CURRENT_SETTINGS; 2493ab163f5fSMatt Jacob cts.valid = CCB_TRANS_DISC_VALID | CCB_TRANS_TQ_VALID; 2494ab163f5fSMatt Jacob if (flags & DPARM_DISC) { 2495ab163f5fSMatt Jacob cts.flags |= CCB_TRANS_DISC_ENB; 2496cbf57b47SMatt Jacob } 2497cbf57b47SMatt Jacob if (flags & DPARM_TQING) { 2498ab163f5fSMatt Jacob cts.flags |= CCB_TRANS_TAG_ENB; 2499cbf57b47SMatt Jacob } 2500ab163f5fSMatt Jacob cts.valid |= CCB_TRANS_BUS_WIDTH_VALID; 2501ab163f5fSMatt Jacob cts.bus_width = (flags & DPARM_WIDE)? 2502cbf57b47SMatt Jacob MSG_EXT_WDTR_BUS_8_BIT : MSG_EXT_WDTR_BUS_16_BIT; 25039ce9bdafSMatt Jacob cts.sync_period = sdp->isp_devparam[tgt].actv_period; 25049ce9bdafSMatt Jacob cts.sync_offset = sdp->isp_devparam[tgt].actv_offset; 2505cbf57b47SMatt Jacob if (flags & DPARM_SYNC) { 2506ab163f5fSMatt Jacob cts.valid |= 25074394c92fSMatt Jacob CCB_TRANS_SYNC_RATE_VALID | 2508cbf57b47SMatt Jacob CCB_TRANS_SYNC_OFFSET_VALID; 2509cbf57b47SMatt Jacob } 2510ab163f5fSMatt Jacob #endif 2511b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2512b09b0095SMatt Jacob "NEW_TGT_PARAMS bus %d tgt %d period %x offset %x flags %x", 25139ce9bdafSMatt Jacob bus, tgt, sdp->isp_devparam[tgt].actv_period, 25149ce9bdafSMatt Jacob sdp->isp_devparam[tgt].actv_offset, flags); 2515ab163f5fSMatt Jacob xpt_setup_ccb(&cts.ccb_h, tmppath, 1); 25165d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2517ab163f5fSMatt Jacob xpt_async(AC_TRANSFER_NEG, tmppath, &cts); 2518cbf57b47SMatt Jacob xpt_free_path(tmppath); 2519f44257c2SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2520cbf57b47SMatt Jacob break; 25210470d791SMatt Jacob } 252257c801f5SMatt Jacob case ISPASYNC_BUS_RESET: 2523ea6f23cdSMatt Jacob bus = *((int *)arg); 2524b09b0095SMatt Jacob isp_prt(isp, ISP_LOGINFO, "SCSI bus reset on bus %d detected", 2525b09b0095SMatt Jacob bus); 2526ea6f23cdSMatt Jacob if (bus > 0 && isp->isp_path2) { 25275d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2528ea6f23cdSMatt Jacob xpt_async(AC_BUS_RESET, isp->isp_path2, NULL); 25295d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2530ea6f23cdSMatt Jacob } else if (isp->isp_path) { 25315d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 253257c801f5SMatt Jacob xpt_async(AC_BUS_RESET, isp->isp_path, NULL); 25335d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 253457c801f5SMatt Jacob } 253557c801f5SMatt Jacob break; 25365d571944SMatt Jacob case ISPASYNC_LIP: 25375d571944SMatt Jacob if (isp->isp_path) { 25385d571944SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 25395d571944SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, "LIP freeze simq"); 25405d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 25415d571944SMatt Jacob xpt_freeze_simq(isp->isp_sim, 1); 25425d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 25435d571944SMatt Jacob } 25445d571944SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN; 25455d571944SMatt Jacob } 25465d571944SMatt Jacob isp_prt(isp, ISP_LOGINFO, "LIP Received"); 25475d571944SMatt Jacob break; 25485d571944SMatt Jacob case ISPASYNC_LOOP_RESET: 25495d571944SMatt Jacob if (isp->isp_path) { 25505d571944SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 25515d571944SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, 25525d571944SMatt Jacob "Loop Reset freeze simq"); 25535d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 25545d571944SMatt Jacob xpt_freeze_simq(isp->isp_sim, 1); 25555d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 25565d571944SMatt Jacob } 25575d571944SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN; 25585d571944SMatt Jacob } 25595d571944SMatt Jacob isp_prt(isp, ISP_LOGINFO, "Loop Reset Received"); 25605d571944SMatt Jacob break; 256157c801f5SMatt Jacob case ISPASYNC_LOOP_DOWN: 256257c801f5SMatt Jacob if (isp->isp_path) { 25630470d791SMatt Jacob if (isp->isp_osinfo.simqfrozen == 0) { 25645d571944SMatt Jacob isp_prt(isp, ISP_LOGDEBUG0, 2565b09b0095SMatt Jacob "loop down freeze simq"); 25665d571944SMatt Jacob ISPLOCK_2_CAMLOCK(isp); 256757c801f5SMatt Jacob xpt_freeze_simq(isp->isp_sim, 1); 25685d571944SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 25690470d791SMatt Jacob } 257057c801f5SMatt Jacob isp->isp_osinfo.simqfrozen |= SIMQFRZ_LOOPDOWN; 257157c801f5SMatt Jacob } 2572b09b0095SMatt Jacob isp_prt(isp, ISP_LOGINFO, "Loop DOWN"); 257357c801f5SMatt Jacob break; 257457c801f5SMatt Jacob case ISPASYNC_LOOP_UP: 25755d571944SMatt Jacob /* 25765d571944SMatt Jacob * Now we just note that Loop has come up. We don't 25775d571944SMatt Jacob * actually do anything because we're waiting for a 25785d571944SMatt Jacob * Change Notify before activating the FC cleanup 25795d571944SMatt Jacob * thread to look at the state of the loop again. 25805d571944SMatt Jacob */ 2581b09b0095SMatt Jacob isp_prt(isp, ISP_LOGINFO, "Loop UP"); 258257c801f5SMatt Jacob break; 2583d6e5500fSMatt Jacob case ISPASYNC_PROMENADE: 25840470d791SMatt Jacob { 2585ab163f5fSMatt Jacob struct cam_path *tmppath; 2586b09b0095SMatt Jacob const char *fmt = "Target %d (Loop 0x%x) Port ID 0x%x " 2587d6e5500fSMatt Jacob "(role %s) %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x"; 2588d6e5500fSMatt Jacob static const char *roles[4] = { 25890470d791SMatt Jacob "(none)", "Target", "Initiator", "Target/Initiator" 259057c801f5SMatt Jacob }; 259102ab3379SMatt Jacob fcparam *fcp = isp->isp_param; 259202ab3379SMatt Jacob int tgt = *((int *) arg); 2593f44257c2SMatt Jacob int is_tgt_mask = (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT); 259402ab3379SMatt Jacob struct lportdb *lp = &fcp->portdb[tgt]; 259502ab3379SMatt Jacob 2596b09b0095SMatt Jacob isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid, 2597d6e5500fSMatt Jacob roles[lp->roles & 0x3], 2598d6e5500fSMatt Jacob (lp->valid)? "Arrived" : "Departed", 259902ab3379SMatt Jacob (u_int32_t) (lp->port_wwn >> 32), 260002ab3379SMatt Jacob (u_int32_t) (lp->port_wwn & 0xffffffffLL), 260102ab3379SMatt Jacob (u_int32_t) (lp->node_wwn >> 32), 260202ab3379SMatt Jacob (u_int32_t) (lp->node_wwn & 0xffffffffLL)); 2603ab163f5fSMatt Jacob 260445c9a36aSMatt Jacob ISPLOCK_2_CAMLOCK(isp); 2605ab163f5fSMatt Jacob if (xpt_create_path(&tmppath, NULL, cam_sim_path(isp->isp_sim), 2606ab163f5fSMatt Jacob (target_id_t)tgt, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 260745c9a36aSMatt Jacob CAMLOCK_2_ISPLOCK(isp); 2608ab163f5fSMatt Jacob break; 2609ab163f5fSMatt Jacob } 2610f44257c2SMatt Jacob /* 2611f44257c2SMatt Jacob * Policy: only announce targets. 2612f44257c2SMatt Jacob */ 2613f44257c2SMatt Jacob if (lp->roles & is_tgt_mask) { 2614f44257c2SMatt Jacob if (lp->valid) { 2615ab163f5fSMatt Jacob xpt_async(AC_FOUND_DEVICE, tmppath, NULL); 2616ab163f5fSMatt Jacob } else { 2617ab163f5fSMatt Jacob xpt_async(AC_LOST_DEVICE, tmppath, NULL); 2618ab163f5fSMatt Jacob } 2619f44257c2SMatt Jacob } 2620ab163f5fSMatt Jacob xpt_free_path(tmppath); 2621f44257c2SMatt Jacob CAMLOCK_2_ISPLOCK(isp); 26224394c92fSMatt Jacob break; 26234394c92fSMatt Jacob } 262457c801f5SMatt Jacob case ISPASYNC_CHANGE_NOTIFY: 2625f44257c2SMatt Jacob if (arg == ISPASYNC_CHANGE_PDB) { 26264b9d588eSMatt Jacob isp_prt(isp, ISP_LOGINFO, 2627f44257c2SMatt Jacob "Port Database Changed"); 2628f44257c2SMatt Jacob } else if (arg == ISPASYNC_CHANGE_SNS) { 26294b9d588eSMatt Jacob isp_prt(isp, ISP_LOGINFO, 26304b9d588eSMatt Jacob "Name Server Database Changed"); 26314b9d588eSMatt Jacob } 26325d571944SMatt Jacob cv_signal(&isp->isp_osinfo.kthread_cv); 263357c801f5SMatt Jacob break; 263402ab3379SMatt Jacob case ISPASYNC_FABRIC_DEV: 263502ab3379SMatt Jacob { 263670d2ccceSMatt Jacob int target, lrange; 263770d2ccceSMatt Jacob struct lportdb *lp = NULL; 263840cfc8feSMatt Jacob char *pt; 263940cfc8feSMatt Jacob sns_ganrsp_t *resp = (sns_ganrsp_t *) arg; 264002ab3379SMatt Jacob u_int32_t portid; 264140cfc8feSMatt Jacob u_int64_t wwpn, wwnn; 264202ab3379SMatt Jacob fcparam *fcp = isp->isp_param; 264302ab3379SMatt Jacob 264402ab3379SMatt Jacob portid = 264502ab3379SMatt Jacob (((u_int32_t) resp->snscb_port_id[0]) << 16) | 264602ab3379SMatt Jacob (((u_int32_t) resp->snscb_port_id[1]) << 8) | 264702ab3379SMatt Jacob (((u_int32_t) resp->snscb_port_id[2])); 264840cfc8feSMatt Jacob 264940cfc8feSMatt Jacob wwpn = 265002ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[0]) << 56) | 265102ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[1]) << 48) | 265202ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[2]) << 40) | 265302ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[3]) << 32) | 265402ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[4]) << 24) | 265502ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[5]) << 16) | 265602ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[6]) << 8) | 265702ab3379SMatt Jacob (((u_int64_t)resp->snscb_portname[7])); 265840cfc8feSMatt Jacob 265940cfc8feSMatt Jacob wwnn = 266040cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[0]) << 56) | 266140cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[1]) << 48) | 266240cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[2]) << 40) | 266340cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[3]) << 32) | 266440cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[4]) << 24) | 266540cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[5]) << 16) | 266640cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[6]) << 8) | 266740cfc8feSMatt Jacob (((u_int64_t)resp->snscb_nodename[7])); 266840cfc8feSMatt Jacob if (portid == 0 || wwpn == 0) { 266902ab3379SMatt Jacob break; 267002ab3379SMatt Jacob } 267140cfc8feSMatt Jacob 267240cfc8feSMatt Jacob switch (resp->snscb_port_type) { 267340cfc8feSMatt Jacob case 1: 267440cfc8feSMatt Jacob pt = " N_Port"; 267540cfc8feSMatt Jacob break; 267640cfc8feSMatt Jacob case 2: 267740cfc8feSMatt Jacob pt = " NL_Port"; 267840cfc8feSMatt Jacob break; 267940cfc8feSMatt Jacob case 3: 268040cfc8feSMatt Jacob pt = "F/NL_Port"; 268140cfc8feSMatt Jacob break; 268240cfc8feSMatt Jacob case 0x7f: 268340cfc8feSMatt Jacob pt = " Nx_Port"; 268440cfc8feSMatt Jacob break; 268540cfc8feSMatt Jacob case 0x81: 268640cfc8feSMatt Jacob pt = " F_port"; 268740cfc8feSMatt Jacob break; 268840cfc8feSMatt Jacob case 0x82: 268940cfc8feSMatt Jacob pt = " FL_Port"; 269040cfc8feSMatt Jacob break; 269140cfc8feSMatt Jacob case 0x84: 269240cfc8feSMatt Jacob pt = " E_port"; 269340cfc8feSMatt Jacob break; 269440cfc8feSMatt Jacob default: 269540cfc8feSMatt Jacob pt = "?"; 269640cfc8feSMatt Jacob break; 269740cfc8feSMatt Jacob } 2698b09b0095SMatt Jacob isp_prt(isp, ISP_LOGINFO, 2699b09b0095SMatt Jacob "%s @ 0x%x, Node 0x%08x%08x Port %08x%08x", 2700b09b0095SMatt Jacob pt, portid, ((u_int32_t) (wwnn >> 32)), ((u_int32_t) wwnn), 270140cfc8feSMatt Jacob ((u_int32_t) (wwpn >> 32)), ((u_int32_t) wwpn)); 270270d2ccceSMatt Jacob /* 270370d2ccceSMatt Jacob * We're only interested in SCSI_FCP types (for now) 270470d2ccceSMatt Jacob */ 270570d2ccceSMatt Jacob if ((resp->snscb_fc4_types[2] & 1) == 0) { 270602ab3379SMatt Jacob break; 270702ab3379SMatt Jacob } 270870d2ccceSMatt Jacob if (fcp->isp_topo != TOPO_F_PORT) 270970d2ccceSMatt Jacob lrange = FC_SNS_ID+1; 271070d2ccceSMatt Jacob else 271170d2ccceSMatt Jacob lrange = 0; 271270d2ccceSMatt Jacob /* 271370d2ccceSMatt Jacob * Is it already in our list? 271470d2ccceSMatt Jacob */ 271570d2ccceSMatt Jacob for (target = lrange; target < MAX_FC_TARG; target++) { 271670d2ccceSMatt Jacob if (target >= FL_PORT_ID && target <= FC_SNS_ID) { 271770d2ccceSMatt Jacob continue; 271870d2ccceSMatt Jacob } 271970d2ccceSMatt Jacob lp = &fcp->portdb[target]; 272070d2ccceSMatt Jacob if (lp->port_wwn == wwpn && lp->node_wwn == wwnn) { 272170d2ccceSMatt Jacob lp->fabric_dev = 1; 272270d2ccceSMatt Jacob break; 272370d2ccceSMatt Jacob } 272470d2ccceSMatt Jacob } 272502ab3379SMatt Jacob if (target < MAX_FC_TARG) { 272602ab3379SMatt Jacob break; 272702ab3379SMatt Jacob } 272870d2ccceSMatt Jacob for (target = lrange; target < MAX_FC_TARG; target++) { 272970d2ccceSMatt Jacob if (target >= FL_PORT_ID && target <= FC_SNS_ID) { 273070d2ccceSMatt Jacob continue; 273170d2ccceSMatt Jacob } 273202ab3379SMatt Jacob lp = &fcp->portdb[target]; 273370d2ccceSMatt Jacob if (lp->port_wwn == 0) { 273402ab3379SMatt Jacob break; 273502ab3379SMatt Jacob } 273670d2ccceSMatt Jacob } 273702ab3379SMatt Jacob if (target == MAX_FC_TARG) { 2738bfbab170SMatt Jacob isp_prt(isp, ISP_LOGWARN, 2739bfbab170SMatt Jacob "no more space for fabric devices"); 274002ab3379SMatt Jacob break; 274102ab3379SMatt Jacob } 274240cfc8feSMatt Jacob lp->node_wwn = wwnn; 274340cfc8feSMatt Jacob lp->port_wwn = wwpn; 274402ab3379SMatt Jacob lp->portid = portid; 274570d2ccceSMatt Jacob lp->fabric_dev = 1; 274602ab3379SMatt Jacob break; 274702ab3379SMatt Jacob } 2748d81ba9d5SMatt Jacob #ifdef ISP_TARGET_MODE 2749d81ba9d5SMatt Jacob case ISPASYNC_TARGET_MESSAGE: 2750d81ba9d5SMatt Jacob { 2751d81ba9d5SMatt Jacob tmd_msg_t *mp = arg; 2752b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2753b09b0095SMatt Jacob "bus %d iid %d tgt %d lun %d ttype %x tval %x msg[0]=%x", 2754b09b0095SMatt Jacob mp->nt_bus, (int) mp->nt_iid, (int) mp->nt_tgt, 2755b09b0095SMatt Jacob (int) mp->nt_lun, mp->nt_tagtype, mp->nt_tagval, 2756b09b0095SMatt Jacob mp->nt_msg[0]); 2757d81ba9d5SMatt Jacob break; 2758d81ba9d5SMatt Jacob } 2759d81ba9d5SMatt Jacob case ISPASYNC_TARGET_EVENT: 2760d81ba9d5SMatt Jacob { 2761d81ba9d5SMatt Jacob tmd_event_t *ep = arg; 2762b09b0095SMatt Jacob isp_prt(isp, ISP_LOGDEBUG2, 2763b09b0095SMatt Jacob "bus %d event code 0x%x", ep->ev_bus, ep->ev_event); 2764d81ba9d5SMatt Jacob break; 2765d81ba9d5SMatt Jacob } 2766d81ba9d5SMatt Jacob case ISPASYNC_TARGET_ACTION: 2767d81ba9d5SMatt Jacob switch (((isphdr_t *)arg)->rqs_entry_type) { 2768cbf57b47SMatt Jacob default: 2769bfbab170SMatt Jacob isp_prt(isp, ISP_LOGWARN, 2770bfbab170SMatt Jacob "event 0x%x for unhandled target action", 2771bfbab170SMatt Jacob ((isphdr_t *)arg)->rqs_entry_type); 2772d81ba9d5SMatt Jacob break; 2773d81ba9d5SMatt Jacob case RQSTYPE_ATIO: 2774d81ba9d5SMatt Jacob rv = isp_handle_platform_atio(isp, (at_entry_t *) arg); 2775d81ba9d5SMatt Jacob break; 2776d81ba9d5SMatt Jacob case RQSTYPE_ATIO2: 2777d81ba9d5SMatt Jacob rv = isp_handle_platform_atio2(isp, (at2_entry_t *)arg); 2778d81ba9d5SMatt Jacob break; 2779d81ba9d5SMatt Jacob case RQSTYPE_CTIO2: 2780d81ba9d5SMatt Jacob case RQSTYPE_CTIO: 2781d81ba9d5SMatt Jacob rv = isp_handle_platform_ctio(isp, arg); 2782d81ba9d5SMatt Jacob break; 2783d81ba9d5SMatt Jacob case RQSTYPE_ENABLE_LUN: 2784d81ba9d5SMatt Jacob case RQSTYPE_MODIFY_LUN: 2785d81ba9d5SMatt Jacob isp_cv_signal_rqe(isp, ((lun_entry_t *)arg)->le_status); 2786d81ba9d5SMatt Jacob break; 2787d81ba9d5SMatt Jacob } 2788d81ba9d5SMatt Jacob break; 2789d81ba9d5SMatt Jacob #endif 2790ab163f5fSMatt Jacob case ISPASYNC_FW_CRASH: 2791ab163f5fSMatt Jacob { 2792ab163f5fSMatt Jacob u_int16_t mbox1, mbox6; 2793ab163f5fSMatt Jacob mbox1 = ISP_READ(isp, OUTMAILBOX1); 2794ab163f5fSMatt Jacob if (IS_DUALBUS(isp)) { 2795ab163f5fSMatt Jacob mbox6 = ISP_READ(isp, OUTMAILBOX6); 2796ab163f5fSMatt Jacob } else { 2797ab163f5fSMatt Jacob mbox6 = 0; 2798ab163f5fSMatt Jacob } 2799ab163f5fSMatt Jacob isp_prt(isp, ISP_LOGERR, 2800ab163f5fSMatt Jacob "Internal Firmware on bus %d Error @ RISC Address 0x%x", 2801ab163f5fSMatt Jacob mbox6, mbox1); 2802ab163f5fSMatt Jacob isp_reinit(isp); 2803ab163f5fSMatt Jacob break; 2804ab163f5fSMatt Jacob } 2805d81ba9d5SMatt Jacob default: 2806b09b0095SMatt Jacob isp_prt(isp, ISP_LOGERR, "unknown isp_async event %d", cmd); 280702ab3379SMatt Jacob rv = -1; 2808cbf57b47SMatt Jacob break; 2809cbf57b47SMatt Jacob } 2810cbf57b47SMatt Jacob return (rv); 2811cbf57b47SMatt Jacob } 2812cbf57b47SMatt Jacob 281392718a7fSMatt Jacob 281492718a7fSMatt Jacob /* 281592718a7fSMatt Jacob * Locks are held before coming here. 281692718a7fSMatt Jacob */ 281792718a7fSMatt Jacob void 281892718a7fSMatt Jacob isp_uninit(struct ispsoftc *isp) 281992718a7fSMatt Jacob { 2820ea6f23cdSMatt Jacob ISP_WRITE(isp, HCCR, HCCR_CMD_RESET); 282192718a7fSMatt Jacob DISABLE_INTS(isp); 282292718a7fSMatt Jacob } 2823b09b0095SMatt Jacob 2824b09b0095SMatt Jacob void 2825b09b0095SMatt Jacob isp_prt(struct ispsoftc *isp, int level, const char *fmt, ...) 2826b09b0095SMatt Jacob { 2827b09b0095SMatt Jacob va_list ap; 2828b09b0095SMatt Jacob if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) { 2829b09b0095SMatt Jacob return; 2830b09b0095SMatt Jacob } 28313c75bb14SMatt Jacob printf("%s: ", device_get_nameunit(isp->isp_dev)); 2832b09b0095SMatt Jacob va_start(ap, fmt); 2833b09b0095SMatt Jacob vprintf(fmt, ap); 2834b09b0095SMatt Jacob va_end(ap); 2835b09b0095SMatt Jacob printf("\n"); 2836b09b0095SMatt Jacob } 2837