summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McDonald <danmcd@mnx.io>2022-07-06 11:17:10 -0400
committerDan McDonald <danmcd@mnx.io>2022-07-06 11:17:10 -0400
commit1631983f238c3295c2b6fea7fd3d5c1f8fb4b358 (patch)
tree3975c90a4cb7b7ffeb47c3b07f141ca10526e256
parent586824c5d718609e395e15b0a92824ba9794397d (diff)
parente302d6af529afb66d0ef5663cf940d230dc1122e (diff)
downloadillumos-joyent-1631983f238c3295c2b6fea7fd3d5c1f8fb4b358.tar.gz
[illumos-gate merge]
commit e302d6af529afb66d0ef5663cf940d230dc1122e 14784 Desire scsi_hba_tgtmap_scan_luns commit fe426563f5e7383c12abf6a347e131898d1a7f6c 14758 spurious presence detect change notification when enabling PCIe hotplug interrupt for the first time
-rw-r--r--manifest1
-rw-r--r--usr/src/man/man9f/Makefile3
-rw-r--r--usr/src/man/man9f/scsi_hba_tgtmap_create.9f29
-rw-r--r--usr/src/pkg/manifests/system-kernel.man9f.inc3
-rw-r--r--usr/src/uts/common/io/pciex/hotplug/pciehpc.c39
-rw-r--r--usr/src/uts/common/io/scsi/impl/scsi_hba.c46
-rw-r--r--usr/src/uts/common/io/vioscsi/vioscsi.c79
-rw-r--r--usr/src/uts/common/sys/scsi/impl/transport.h4
8 files changed, 113 insertions, 91 deletions
diff --git a/manifest b/manifest
index 32a5a0df1b..55ff346097 100644
--- a/manifest
+++ b/manifest
@@ -21164,6 +21164,7 @@ s usr/share/man/man9f/scsi_hba_pkt_free.9f=scsi_hba_pkt_alloc.9f
f usr/share/man/man9f/scsi_hba_probe.9f 0444 root bin
f usr/share/man/man9f/scsi_hba_tgtmap_create.9f 0444 root bin
s usr/share/man/man9f/scsi_hba_tgtmap_destroy.9f=scsi_hba_tgtmap_create.9f
+s usr/share/man/man9f/scsi_hba_tgtmap_scan_luns.9f=scsi_hba_tgtmap_create.9f
s usr/share/man/man9f/scsi_hba_tgtmap_set_add.9f=scsi_hba_tgtmap_create.9f
s usr/share/man/man9f/scsi_hba_tgtmap_set_begin.9f=scsi_hba_tgtmap_create.9f
s usr/share/man/man9f/scsi_hba_tgtmap_set_end.9f=scsi_hba_tgtmap_create.9f
diff --git a/usr/src/man/man9f/Makefile b/usr/src/man/man9f/Makefile
index bcefcfe990..40082cd72a 100644
--- a/usr/src/man/man9f/Makefile
+++ b/usr/src/man/man9f/Makefile
@@ -15,6 +15,7 @@
# Copyright 2019 Joyent, Inc.
# Copyright 2020-2021 Tintri by DDN, Inc. All rights reserved.
# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
+# Copyright 2022 RackTop Systems, Inc.
#
include $(SRC)/Makefile.master
@@ -1163,6 +1164,7 @@ MANLINKS= AVL_NEXT.9f \
scsi_hba_iportmap_iport_remove.9f \
scsi_hba_pkt_free.9f \
scsi_hba_tgtmap_destroy.9f \
+ scsi_hba_tgtmap_scan_luns.9f \
scsi_hba_tgtmap_set_begin.9f \
scsi_hba_tgtmap_set_add.9f \
scsi_hba_tgtmap_set_end.9f \
@@ -2030,6 +2032,7 @@ scsi_hba_iport_find.9f := LINKSRC = scsi_hba_iport_exist.9f
scsi_hba_pkt_free.9f := LINKSRC = scsi_hba_pkt_alloc.9f
scsi_hba_tgtmap_destroy.9f := LINKSRC = scsi_hba_tgtmap_create.9f
+scsi_hba_tgtmap_scan_luns.9f := LINKSRC = scsi_hba_tgtmap_create.9f
scsi_hba_tgtmap_set_begin.9f := LINKSRC = scsi_hba_tgtmap_create.9f
scsi_hba_tgtmap_set_add.9f := LINKSRC = scsi_hba_tgtmap_create.9f
scsi_hba_tgtmap_set_end.9f := LINKSRC = scsi_hba_tgtmap_create.9f
diff --git a/usr/src/man/man9f/scsi_hba_tgtmap_create.9f b/usr/src/man/man9f/scsi_hba_tgtmap_create.9f
index a8a16afab0..77596030dc 100644
--- a/usr/src/man/man9f/scsi_hba_tgtmap_create.9f
+++ b/usr/src/man/man9f/scsi_hba_tgtmap_create.9f
@@ -11,6 +11,7 @@
.\"
.\" Copyright 2019, Joyent, Inc.
.\" Copyright 2022 Oxide Computer Company
+.\" Copyright 2022 RackTop Systems, Inc.
.\"
.Dd January 29, 2022
.Dt SCSI_HBA_TGTMAP_CREATE 9F
@@ -18,6 +19,7 @@
.Sh NAME
.Nm scsi_hba_tgtmap_create ,
.Nm scsi_hba_tgtmap_destroy ,
+.Nm scsi_hba_tgtmap_scan_luns ,
.Nm scsi_hba_tgtmap_set_begin ,
.Nm scsi_hba_tgtmap_set_add ,
.Nm scsi_hba_tgtmap_set_end ,
@@ -57,6 +59,11 @@
.Fa "void *tgt_priv"
.Fa "scsi_tgtmap_deact_rsn_t deact"
.Fc
+.Ft void
+.Fo scsi_hba_tgtmap_scan_luns
+.Fa "scsi_hba_tgtmap_t *tgtmap"
+.Fa "char *tgt_addr"
+.Fc
.Ft int
.Fo scsi_hba_tgtmap_set_begin
.Fa "scsi_hba_tgtmap_t *tgtmap"
@@ -425,6 +432,20 @@ and
arguments match those that were used when calling the
.Fn scsi_hba_tgtmap_tgt_add
function.
+.Ss Scanning for Logical Units
+SCSI targets may contain logical units
+.Pq LUNS
+that are created or destroyed by the target dynamically.
+In order to facilitate discovery of logical units, the HBA may call
+.Fn scsi_hba_tgtmap_scan_luns
+using the address of a target that has been registered using the given
+.Fa tgt_addr .
+.Pp
+This will cause the framework to issue a
+.Sy REPORT_LUNS
+command, to enumerate any present logical units.
+Logical units that are no longer present will be pruned from the system,
+and any new ones will be created.
.Sh CONTEXT
The
.Fn scsi_hba_tgtmap_create
@@ -450,6 +471,7 @@ functions for a target map will be called into the driver from
context.
.Pp
The
+.Fn scsi_hba_tgtmap_scan_luns ,
.Fn scsi_hba_tgtmap_set_begin ,
.Fn scsi_hba_tgtmap_set_add ,
.Fn scsi_hba_tgtmap_set_end ,
@@ -462,13 +484,12 @@ functions may be called from
or
.Sy kernel
context.
-It is recommended that device drivers do not call these functions from
+Device drivers should not call these functions from
.Sy interrupt
-context and instead should schedule deferred work with a task queue
+context and should instead schedule deferred work with a task queue
or with
.Xr timeout 9F
-if they receive notifications during an interrupt that causes them to
-need to call these functions.
+if a need to call these arises while handling an interrupt.
.Sh RETURN VALUES
Upon successful completion, the
.Fn scsi_hba_tgtmap_create ,
diff --git a/usr/src/pkg/manifests/system-kernel.man9f.inc b/usr/src/pkg/manifests/system-kernel.man9f.inc
index ff65a720ad..23f9420de2 100644
--- a/usr/src/pkg/manifests/system-kernel.man9f.inc
+++ b/usr/src/pkg/manifests/system-kernel.man9f.inc
@@ -15,6 +15,7 @@
# Copyright 2020-2021 Tintri by DDN, Inc. All rights reserved.
# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
# Copyright 2019 Joyent, Inc.
+# Copyright 2022 RackTop Systems, Inc.
#
file path=usr/share/man/man9f/ASSERT.9f
@@ -1196,6 +1197,8 @@ file path=usr/share/man/man9f/scsi_hba_probe.9f
file path=usr/share/man/man9f/scsi_hba_tgtmap_create.9f
link path=usr/share/man/man9f/scsi_hba_tgtmap_destroy.9f \
target=scsi_hba_tgtmap_create.9f
+link path=usr/share/man/man9f/scsi_hba_tgtmap_scan_luns.9f \
+ target=scsi_hba_tgtmap_create.9f
link path=usr/share/man/man9f/scsi_hba_tgtmap_set_add.9f \
target=scsi_hba_tgtmap_create.9f
link path=usr/share/man/man9f/scsi_hba_tgtmap_set_begin.9f \
diff --git a/usr/src/uts/common/io/pciex/hotplug/pciehpc.c b/usr/src/uts/common/io/pciex/hotplug/pciehpc.c
index eaf09ee4e6..ce18cec3e2 100644
--- a/usr/src/uts/common/io/pciex/hotplug/pciehpc.c
+++ b/usr/src/uts/common/io/pciex/hotplug/pciehpc.c
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2019 Joyent, Inc.
+ * Copyright 2022 Oxide Computer Company
*/
/*
@@ -890,6 +891,27 @@ pciehpc_enable_intr(pcie_hp_ctrl_t *ctrl_p)
pcie_hp_slot_t *slot_p = ctrl_p->hc_slots[0];
pcie_bus_t *bus_p = PCIE_DIP2BUS(ctrl_p->hc_dip);
uint16_t reg;
+ uint16_t intr_mask = PCIE_SLOTCTL_INTR_MASK;
+
+ /*
+ * power fault detection interrupt is enabled only
+ * when the slot is powered ON
+ */
+ if (slot_p->hs_info.cn_state < DDI_HP_CN_STATE_POWERED)
+ intr_mask &= ~PCIE_SLOTCTL_PWR_FAULT_EN;
+
+ /*
+ * enable interrupt sources but leave the top-level
+ * interrupt disabled. some sources may generate a
+ * spurrious event when they are first enabled.
+ * by leaving the top-level interrupt disabled, those
+ * can be cleared first.
+ */
+ reg = pciehpc_reg_get16(ctrl_p,
+ bus_p->bus_pcie_off + PCIE_SLOTCTL);
+ pciehpc_reg_put16(ctrl_p,
+ bus_p->bus_pcie_off + PCIE_SLOTCTL,
+ reg | (intr_mask & ~PCIE_SLOTCTL_HP_INTR_EN));
/* clear any interrupt status bits */
reg = pciehpc_reg_get16(ctrl_p,
@@ -897,21 +919,12 @@ pciehpc_enable_intr(pcie_hp_ctrl_t *ctrl_p)
pciehpc_reg_put16(ctrl_p,
bus_p->bus_pcie_off + PCIE_SLOTSTS, reg);
- /* read the Slot Control Register */
+ /* enable top-level interrupt */
reg = pciehpc_reg_get16(ctrl_p,
bus_p->bus_pcie_off + PCIE_SLOTCTL);
-
- /*
- * enable interrupts: power fault detection interrupt is enabled
- * only when the slot is powered ON
- */
- if (slot_p->hs_info.cn_state >= DDI_HP_CN_STATE_POWERED)
- pciehpc_reg_put16(ctrl_p, bus_p->bus_pcie_off +
- PCIE_SLOTCTL, reg | PCIE_SLOTCTL_INTR_MASK);
- else
- pciehpc_reg_put16(ctrl_p, bus_p->bus_pcie_off +
- PCIE_SLOTCTL, reg | (PCIE_SLOTCTL_INTR_MASK &
- ~PCIE_SLOTCTL_PWR_FAULT_EN));
+ pciehpc_reg_put16(ctrl_p,
+ bus_p->bus_pcie_off + PCIE_SLOTCTL,
+ reg | intr_mask);
return (DDI_SUCCESS);
}
diff --git a/usr/src/uts/common/io/scsi/impl/scsi_hba.c b/usr/src/uts/common/io/scsi/impl/scsi_hba.c
index 0ae0978796..ed9df67847 100644
--- a/usr/src/uts/common/io/scsi/impl/scsi_hba.c
+++ b/usr/src/uts/common/io/scsi/impl/scsi_hba.c
@@ -23,6 +23,7 @@
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
* Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright 2022 RackTop Systems, Inc.
*/
#include <sys/note.h>
@@ -5609,7 +5610,7 @@ scsi_hba_pkt_comp(struct scsi_pkt *pkt)
pkt->pkt_stmp = scsi_lunchg1_list;
scsi_lunchg1_list = pkt;
if (pkt->pkt_stmp == NULL)
- (void) cv_signal(&scsi_lunchg1_cv);
+ cv_signal(&scsi_lunchg1_cv);
mutex_exit(&scsi_lunchg1_mutex);
return;
}
@@ -5719,7 +5720,7 @@ scsi_hba_barrier_add(dev_info_t *probe, int seconds)
nb->barrier_probe = probe;
*bp = nb;
if (bp == &scsi_hba_barrier_list)
- (void) cv_signal(&scsi_hba_barrier_cv);
+ cv_signal(&scsi_hba_barrier_cv);
mutex_exit(&scsi_hba_barrier_mutex);
}
@@ -5935,9 +5936,9 @@ scsi_lunchg1_daemon(void *arg)
* lun enumeration.
*/
(void) ddi_pathname(self, path);
- (void) strcat(path, "/luns@");
- (void) strcat(path, taddr);
- (void) strcat(path, ",*");
+ (void) strlcat(path, "/luns@", sizeof (path));
+ (void) strlcat(path, taddr, sizeof (path));
+ (void) strlcat(path, ",*", sizeof (path));
/*
* Now that we have the path, complete the pkt that
@@ -5956,7 +5957,7 @@ scsi_lunchg1_daemon(void *arg)
lunchg2->lunchg2_next = scsi_lunchg2_list;
scsi_lunchg2_list = lunchg2;
if (lunchg2->lunchg2_next == NULL)
- (void) cv_signal(&scsi_lunchg2_cv);
+ cv_signal(&scsi_lunchg2_cv);
mutex_exit(&scsi_lunchg2_mutex);
}
}
@@ -8911,6 +8912,39 @@ scsi_hba_tgtmap_tgt_remove(scsi_hba_tgtmap_t *handle,
tgt_addr) == DAM_SUCCESS) ? DDI_SUCCESS : DDI_FAILURE);
}
+void
+scsi_hba_tgtmap_scan_luns(scsi_hba_tgtmap_t *handle, char *tgt_addr)
+{
+ impl_scsi_tgtmap_t *tgtmap = (impl_scsi_tgtmap_t *)handle;
+ dev_info_t *self = tgtmap->tgtmap_tran->tran_iport_dip;
+ struct scsi_lunchg2 *lunchg2;
+ struct scsi_lunchg2 *p;
+ char path[MAXPATHLEN];
+
+ (void) ddi_pathname(self, path);
+ (void) strlcat(path, "/luns@", sizeof (path));
+ (void) strlcat(path, tgt_addr, sizeof (path));
+ (void) strlcat(path, ",*", sizeof (path));
+
+ mutex_enter(&scsi_lunchg2_mutex);
+
+ /* if we're already scheduled to do this, don't submit another one */
+ for (p = scsi_lunchg2_list; p != NULL; p = p->lunchg2_next) {
+ if (strcmp(path, p->lunchg2_path) == 0) {
+ mutex_exit(&scsi_lunchg2_mutex);
+ return;
+ }
+ }
+
+ lunchg2 = kmem_alloc(sizeof (*lunchg2), KM_SLEEP);
+ lunchg2->lunchg2_path = strdup(path);
+ lunchg2->lunchg2_next = scsi_lunchg2_list;
+ scsi_lunchg2_list = lunchg2;
+ if (lunchg2->lunchg2_next == NULL)
+ cv_signal(&scsi_lunchg2_cv);
+ mutex_exit(&scsi_lunchg2_mutex);
+}
+
int
scsi_hba_tgtmap_lookup(scsi_hba_tgtmap_t *handle,
char *tgt_addr, scsi_tgtmap_tgt_type_t *r_type)
diff --git a/usr/src/uts/common/io/vioscsi/vioscsi.c b/usr/src/uts/common/io/vioscsi/vioscsi.c
index 1e35252a6c..c647740672 100644
--- a/usr/src/uts/common/io/vioscsi/vioscsi.c
+++ b/usr/src/uts/common/io/vioscsi/vioscsi.c
@@ -1037,81 +1037,24 @@ vioscsi_probe_target(vioscsi_softc_t *sc, vioscsi_request_t *req,
}
static void
-vioscsi_null_complete(struct scsi_pkt *pkt)
-{
- /*
- * This intentionally does nothing.
- */
-}
-
-static void
-vioscsi_dev_rescan(vioscsi_dev_t *vd)
-{
- struct scsi_pkt *pkt;
- struct scsi_arq_status *aqs;
- uint8_t *sense;
-
- /*
- * This routine is a bit of a hack, to workaround the fact that we have
- * no other good way to convince the SCSI HBA framework to rescan for
- * new LUNs. What we do is fake an inquiry and complete it with a UNIT
- * ATTENTION indicating that the REPORT LUNS data has changed.
- */
-
- pkt = scsi_init_pkt(&vd->vd_sd->sd_address, NULL, NULL, 6,
- sizeof (struct scsi_arq_status), 0, 0, SLEEP_FUNC, NULL);
- if (pkt == NULL) { /* should never happen with SLEEP_FUNC */
- return;
- }
-
- /*
- * Must have a non-null completion routine in order to get the HBA
- * logic to check the UNIT ATTENTION STATUS.
- */
- pkt->pkt_comp = vioscsi_null_complete;
-
- /*
- * The default CDB is 0, TEST UNIT READY, which takes no data, and
- * returns no data.
- */
- pkt->pkt_state = CMD_CMPLT;
- pkt->pkt_state = STATE_GOT_BUS | STATE_GOT_TARGET | STATE_SENT_CMD |
- STATE_GOT_STATUS | STATE_ARQ_DONE;
- pkt->pkt_scbp[0] = STATUS_CHECK;
- aqs = (void *)pkt->pkt_scbp;
- aqs->sts_rqpkt_reason = CMD_CMPLT;
- aqs->sts_rqpkt_resid = 0;
- aqs->sts_rqpkt_state = STATE_GOT_BUS | STATE_GOT_TARGET |
- STATE_GOT_STATUS | STATE_SENT_CMD | STATE_XFERRED_DATA;
- sense = (void *)&aqs->sts_sensedata;
-
- /*
- * Descriptor format sense response:
- */
- sense[0] = 0x72;
- sense[1] = KEY_UNIT_ATTENTION;
- sense[2] = 0x3f; /* ASC - reported LUNs data changed */
- sense[3] = 0x0e; /* ASCQ */
- sense[7] = 0x00; /* additional sense length (none) */
-
- vd->vd_rescan = B_FALSE;
-
- scsi_hba_pkt_comp(pkt);
-}
-
-static void
vioscsi_rescan_luns(void *arg)
{
- vioscsi_softc_t *sc = arg;
- vioscsi_dev_t *vd;
- list_t *l;
+ vioscsi_softc_t *sc = arg;
+ vioscsi_dev_t *vd;
+ scsi_hba_tgtmap_t *tm = sc->vs_tgtmap;
+ list_t *l;
+ char addr[16];
l = &sc->vs_devs;
mutex_enter(&sc->vs_lock);
for (vd = list_head(l); vd != NULL; vd = list_next(l, vd)) {
- if (vd->vd_rescan) {
- vioscsi_dev_rescan(vd);
+ if (!vd->vd_rescan) {
+ continue;
}
+
+ vd->vd_rescan = B_FALSE;
+ (void) snprintf(addr, sizeof (addr), "%x", vd->vd_target);
+ scsi_hba_tgtmap_scan_luns(tm, addr);
}
mutex_exit(&sc->vs_lock);
}
diff --git a/usr/src/uts/common/sys/scsi/impl/transport.h b/usr/src/uts/common/sys/scsi/impl/transport.h
index 58e146c907..cfd18128f7 100644
--- a/usr/src/uts/common/sys/scsi/impl/transport.h
+++ b/usr/src/uts/common/sys/scsi/impl/transport.h
@@ -21,6 +21,7 @@
/*
* Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
+ * Copyright 2022 RackTop Systems, Inc.
*/
#ifndef _SYS_SCSI_IMPL_TRANSPORT_H
@@ -653,6 +654,9 @@ int scsi_hba_tgtmap_tgt_remove(
void scsi_hba_tgtmap_destroy(scsi_hba_tgtmap_t *tgt_map);
+void scsi_hba_tgtmap_scan_luns(scsi_hba_tgtmap_t *tgt_map,
+ char *tgt_addr);
+
/*
* For minor nodes created by the SCSA framework, minor numbers are