Skip to content

Commit 63cef81

Browse files
davejiangdjbw
authored andcommitted
cxl: Add callback to parse the DSLBIS subtable from CDAT
Provide a callback to parse the Device Scoped Latency and Bandwidth Information Structure (DSLBIS) in the CDAT structures. The DSLBIS contains the bandwidth and latency information that's tied to a DSMAS handle. The driver will retrieve the read and write latency and bandwidth associated with the DSMAS which is tied to a DPA range. Coherent Device Attribute Table 1.03 2.1 Device Scoped Latency and Bandwidth Information Structure (DSLBIS) Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/170319620005.2212653.7475488478229720542.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent ad6f04c commit 63cef81

1 file changed

Lines changed: 100 additions & 2 deletions

File tree

drivers/cxl/core/cdat.c

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
#include <linux/acpi.h>
44
#include <linux/xarray.h>
55
#include <linux/fw_table.h>
6+
#include <linux/node.h>
7+
#include <linux/overflow.h>
68
#include "cxlpci.h"
79
#include "cxl.h"
810

911
struct dsmas_entry {
1012
struct range dpa_range;
1113
u8 handle;
14+
struct access_coordinate coord;
1215
};
1316

1417
static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg,
@@ -49,11 +52,106 @@ static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg,
4952
return 0;
5053
}
5154

55+
static void cxl_access_coordinate_set(struct access_coordinate *coord,
56+
int access, unsigned int val)
57+
{
58+
switch (access) {
59+
case ACPI_HMAT_ACCESS_LATENCY:
60+
coord->read_latency = val;
61+
coord->write_latency = val;
62+
break;
63+
case ACPI_HMAT_READ_LATENCY:
64+
coord->read_latency = val;
65+
break;
66+
case ACPI_HMAT_WRITE_LATENCY:
67+
coord->write_latency = val;
68+
break;
69+
case ACPI_HMAT_ACCESS_BANDWIDTH:
70+
coord->read_bandwidth = val;
71+
coord->write_bandwidth = val;
72+
break;
73+
case ACPI_HMAT_READ_BANDWIDTH:
74+
coord->read_bandwidth = val;
75+
break;
76+
case ACPI_HMAT_WRITE_BANDWIDTH:
77+
coord->write_bandwidth = val;
78+
break;
79+
}
80+
}
81+
82+
static int cdat_dslbis_handler(union acpi_subtable_headers *header, void *arg,
83+
const unsigned long end)
84+
{
85+
struct acpi_cdat_header *hdr = &header->cdat;
86+
struct acpi_cdat_dslbis *dslbis;
87+
int size = sizeof(*hdr) + sizeof(*dslbis);
88+
struct xarray *dsmas_xa = arg;
89+
struct dsmas_entry *dent;
90+
__le64 le_base;
91+
__le16 le_val;
92+
u64 val;
93+
u16 len;
94+
int rc;
95+
96+
len = le16_to_cpu((__force __le16)hdr->length);
97+
if (len != size || (unsigned long)hdr + len > end) {
98+
pr_warn("Malformed DSLBIS table length: (%u:%u)\n", size, len);
99+
return -EINVAL;
100+
}
101+
102+
/* Skip common header */
103+
dslbis = (struct acpi_cdat_dslbis *)(hdr + 1);
104+
105+
/* Skip unrecognized data type */
106+
if (dslbis->data_type > ACPI_HMAT_WRITE_BANDWIDTH)
107+
return 0;
108+
109+
/* Not a memory type, skip */
110+
if ((dslbis->flags & ACPI_HMAT_MEMORY_HIERARCHY) != ACPI_HMAT_MEMORY)
111+
return 0;
112+
113+
dent = xa_load(dsmas_xa, dslbis->handle);
114+
if (!dent) {
115+
pr_warn("No matching DSMAS entry for DSLBIS entry.\n");
116+
return 0;
117+
}
118+
119+
le_base = (__force __le64)dslbis->entry_base_unit;
120+
le_val = (__force __le16)dslbis->entry[0];
121+
rc = check_mul_overflow(le64_to_cpu(le_base),
122+
le16_to_cpu(le_val), &val);
123+
if (rc)
124+
pr_warn("DSLBIS value overflowed.\n");
125+
126+
cxl_access_coordinate_set(&dent->coord, dslbis->data_type, val);
127+
128+
return 0;
129+
}
130+
131+
static int cdat_table_parse_output(int rc)
132+
{
133+
if (rc < 0)
134+
return rc;
135+
if (rc == 0)
136+
return -ENOENT;
137+
138+
return 0;
139+
}
140+
52141
static int cxl_cdat_endpoint_process(struct cxl_port *port,
53142
struct xarray *dsmas_xa)
54143
{
55-
return cdat_table_parse(ACPI_CDAT_TYPE_DSMAS, cdat_dsmas_handler,
56-
dsmas_xa, port->cdat.table);
144+
int rc;
145+
146+
rc = cdat_table_parse(ACPI_CDAT_TYPE_DSMAS, cdat_dsmas_handler,
147+
dsmas_xa, port->cdat.table);
148+
rc = cdat_table_parse_output(rc);
149+
if (rc)
150+
return rc;
151+
152+
rc = cdat_table_parse(ACPI_CDAT_TYPE_DSLBIS, cdat_dslbis_handler,
153+
dsmas_xa, port->cdat.table);
154+
return cdat_table_parse_output(rc);
57155
}
58156

59157
static void discard_dsmas(struct xarray *xa)

0 commit comments

Comments
 (0)