Skip to content

Commit ed83f7c

Browse files
AlisonSchofielddjbw
authored andcommitted
cxl/mbox: Add GET_POISON_LIST mailbox command
CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host. Per the spec, (CXL 3.0 8.2.9.8.4.1), the device returns this Poison list as a set of Media Error Records that include the source of the error, the starting device physical address, and length. The length is the number of adjacent DPAs in the record and is in units of 64 bytes. Retrieve the poison list. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/a1f332e817834ef8e89c0ff32e760308fb903346.1681838291.git.alison.schofield@intel.com Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent d0abf57 commit ed83f7c

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

drivers/cxl/core/mbox.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/debugfs.h>
66
#include <linux/ktime.h>
77
#include <linux/mutex.h>
8+
#include <asm/unaligned.h>
89
#include <cxlpci.h>
910
#include <cxlmem.h>
1011
#include <cxl.h>
@@ -1038,6 +1039,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
10381039
/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
10391040
struct cxl_mbox_identify id;
10401041
struct cxl_mbox_cmd mbox_cmd;
1042+
u32 val;
10411043
int rc;
10421044

10431045
mbox_cmd = (struct cxl_mbox_cmd) {
@@ -1061,6 +1063,11 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
10611063
cxlds->lsa_size = le32_to_cpu(id.lsa_size);
10621064
memcpy(cxlds->firmware_version, id.fw_revision, sizeof(id.fw_revision));
10631065

1066+
if (test_bit(CXL_POISON_ENABLED_LIST, cxlds->poison.enabled_cmds)) {
1067+
val = get_unaligned_le24(id.poison_list_max_mer);
1068+
cxlds->poison.max_errors = min_t(u32, val, CXL_POISON_LIST_MAX);
1069+
}
1070+
10641071
return 0;
10651072
}
10661073
EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL);
@@ -1151,6 +1158,54 @@ int cxl_set_timestamp(struct cxl_dev_state *cxlds)
11511158
}
11521159
EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, CXL);
11531160

1161+
int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
1162+
struct cxl_region *cxlr)
1163+
{
1164+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
1165+
struct cxl_mbox_poison_out *po;
1166+
struct cxl_mbox_poison_in pi;
1167+
struct cxl_mbox_cmd mbox_cmd;
1168+
int nr_records = 0;
1169+
int rc;
1170+
1171+
rc = mutex_lock_interruptible(&cxlds->poison.lock);
1172+
if (rc)
1173+
return rc;
1174+
1175+
po = cxlds->poison.list_out;
1176+
pi.offset = cpu_to_le64(offset);
1177+
pi.length = cpu_to_le64(len / CXL_POISON_LEN_MULT);
1178+
1179+
mbox_cmd = (struct cxl_mbox_cmd) {
1180+
.opcode = CXL_MBOX_OP_GET_POISON,
1181+
.size_in = sizeof(pi),
1182+
.payload_in = &pi,
1183+
.size_out = cxlds->payload_size,
1184+
.payload_out = po,
1185+
.min_out = struct_size(po, record, 0),
1186+
};
1187+
1188+
do {
1189+
rc = cxl_internal_send_cmd(cxlds, &mbox_cmd);
1190+
if (rc)
1191+
break;
1192+
1193+
/* TODO TRACE the media error records */
1194+
1195+
/* Protect against an uncleared _FLAG_MORE */
1196+
nr_records = nr_records + le16_to_cpu(po->count);
1197+
if (nr_records >= cxlds->poison.max_errors) {
1198+
dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n",
1199+
nr_records);
1200+
break;
1201+
}
1202+
} while (po->flags & CXL_POISON_FLAG_MORE);
1203+
1204+
mutex_unlock(&cxlds->poison.lock);
1205+
return rc;
1206+
}
1207+
EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL);
1208+
11541209
static void free_poison_buf(void *buf)
11551210
{
11561211
kvfree(buf);

drivers/cxl/cxlmem.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,50 @@ struct cxl_mbox_set_timestamp_in {
571571

572572
} __packed;
573573

574+
/* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */
575+
struct cxl_mbox_poison_in {
576+
__le64 offset;
577+
__le64 length;
578+
} __packed;
579+
580+
struct cxl_mbox_poison_out {
581+
u8 flags;
582+
u8 rsvd1;
583+
__le64 overflow_ts;
584+
__le16 count;
585+
u8 rsvd2[20];
586+
struct cxl_poison_record {
587+
__le64 address;
588+
__le32 length;
589+
__le32 rsvd;
590+
} __packed record[];
591+
} __packed;
592+
593+
/*
594+
* Get Poison List address field encodes the starting
595+
* address of poison, and the source of the poison.
596+
*/
597+
#define CXL_POISON_START_MASK GENMASK_ULL(63, 6)
598+
#define CXL_POISON_SOURCE_MASK GENMASK(2, 0)
599+
600+
/* Get Poison List record length is in units of 64 bytes */
601+
#define CXL_POISON_LEN_MULT 64
602+
603+
/* Kernel defined maximum for a list of poison errors */
604+
#define CXL_POISON_LIST_MAX 1024
605+
606+
/* Get Poison List: Payload out flags */
607+
#define CXL_POISON_FLAG_MORE BIT(0)
608+
#define CXL_POISON_FLAG_OVERFLOW BIT(1)
609+
#define CXL_POISON_FLAG_SCANNING BIT(2)
610+
611+
/* Get Poison List: Poison Source */
612+
#define CXL_POISON_SOURCE_UNKNOWN 0
613+
#define CXL_POISON_SOURCE_EXTERNAL 1
614+
#define CXL_POISON_SOURCE_INTERNAL 2
615+
#define CXL_POISON_SOURCE_INJECTED 3
616+
#define CXL_POISON_SOURCE_VENDOR 7
617+
574618
/**
575619
* struct cxl_mem_command - Driver representation of a memory device command
576620
* @info: Command information as it exists for the UAPI
@@ -642,6 +686,8 @@ void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cm
642686
void cxl_mem_get_event_records(struct cxl_dev_state *cxlds, u32 status);
643687
int cxl_set_timestamp(struct cxl_dev_state *cxlds);
644688
int cxl_poison_state_init(struct cxl_dev_state *cxlds);
689+
int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
690+
struct cxl_region *cxlr);
645691

646692
#ifdef CONFIG_CXL_SUSPEND
647693
void cxl_mem_active_inc(void);

0 commit comments

Comments
 (0)