10042 }
10043
10044 static int
10045 mptsas_quiesce_bus(mptsas_t *mpt)
10046 {
10047 mptsas_target_t *ptgt = NULL;
10048
10049 NDBG28(("mptsas_quiesce_bus"));
10050 mutex_enter(&mpt->m_mutex);
10051
10052 /* Set all the throttles to zero */
10053 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10054 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10055 mptsas_set_throttle(mpt, ptgt, HOLD_THROTTLE);
10056 }
10057
10058 /* If there are any outstanding commands in the queue */
10059 if (mpt->m_ncmds) {
10060 mpt->m_softstate |= MPTSAS_SS_DRAINING;
10061 mpt->m_quiesce_timeid = timeout(mptsas_ncmds_checkdrain,
10062 mpt, (MPTSAS_QUIESCE_TIMEOUT * drv_usectohz(1000000)));
10063 if (cv_wait_sig(&mpt->m_cv, &mpt->m_mutex) == 0) {
10064 /*
10065 * Quiesce has been interrupted
10066 */
10067 mpt->m_softstate &= ~MPTSAS_SS_DRAINING;
10068 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10069 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10070 mptsas_set_throttle(mpt, ptgt, MAX_THROTTLE);
10071 }
10072 mptsas_restart_hba(mpt);
10073 if (mpt->m_quiesce_timeid != 0) {
10074 timeout_id_t tid = mpt->m_quiesce_timeid;
10075 mpt->m_quiesce_timeid = 0;
10076 mutex_exit(&mpt->m_mutex);
10077 (void) untimeout(tid);
10078 return (-1);
10079 }
10080 mutex_exit(&mpt->m_mutex);
10081 return (-1);
10082 } else {
10117 mptsas_t *mpt = arg;
10118 mptsas_target_t *ptgt = NULL;
10119
10120 mutex_enter(&mpt->m_mutex);
10121 if (mpt->m_softstate & MPTSAS_SS_DRAINING) {
10122 mpt->m_quiesce_timeid = 0;
10123 if (mpt->m_ncmds == 0) {
10124 /* Command queue has been drained */
10125 cv_signal(&mpt->m_cv);
10126 } else {
10127 /*
10128 * The throttle may have been reset because
10129 * of a SCSI bus reset
10130 */
10131 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10132 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10133 mptsas_set_throttle(mpt, ptgt, HOLD_THROTTLE);
10134 }
10135
10136 mpt->m_quiesce_timeid = timeout(mptsas_ncmds_checkdrain,
10137 mpt, (MPTSAS_QUIESCE_TIMEOUT *
10138 drv_usectohz(1000000)));
10139 }
10140 }
10141 mutex_exit(&mpt->m_mutex);
10142 }
10143
10144 /*ARGSUSED*/
10145 static void
10146 mptsas_dump_cmd(mptsas_t *mpt, mptsas_cmd_t *cmd)
10147 {
10148 int i;
10149 uint8_t *cp = (uchar_t *)cmd->cmd_pkt->pkt_cdbp;
10150 char buf[128];
10151
10152 buf[0] = '\0';
10153 NDBG25(("?Cmd (0x%p) dump for Target %d Lun %d:\n", (void *)cmd,
10154 Tgt(cmd), Lun(cmd)));
10155 (void) sprintf(&buf[0], "\tcdb=[");
10156 for (i = 0; i < (int)cmd->cmd_cdblen; i++) {
10157 (void) sprintf(&buf[strlen(buf)], " 0x%x", *cp++);
10158 }
13614 /* According to SAT2, the first descriptor is logic unit name */
13615 dblk = &inq83[4];
13616 if ((dblk[1] & 0x30) != 0) {
13617 mptsas_log(mpt, CE_WARN, "!Descriptor is not lun associated.");
13618 goto out;
13619 }
13620 pwwn = (uint64_t *)(void *)(&dblk[4]);
13621 if ((dblk[4] & 0xf0) == 0x50) {
13622 sata_guid = BE_64(*pwwn);
13623 goto out;
13624 } else if (dblk[4] == 'A') {
13625 NDBG20(("SATA drive has no NAA format GUID."));
13626 goto out;
13627 } else {
13628 /* The data is not ready, wait and retry */
13629 inq83_retry--;
13630 if (inq83_retry <= 0) {
13631 goto out;
13632 }
13633 NDBG20(("The GUID is not ready, retry..."));
13634 delay(1 * drv_usectohz(1000000));
13635 goto inq83_retry;
13636 }
13637 out:
13638 kmem_free(inq83, inq83_len);
13639 return (sata_guid);
13640 }
13641
13642 static int
13643 mptsas_inquiry(mptsas_t *mpt, mptsas_target_t *ptgt, int lun, uchar_t page,
13644 unsigned char *buf, int len, int *reallen, uchar_t evpd)
13645 {
13646 uchar_t cdb[CDB_GROUP0];
13647 struct scsi_address ap;
13648 struct buf *data_bp = NULL;
13649 int resid = 0;
13650 int ret = DDI_FAILURE;
13651
13652 ASSERT(len <= 0xffff);
13653
13654 ap.a_target = MPTSAS_INVALID_DEVHDL;
14913 if (mpt->m_mpxio_enable == TRUE) {
14914 mptsas_log(mpt, CE_NOTE, "!Target:%x, "
14915 "lun:%x doesn't have a valid GUID, "
14916 "multipathing for this drive is "
14917 "not enabled", target, lun);
14918 }
14919 }
14920
14921 /*
14922 * devid no longer needed
14923 */
14924 ddi_devid_free(devid);
14925 break;
14926 } else if (rval == DDI_NOT_WELL_FORMED) {
14927 /*
14928 * return value of ddi_devid_scsi_encode equal to
14929 * DDI_NOT_WELL_FORMED means DEVID_RETRY, it worth
14930 * to retry inquiry page 0x83 and get GUID.
14931 */
14932 NDBG20(("Not well formed devid, retry..."));
14933 delay(1 * drv_usectohz(1000000));
14934 continue;
14935 } else {
14936 mptsas_log(mpt, CE_WARN, "!Encode devid failed for "
14937 "path target:%x, lun:%x", target, lun);
14938 rval = DDI_FAILURE;
14939 goto create_lun;
14940 }
14941 }
14942
14943 if (i == mptsas_inq83_retry_timeout) {
14944 mptsas_log(mpt, CE_WARN, "!Repeated page83 requests timeout "
14945 "for path target:%x, lun:%x", target, lun);
14946 }
14947
14948 rval = DDI_FAILURE;
14949
14950 create_lun:
14951 if ((guid != NULL) && (mpt->m_mpxio_enable == TRUE)) {
14952 rval = mptsas_create_virt_lun(pdip, sd_inq, guid, lun_dip, &pip,
14953 ptgt, lun);
|
10042 }
10043
10044 static int
10045 mptsas_quiesce_bus(mptsas_t *mpt)
10046 {
10047 mptsas_target_t *ptgt = NULL;
10048
10049 NDBG28(("mptsas_quiesce_bus"));
10050 mutex_enter(&mpt->m_mutex);
10051
10052 /* Set all the throttles to zero */
10053 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10054 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10055 mptsas_set_throttle(mpt, ptgt, HOLD_THROTTLE);
10056 }
10057
10058 /* If there are any outstanding commands in the queue */
10059 if (mpt->m_ncmds) {
10060 mpt->m_softstate |= MPTSAS_SS_DRAINING;
10061 mpt->m_quiesce_timeid = timeout(mptsas_ncmds_checkdrain,
10062 mpt, drv_sectohz(MPTSAS_QUIESCE_TIMEOUT));
10063 if (cv_wait_sig(&mpt->m_cv, &mpt->m_mutex) == 0) {
10064 /*
10065 * Quiesce has been interrupted
10066 */
10067 mpt->m_softstate &= ~MPTSAS_SS_DRAINING;
10068 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10069 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10070 mptsas_set_throttle(mpt, ptgt, MAX_THROTTLE);
10071 }
10072 mptsas_restart_hba(mpt);
10073 if (mpt->m_quiesce_timeid != 0) {
10074 timeout_id_t tid = mpt->m_quiesce_timeid;
10075 mpt->m_quiesce_timeid = 0;
10076 mutex_exit(&mpt->m_mutex);
10077 (void) untimeout(tid);
10078 return (-1);
10079 }
10080 mutex_exit(&mpt->m_mutex);
10081 return (-1);
10082 } else {
10117 mptsas_t *mpt = arg;
10118 mptsas_target_t *ptgt = NULL;
10119
10120 mutex_enter(&mpt->m_mutex);
10121 if (mpt->m_softstate & MPTSAS_SS_DRAINING) {
10122 mpt->m_quiesce_timeid = 0;
10123 if (mpt->m_ncmds == 0) {
10124 /* Command queue has been drained */
10125 cv_signal(&mpt->m_cv);
10126 } else {
10127 /*
10128 * The throttle may have been reset because
10129 * of a SCSI bus reset
10130 */
10131 for (ptgt = refhash_first(mpt->m_targets); ptgt != NULL;
10132 ptgt = refhash_next(mpt->m_targets, ptgt)) {
10133 mptsas_set_throttle(mpt, ptgt, HOLD_THROTTLE);
10134 }
10135
10136 mpt->m_quiesce_timeid = timeout(mptsas_ncmds_checkdrain,
10137 mpt, drv_sectohz(MPTSAS_QUIESCE_TIMEOUT));
10138 }
10139 }
10140 mutex_exit(&mpt->m_mutex);
10141 }
10142
10143 /*ARGSUSED*/
10144 static void
10145 mptsas_dump_cmd(mptsas_t *mpt, mptsas_cmd_t *cmd)
10146 {
10147 int i;
10148 uint8_t *cp = (uchar_t *)cmd->cmd_pkt->pkt_cdbp;
10149 char buf[128];
10150
10151 buf[0] = '\0';
10152 NDBG25(("?Cmd (0x%p) dump for Target %d Lun %d:\n", (void *)cmd,
10153 Tgt(cmd), Lun(cmd)));
10154 (void) sprintf(&buf[0], "\tcdb=[");
10155 for (i = 0; i < (int)cmd->cmd_cdblen; i++) {
10156 (void) sprintf(&buf[strlen(buf)], " 0x%x", *cp++);
10157 }
13613 /* According to SAT2, the first descriptor is logic unit name */
13614 dblk = &inq83[4];
13615 if ((dblk[1] & 0x30) != 0) {
13616 mptsas_log(mpt, CE_WARN, "!Descriptor is not lun associated.");
13617 goto out;
13618 }
13619 pwwn = (uint64_t *)(void *)(&dblk[4]);
13620 if ((dblk[4] & 0xf0) == 0x50) {
13621 sata_guid = BE_64(*pwwn);
13622 goto out;
13623 } else if (dblk[4] == 'A') {
13624 NDBG20(("SATA drive has no NAA format GUID."));
13625 goto out;
13626 } else {
13627 /* The data is not ready, wait and retry */
13628 inq83_retry--;
13629 if (inq83_retry <= 0) {
13630 goto out;
13631 }
13632 NDBG20(("The GUID is not ready, retry..."));
13633 delay(drv_sectohz(1));
13634 goto inq83_retry;
13635 }
13636 out:
13637 kmem_free(inq83, inq83_len);
13638 return (sata_guid);
13639 }
13640
13641 static int
13642 mptsas_inquiry(mptsas_t *mpt, mptsas_target_t *ptgt, int lun, uchar_t page,
13643 unsigned char *buf, int len, int *reallen, uchar_t evpd)
13644 {
13645 uchar_t cdb[CDB_GROUP0];
13646 struct scsi_address ap;
13647 struct buf *data_bp = NULL;
13648 int resid = 0;
13649 int ret = DDI_FAILURE;
13650
13651 ASSERT(len <= 0xffff);
13652
13653 ap.a_target = MPTSAS_INVALID_DEVHDL;
14912 if (mpt->m_mpxio_enable == TRUE) {
14913 mptsas_log(mpt, CE_NOTE, "!Target:%x, "
14914 "lun:%x doesn't have a valid GUID, "
14915 "multipathing for this drive is "
14916 "not enabled", target, lun);
14917 }
14918 }
14919
14920 /*
14921 * devid no longer needed
14922 */
14923 ddi_devid_free(devid);
14924 break;
14925 } else if (rval == DDI_NOT_WELL_FORMED) {
14926 /*
14927 * return value of ddi_devid_scsi_encode equal to
14928 * DDI_NOT_WELL_FORMED means DEVID_RETRY, it worth
14929 * to retry inquiry page 0x83 and get GUID.
14930 */
14931 NDBG20(("Not well formed devid, retry..."));
14932 delay(drv_sectohz(1));
14933 continue;
14934 } else {
14935 mptsas_log(mpt, CE_WARN, "!Encode devid failed for "
14936 "path target:%x, lun:%x", target, lun);
14937 rval = DDI_FAILURE;
14938 goto create_lun;
14939 }
14940 }
14941
14942 if (i == mptsas_inq83_retry_timeout) {
14943 mptsas_log(mpt, CE_WARN, "!Repeated page83 requests timeout "
14944 "for path target:%x, lun:%x", target, lun);
14945 }
14946
14947 rval = DDI_FAILURE;
14948
14949 create_lun:
14950 if ((guid != NULL) && (mpt->m_mpxio_enable == TRUE)) {
14951 rval = mptsas_create_virt_lun(pdip, sd_inq, guid, lun_dip, &pip,
14952 ptgt, lun);
|