Skip to content

Commit fa88434

Browse files
jic23djbw
authored andcommitted
cxl/pci: Set the device timestamp
CXL r3.0 section 8.2.9.4.2 "Set Timestamp" recommends that the host sets the timestamp after every Conventional or CXL Reset to ensure accurate timestamps. This should include on initial boot up. The time base that is being set is used by a device for the poison list overflow timestamp and all event timestamps. Note that the command is optional and if not supported and the device cannot return accurate timestamps it will fill the fields in with an appropriate marker (see the specification description of each timestamp). Signed-off-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 7ebf38c commit fa88434

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

drivers/cxl/core/mbox.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/io-64-nonatomic-lo-hi.h>
44
#include <linux/security.h>
55
#include <linux/debugfs.h>
6+
#include <linux/ktime.h>
67
#include <linux/mutex.h>
78
#include <cxlmem.h>
89
#include <cxl.h>
@@ -1055,6 +1056,32 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
10551056
}
10561057
EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL);
10571058

1059+
int cxl_set_timestamp(struct cxl_dev_state *cxlds)
1060+
{
1061+
struct cxl_mbox_cmd mbox_cmd;
1062+
struct cxl_mbox_set_timestamp_in pi;
1063+
int rc;
1064+
1065+
pi.timestamp = cpu_to_le64(ktime_get_real_ns());
1066+
mbox_cmd = (struct cxl_mbox_cmd) {
1067+
.opcode = CXL_MBOX_OP_SET_TIMESTAMP,
1068+
.size_in = sizeof(pi),
1069+
.payload_in = &pi,
1070+
};
1071+
1072+
rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
1073+
/*
1074+
* Command is optional. Devices may have another way of providing
1075+
* a timestamp, or may return all 0s in timestamp fields.
1076+
* Don't report an error if this command isn't supported
1077+
*/
1078+
if (rc && (mbox_cmd.return_code != CXL_MBOX_CMD_RC_UNSUPPORTED))
1079+
return rc;
1080+
1081+
return 0;
1082+
}
1083+
EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, CXL);
1084+
10581085
struct cxl_dev_state *cxl_dev_state_create(struct device *dev)
10591086
{
10601087
struct cxl_dev_state *cxlds;

drivers/cxl/cxlmem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ enum cxl_opcode {
309309
CXL_MBOX_OP_SET_EVT_INT_POLICY = 0x0103,
310310
CXL_MBOX_OP_GET_FW_INFO = 0x0200,
311311
CXL_MBOX_OP_ACTIVATE_FW = 0x0202,
312+
CXL_MBOX_OP_SET_TIMESTAMP = 0x0301,
312313
CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400,
313314
CXL_MBOX_OP_GET_LOG = 0x0401,
314315
CXL_MBOX_OP_IDENTIFY = 0x4000,
@@ -537,6 +538,12 @@ struct cxl_mbox_set_partition_info {
537538

538539
#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0)
539540

541+
/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
542+
struct cxl_mbox_set_timestamp_in {
543+
__le64 timestamp;
544+
545+
} __packed;
546+
540547
/**
541548
* struct cxl_mem_command - Driver representation of a memory device command
542549
* @info: Command information as it exists for the UAPI
@@ -607,6 +614,8 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
607614
void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
608615
void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
609616
void cxl_mem_get_event_records(struct cxl_dev_state *cxlds, u32 status);
617+
int cxl_set_timestamp(struct cxl_dev_state *cxlds);
618+
610619
#ifdef CONFIG_CXL_SUSPEND
611620
void cxl_mem_active_inc(void);
612621
void cxl_mem_active_dec(void);

drivers/cxl/pci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
708708
if (rc)
709709
return rc;
710710

711+
rc = cxl_set_timestamp(cxlds);
712+
if (rc)
713+
return rc;
714+
711715
rc = cxl_dev_state_identify(cxlds);
712716
if (rc)
713717
return rc;

0 commit comments

Comments
 (0)