Page MenuHomeFreeBSD

D59997.1794686277.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D59997.1794686277.diff

diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -1150,6 +1150,25 @@
NVME_AA_ACTIVATE = 0x2,
};
+/* Timestamp - Data Structure for Set Features / Get Features */
+struct nvme_timestamp_data {
+ uint8_t tstmp[6]; /* milliseconds since 1970-01-01 UTC */
+ uint8_t tstmps; /* attributes, get features only */
+ uint8_t rsvd7;
+} __packed;
+
+_Static_assert(sizeof(struct nvme_timestamp_data) == 8,
+ "bad size for nvme_timestamp_data");
+
+/** Timestamp attributes */
+#define NVME_TIMESTAMP_TSTMPS_SYNCH_SHIFT (0)
+#define NVME_TIMESTAMP_TSTMPS_SYNCH_MASK (0x1)
+#define NVME_TIMESTAMP_TSTMPS_ORIGIN_SHIFT (1)
+#define NVME_TIMESTAMP_TSTMPS_ORIGIN_MASK (0x7)
+
+#define NVME_TIMESTAMP_ORIGIN_RESET (0x0)
+#define NVME_TIMESTAMP_ORIGIN_SET_FEATURES (0x1)
+
struct nvme_power_state {
/** Maximum Power */
uint16_t mp; /* Maximum Power */
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -885,6 +885,54 @@
free(data, M_NVME);
}
+/* XXX revisit the ordering if the clock ever comes up earlier. */
+static void
+nvme_ctrlr_set_timestamp(struct nvme_controller *ctrlr)
+{
+ struct nvme_completion_poll_status status;
+ struct nvme_timestamp_data *ts;
+ struct timespec now;
+ uint64_t ms;
+ int i;
+
+ ts = malloc(sizeof(*ts), M_NVME, M_WAITOK | M_ZERO);
+ getnanotime(&now);
+ ms = (uint64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
+ for (i = 0; i < nitems(ts->tstmp); i++)
+ ts->tstmp[i] = (ms >> (i * 8)) & 0xff;
+
+ status.done = 0;
+ nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_TIMESTAMP, 0, 0, 0, 0, 0,
+ ts, sizeof(*ts), nvme_completion_poll_cb, &status);
+ nvme_completion_poll(&status);
+ if (nvme_completion_is_error(&status.cpl) && bootverbose)
+ nvme_printf(ctrlr, "failed to set the timestamp\n");
+ free(ts, M_NVME);
+}
+
+static void
+nvme_ctrlr_timestamp_mountroot(void *arg)
+{
+ struct nvme_controller *ctrlr = arg;
+
+ if (ctrlr->is_failed || ctrlr->is_failed_admin || ctrlr->is_dying)
+ return;
+ nvme_ctrlr_set_timestamp(ctrlr);
+}
+
+static void
+nvme_ctrlr_configure_timestamp(struct nvme_controller *ctrlr)
+{
+ if (NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, ctrlr->cdata.oncs) == 0)
+ return;
+
+ /* The mountroot handler registered at attach does the initial set. */
+ if (!root_mounted())
+ return;
+
+ nvme_ctrlr_set_timestamp(ctrlr);
+}
+
static void
nvme_ctrlr_configure_int_coalescing(struct nvme_controller *ctrlr)
{
@@ -1153,6 +1201,7 @@
nvme_ctrlr_configure_aer(ctrlr);
nvme_ctrlr_configure_apst(ctrlr);
nvme_ctrlr_configure_int_coalescing(ctrlr);
+ nvme_ctrlr_configure_timestamp(ctrlr);
for (i = 0; i < ctrlr->num_io_queues; i++)
nvme_io_qpair_enable(&ctrlr->ioq[i]);
@@ -1194,6 +1243,12 @@
nvme_printf(ctrlr,
"ignoring Apple-internal namespaces above NSID 1\n");
+ if (!root_mounted() &&
+ NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, ctrlr->cdata.oncs) != 0)
+ ctrlr->timestamp_tag = EVENTHANDLER_REGISTER(mountroot,
+ nvme_ctrlr_timestamp_mountroot, ctrlr,
+ EVENTHANDLER_PRI_ANY);
+
ctrlr->is_initialized = true;
child = device_add_child(ctrlr->dev, NULL, DEVICE_UNIT_ANY);
device_set_ivars(child, ctrlr);
@@ -1851,6 +1906,11 @@
ctrlr->is_dying = true;
+ if (ctrlr->timestamp_tag != NULL) {
+ EVENTHANDLER_DEREGISTER(mountroot, ctrlr->timestamp_tag);
+ ctrlr->timestamp_tag = NULL;
+ }
+
if (ctrlr->resource == NULL)
goto nores;
if (!mtx_initialized(&ctrlr->adminq.lock))
diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -33,6 +33,7 @@
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/counter.h>
+#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
@@ -323,6 +324,8 @@
bool isr_warned;
bool is_initialized;
+ eventhandler_tag timestamp_tag;
+
/* Host Memory Buffer */
int hmb_nchunks;
size_t hmb_chunk;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 14, 7:57 PM (10 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41731572
Default Alt Text
D59997.1794686277.diff (3 KB)

Event Timeline