isp_freebsd.c (81791) | isp_freebsd.c (82689) |
---|---|
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.c 81791 2001-08-16 17:25:41Z mjacob $ */ | 1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.c 82689 2001-08-31 21:39:04Z mjacob $ */ |
2/* 3 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters. 4 * 5 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 375 unchanged lines hidden (view full) --- 385} 386 387static __inline tstate_t * 388get_lun_statep(struct ispsoftc *isp, int bus, lun_id_t lun) 389{ 390 tstate_t *tptr; 391 392 if (lun == CAM_LUN_WILDCARD) { | 2/* 3 * Platform (FreeBSD) dependent common attachment code for Qlogic adapters. 4 * 5 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 375 unchanged lines hidden (view full) --- 385} 386 387static __inline tstate_t * 388get_lun_statep(struct ispsoftc *isp, int bus, lun_id_t lun) 389{ 390 tstate_t *tptr; 391 392 if (lun == CAM_LUN_WILDCARD) { |
393 tptr = &isp->isp_osinfo.tsdflt[bus]; 394 tptr->hold++; 395 return (tptr); | 393 if (isp->isp_osinfo.tmflags & TM_WILDCARD_ENABLED) { 394 tptr = &isp->isp_osinfo.tsdflt[bus]; 395 tptr->hold++; 396 return (tptr); 397 } else { 398 return (NULL); 399 } |
396 } else { 397 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)]; 398 } | 400 } else { 401 tptr = isp->isp_osinfo.lun_hash[LUN_HASH_FUNC(isp, bus, lun)]; 402 } |
399 if (tptr == NULL) { 400 return (NULL); 401 } | |
402 403 do { 404 if (tptr->lun == lun && tptr->bus == bus) { 405 tptr->hold++; 406 return (tptr); 407 } 408 } while ((tptr = tptr->next) != NULL); 409 return (tptr); --- 131 unchanged lines hidden (view full) --- 541 */ 542static void 543isp_en_lun(struct ispsoftc *isp, union ccb *ccb) 544{ 545 const char lfmt[] = "Lun now %sabled for target mode on channel %d"; 546 struct ccb_en_lun *cel = &ccb->cel; 547 tstate_t *tptr; 548 u_int16_t rstat; | 403 404 do { 405 if (tptr->lun == lun && tptr->bus == bus) { 406 tptr->hold++; 407 return (tptr); 408 } 409 } while ((tptr = tptr->next) != NULL); 410 return (tptr); --- 131 unchanged lines hidden (view full) --- 542 */ 543static void 544isp_en_lun(struct ispsoftc *isp, union ccb *ccb) 545{ 546 const char lfmt[] = "Lun now %sabled for target mode on channel %d"; 547 struct ccb_en_lun *cel = &ccb->cel; 548 tstate_t *tptr; 549 u_int16_t rstat; |
549 int bus, cmd, frozen = 0; | 550 int bus, cmd, av, wildcard, frozen = 0; |
550 lun_id_t lun; 551 target_id_t tgt; 552 553 554 bus = XS_CHANNEL(ccb) & 0x1; 555 tgt = ccb->ccb_h.target_id; 556 lun = ccb->ccb_h.target_lun; 557 --- 67 unchanged lines hidden (view full) --- 625 ISPLOCK_2_CAMLOCK(isp); 626 xpt_release_simq(isp->isp_sim, 1); 627 CAMLOCK_2_ISPLOCK(isp); 628 } 629 return; 630 } 631 } 632 | 551 lun_id_t lun; 552 target_id_t tgt; 553 554 555 bus = XS_CHANNEL(ccb) & 0x1; 556 tgt = ccb->ccb_h.target_id; 557 lun = ccb->ccb_h.target_lun; 558 --- 67 unchanged lines hidden (view full) --- 626 ISPLOCK_2_CAMLOCK(isp); 627 xpt_release_simq(isp->isp_sim, 1); 628 CAMLOCK_2_ISPLOCK(isp); 629 } 630 return; 631 } 632 } 633 |
634 if (lun == CAM_LUN_WILDCARD && tgt == CAM_TARGET_WILDCARD) { 635 wildcard = 1; 636 } else { 637 wildcard = 0; 638 } |
|
633 634 /* 635 * Next check to see whether this is a target/lun wildcard action. | 639 640 /* 641 * Next check to see whether this is a target/lun wildcard action. |
636 * 637 * If so, we enable/disable target mode but don't do any lun enabling. | 642 * If so, we know that we can accept commands and send them 643 * upstream. Otherwise, we have to handle them locally. |
638 */ | 644 */ |
639 if (lun == CAM_LUN_WILDCARD && tgt == CAM_TARGET_WILDCARD) { 640 int av = bus << 31; | 645 646 if (wildcard) { |
641 tptr = &isp->isp_osinfo.tsdflt[bus]; 642 if (cel->enable) { | 647 tptr = &isp->isp_osinfo.tsdflt[bus]; 648 if (cel->enable) { |
643 if (isp->isp_osinfo.tmflags & (1 << bus)) { | 649 if (isp->isp_osinfo.tmflags & TM_WILDCARD_ENABLED) { |
644 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; | 650 ccb->ccb_h.status = CAM_LUN_ALRDY_ENA; |
645 if (frozen) { 646 ISPLOCK_2_CAMLOCK(isp); 647 xpt_release_simq(isp->isp_sim, 1); 648 CAMLOCK_2_ISPLOCK(isp); 649 } | |
650 return; 651 } 652 ccb->ccb_h.status = 653 xpt_create_path(&tptr->owner, NULL, 654 xpt_path_path_id(ccb->ccb_h.path), 655 xpt_path_target_id(ccb->ccb_h.path), 656 xpt_path_lun_id(ccb->ccb_h.path)); 657 if (ccb->ccb_h.status != CAM_REQ_CMP) { 658 if (frozen) { 659 ISPLOCK_2_CAMLOCK(isp); 660 xpt_release_simq(isp->isp_sim, 1); 661 CAMLOCK_2_ISPLOCK(isp); 662 } 663 return; 664 } 665 SLIST_INIT(&tptr->atios); 666 SLIST_INIT(&tptr->inots); | 651 return; 652 } 653 ccb->ccb_h.status = 654 xpt_create_path(&tptr->owner, NULL, 655 xpt_path_path_id(ccb->ccb_h.path), 656 xpt_path_target_id(ccb->ccb_h.path), 657 xpt_path_lun_id(ccb->ccb_h.path)); 658 if (ccb->ccb_h.status != CAM_REQ_CMP) { 659 if (frozen) { 660 ISPLOCK_2_CAMLOCK(isp); 661 xpt_release_simq(isp->isp_sim, 1); 662 CAMLOCK_2_ISPLOCK(isp); 663 } 664 return; 665 } 666 SLIST_INIT(&tptr->atios); 667 SLIST_INIT(&tptr->inots); |
667 av |= ENABLE_TARGET_FLAG; 668 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 669 if (av) { 670 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 671 xpt_free_path(tptr->owner); 672 if (frozen) { 673 ISPLOCK_2_CAMLOCK(isp); 674 xpt_release_simq(isp->isp_sim, 1); 675 CAMLOCK_2_ISPLOCK(isp); 676 } 677 return; 678 } 679 isp->isp_osinfo.tmflags |= (1 << bus); | 668 isp->isp_osinfo.tmflags |= TM_WILDCARD_ENABLED; |
680 } else { | 669 } else { |
681 if ((isp->isp_osinfo.tmflags & (1 << bus)) == 0) { 682 ccb->ccb_h.status = CAM_LUN_INVALID; 683 if (frozen) { 684 ISPLOCK_2_CAMLOCK(isp); 685 xpt_release_simq(isp->isp_sim, 1); 686 CAMLOCK_2_ISPLOCK(isp); 687 } | 670 if (!(isp->isp_osinfo.tmflags & TM_WILDCARD_ENABLED)) { 671 ccb->ccb_h.status = CAM_REQ_CMP; |
688 return; 689 } | 672 return; 673 } |
690 if (are_any_luns_enabled(isp, bus)) { | 674 if (tptr->hold) { |
691 ccb->ccb_h.status = CAM_SCSI_BUSY; | 675 ccb->ccb_h.status = CAM_SCSI_BUSY; |
692 if (frozen) { 693 ISPLOCK_2_CAMLOCK(isp); 694 xpt_release_simq(isp->isp_sim, 1); 695 CAMLOCK_2_ISPLOCK(isp); 696 } | |
697 return; 698 } | 676 return; 677 } |
699 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 700 if (av) { 701 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 702 if (frozen) { 703 ISPLOCK_2_CAMLOCK(isp); 704 xpt_release_simq(isp->isp_sim, 1); 705 CAMLOCK_2_ISPLOCK(isp); 706 } 707 return; | 678 xpt_free_path(tptr->owner); 679 isp->isp_osinfo.tmflags &= ~TM_WILDCARD_ENABLED; 680 } 681 } 682 683 /* 684 * Now check to see whether this bus needs to be 685 * enabled/disabled with respect to target mode. 686 */ 687 688 av = bus << 31; 689 if (cel->enable && (isp->isp_osinfo.tmflags & (1 << bus)) == 0) { 690 av |= ENABLE_TARGET_FLAG; 691 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 692 if (av) { 693 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 694 ISPLOCK_2_CAMLOCK(isp); 695 xpt_release_simq(isp->isp_sim, 1); 696 CAMLOCK_2_ISPLOCK(isp); 697 if (wildcard) { 698 isp->isp_osinfo.tmflags &= ~TM_WILDCARD_ENABLED; 699 xpt_free_path(tptr->owner); |
708 } | 700 } |
709 isp->isp_osinfo.tmflags &= ~(1 << bus); 710 ccb->ccb_h.status = CAM_REQ_CMP; | 701 return; |
711 } | 702 } |
703 isp_prt(isp, ISP_LOGINFO, 704 "Target Mode enabled on channel %d", bus); 705 } else if (cel->enable == 0 && (isp->isp_osinfo.tmflags & (1 << bus)) && 706 wildcard) { 707 if (are_any_luns_enabled(isp, bus)) { 708 ccb->ccb_h.status = CAM_SCSI_BUSY; 709 if (frozen) { 710 ISPLOCK_2_CAMLOCK(isp); 711 xpt_release_simq(isp->isp_sim, 1); 712 CAMLOCK_2_ISPLOCK(isp); 713 } 714 return; 715 } 716 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 717 if (av) { 718 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 719 if (frozen) { 720 ISPLOCK_2_CAMLOCK(isp); 721 xpt_release_simq(isp->isp_sim, 1); 722 CAMLOCK_2_ISPLOCK(isp); 723 } 724 return; 725 } 726 isp->isp_osinfo.tmflags &= ~(1 << bus); 727 ccb->ccb_h.status = CAM_REQ_CMP; |
|
712 xpt_print_path(ccb->ccb_h.path); | 728 xpt_print_path(ccb->ccb_h.path); |
713 isp_prt(isp, ISP_LOGINFO, "Target Mode %sabled on channel %d", 714 (cel->enable) ? "en" : "dis", bus); | 729 isp_prt(isp, ISP_LOGINFO, 730 "Target Mode disabled on channel %d", bus); 731 } 732 733 if (wildcard) { |
715 if (frozen) { 716 ISPLOCK_2_CAMLOCK(isp); 717 xpt_release_simq(isp->isp_sim, 1); 718 CAMLOCK_2_ISPLOCK(isp); 719 } 720 return; 721 } 722 --- 122 unchanged lines hidden (view full) --- 845 } 846 rstat = isp->isp_osinfo.rstatus; 847 if (rstat != LUN_OK) { 848 xpt_print_path(ccb->ccb_h.path); 849 isp_prt(isp, ISP_LOGWARN, 850 "DISABLE LUN returned 0x%x", rstat); 851 goto out; 852 } | 734 if (frozen) { 735 ISPLOCK_2_CAMLOCK(isp); 736 xpt_release_simq(isp->isp_sim, 1); 737 CAMLOCK_2_ISPLOCK(isp); 738 } 739 return; 740 } 741 --- 122 unchanged lines hidden (view full) --- 864 } 865 rstat = isp->isp_osinfo.rstatus; 866 if (rstat != LUN_OK) { 867 xpt_print_path(ccb->ccb_h.path); 868 isp_prt(isp, ISP_LOGWARN, 869 "DISABLE LUN returned 0x%x", rstat); 870 goto out; 871 } |
872 if (are_any_luns_enabled(isp, bus) == 0) { 873 av = isp_control(isp, ISPCTL_TOGGLE_TMODE, &av); 874 if (av) { 875 isp_prt(isp, ISP_LOGWARN, 876 "disable target mode on channel %d failed", 877 bus); 878 goto out; 879 } 880 isp->isp_osinfo.tmflags &= ~(1 << bus); 881 xpt_print_path(ccb->ccb_h.path); 882 isp_prt(isp, ISP_LOGINFO, 883 "Target Mode disabled on channel %d", bus); 884 } |
|
853 } | 885 } |
886 |
|
854out: 855 isp_vsema_rqe(isp); 856 857 if (rstat != LUN_OK) { 858 xpt_print_path(ccb->ccb_h.path); 859 isp_prt(isp, ISP_LOGWARN, 860 "lun %sable failed", (cel->enable) ? "en" : "dis"); 861 ccb->ccb_h.status = CAM_REQ_CMP_ERR; --- 704 unchanged lines hidden (view full) --- 1566 break; 1567 } 1568} 1569 1570static void 1571isp_poll(struct cam_sim *sim) 1572{ 1573 struct ispsoftc *isp = cam_sim_softc(sim); | 887out: 888 isp_vsema_rqe(isp); 889 890 if (rstat != LUN_OK) { 891 xpt_print_path(ccb->ccb_h.path); 892 isp_prt(isp, ISP_LOGWARN, 893 "lun %sable failed", (cel->enable) ? "en" : "dis"); 894 ccb->ccb_h.status = CAM_REQ_CMP_ERR; --- 704 unchanged lines hidden (view full) --- 1599 break; 1600 } 1601} 1602 1603static void 1604isp_poll(struct cam_sim *sim) 1605{ 1606 struct ispsoftc *isp = cam_sim_softc(sim); |
1607 u_int16_t isr, sema, mbox; 1608 |
|
1574 ISP_LOCK(isp); | 1609 ISP_LOCK(isp); |
1575 (void) isp_intr(isp); | 1610 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) { 1611 isp_intr(isp, isr, sema, mbox); 1612 } |
1576 ISP_UNLOCK(isp); 1577} 1578 1579#if 0 1580static void 1581isp_relsim(void *arg) 1582{ 1583 struct ispsoftc *isp = arg; --- 20 unchanged lines hidden (view full) --- 1604 /* 1605 * We've decided this command is dead. Make sure we're not trying 1606 * to kill a command that's already dead by getting it's handle and 1607 * and seeing whether it's still alive. 1608 */ 1609 ISP_LOCK(isp); 1610 handle = isp_find_handle(isp, xs); 1611 if (handle) { | 1613 ISP_UNLOCK(isp); 1614} 1615 1616#if 0 1617static void 1618isp_relsim(void *arg) 1619{ 1620 struct ispsoftc *isp = arg; --- 20 unchanged lines hidden (view full) --- 1641 /* 1642 * We've decided this command is dead. Make sure we're not trying 1643 * to kill a command that's already dead by getting it's handle and 1644 * and seeing whether it's still alive. 1645 */ 1646 ISP_LOCK(isp); 1647 handle = isp_find_handle(isp, xs); 1648 if (handle) { |
1612 u_int16_t r; | 1649 u_int16_t isr, sema, mbox; |
1613 | 1650 |
1651 |
|
1614 if (XS_CMD_DONE_P(xs)) { 1615 isp_prt(isp, ISP_LOGDEBUG1, 1616 "watchdog found done cmd (handle 0x%x)", handle); 1617 ISP_UNLOCK(isp); 1618 return; 1619 } 1620 1621 if (XS_CMD_WDOG_P(xs)) { 1622 isp_prt(isp, ISP_LOGDEBUG2, 1623 "recursive watchdog (handle 0x%x)", handle); 1624 ISP_UNLOCK(isp); 1625 return; 1626 } 1627 1628 XS_CMD_S_WDOG(xs); | 1652 if (XS_CMD_DONE_P(xs)) { 1653 isp_prt(isp, ISP_LOGDEBUG1, 1654 "watchdog found done cmd (handle 0x%x)", handle); 1655 ISP_UNLOCK(isp); 1656 return; 1657 } 1658 1659 if (XS_CMD_WDOG_P(xs)) { 1660 isp_prt(isp, ISP_LOGDEBUG2, 1661 "recursive watchdog (handle 0x%x)", handle); 1662 ISP_UNLOCK(isp); 1663 return; 1664 } 1665 1666 XS_CMD_S_WDOG(xs); |
1629 1630 r = ISP_READ(isp, BIU_ISR); 1631 1632 if (INT_PENDING(isp, r) && isp_intr(isp) && XS_CMD_DONE_P(xs)) { | 1667 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) { 1668 isp_intr(isp, isr, sema, mbox); 1669 } 1670 if (XS_CMD_DONE_P(xs)) { |
1633 isp_prt(isp, ISP_LOGDEBUG2, | 1671 isp_prt(isp, ISP_LOGDEBUG2, |
1634 "watchdog cleanup (%x, %x)", handle, r); | 1672 "watchdog cleanup for handle 0x%x", handle); |
1635 xpt_done((union ccb *) xs); 1636 } else if (XS_CMD_GRACE_P(xs)) { 1637 /* 1638 * Make sure the command is *really* dead before we 1639 * release the handle (and DMA resources) for reuse. 1640 */ 1641 (void) isp_control(isp, ISPCTL_ABORT_CMD, arg); 1642 1643 /* 1644 * After this point, the comamnd is really dead. 1645 */ 1646 if (XS_XFRLEN(xs)) { 1647 ISP_DMAFREE(isp, xs, handle); 1648 } 1649 isp_destroy_handle(isp, handle); 1650 xpt_print_path(xs->ccb_h.path); 1651 isp_prt(isp, ISP_LOGWARN, | 1673 xpt_done((union ccb *) xs); 1674 } else if (XS_CMD_GRACE_P(xs)) { 1675 /* 1676 * Make sure the command is *really* dead before we 1677 * release the handle (and DMA resources) for reuse. 1678 */ 1679 (void) isp_control(isp, ISPCTL_ABORT_CMD, arg); 1680 1681 /* 1682 * After this point, the comamnd is really dead. 1683 */ 1684 if (XS_XFRLEN(xs)) { 1685 ISP_DMAFREE(isp, xs, handle); 1686 } 1687 isp_destroy_handle(isp, handle); 1688 xpt_print_path(xs->ccb_h.path); 1689 isp_prt(isp, ISP_LOGWARN, |
1652 "watchdog timeout (%x, %x)", handle, r); | 1690 "watchdog timeout for handle %x", handle); |
1653 XS_SETERR(xs, CAM_CMD_TIMEOUT); 1654 XS_CMD_C_WDOG(xs); 1655 isp_done(xs); 1656 } else { 1657 u_int16_t iptr, optr; 1658 ispreq_t *mp; 1659 1660 XS_CMD_C_WDOG(xs); --- 1177 unchanged lines hidden --- | 1691 XS_SETERR(xs, CAM_CMD_TIMEOUT); 1692 XS_CMD_C_WDOG(xs); 1693 isp_done(xs); 1694 } else { 1695 u_int16_t iptr, optr; 1696 ispreq_t *mp; 1697 1698 XS_CMD_C_WDOG(xs); --- 1177 unchanged lines hidden --- |