Skip to content

Commit 86557b7

Browse files
davejiangdjbw
authored andcommitted
cxl: Store QTG IDs and related info to the CXL memory device context
Once the QTG ID _DSM is executed successfully, the QTG ID is retrieved from the return package. Create a list of entries in the cxl_memdev context and store the QTG ID as qos_class token and the associated DPA range. This information can be exposed to user space via sysfs in order to help region setup for hot-plugged CXL memory devices. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/170319625109.2212653.11872111896220384056.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 7a4f148 commit 86557b7

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

drivers/cxl/core/cdat.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/node.h>
77
#include <linux/overflow.h>
88
#include "cxlpci.h"
9+
#include "cxlmem.h"
910
#include "cxl.h"
1011

1112
struct dsmas_entry {
@@ -206,6 +207,71 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
206207
return 0;
207208
}
208209

210+
static void add_perf_entry(struct device *dev, struct dsmas_entry *dent,
211+
struct list_head *list)
212+
{
213+
struct cxl_dpa_perf *dpa_perf;
214+
215+
dpa_perf = kzalloc(sizeof(*dpa_perf), GFP_KERNEL);
216+
if (!dpa_perf)
217+
return;
218+
219+
dpa_perf->dpa_range = dent->dpa_range;
220+
dpa_perf->coord = dent->coord;
221+
dpa_perf->qos_class = dent->qos_class;
222+
list_add_tail(&dpa_perf->list, list);
223+
dev_dbg(dev,
224+
"DSMAS: dpa: %#llx qos: %d read_bw: %d write_bw %d read_lat: %d write_lat: %d\n",
225+
dent->dpa_range.start, dpa_perf->qos_class,
226+
dent->coord.read_bandwidth, dent->coord.write_bandwidth,
227+
dent->coord.read_latency, dent->coord.write_latency);
228+
}
229+
230+
static void free_perf_ents(void *data)
231+
{
232+
struct cxl_memdev_state *mds = data;
233+
struct cxl_dpa_perf *dpa_perf, *n;
234+
LIST_HEAD(discard);
235+
236+
list_splice_tail_init(&mds->ram_perf_list, &discard);
237+
list_splice_tail_init(&mds->pmem_perf_list, &discard);
238+
list_for_each_entry_safe(dpa_perf, n, &discard, list) {
239+
list_del(&dpa_perf->list);
240+
kfree(dpa_perf);
241+
}
242+
}
243+
244+
static void cxl_memdev_set_qos_class(struct cxl_dev_state *cxlds,
245+
struct xarray *dsmas_xa)
246+
{
247+
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
248+
struct device *dev = cxlds->dev;
249+
struct range pmem_range = {
250+
.start = cxlds->pmem_res.start,
251+
.end = cxlds->pmem_res.end,
252+
};
253+
struct range ram_range = {
254+
.start = cxlds->ram_res.start,
255+
.end = cxlds->ram_res.end,
256+
};
257+
struct dsmas_entry *dent;
258+
unsigned long index;
259+
260+
xa_for_each(dsmas_xa, index, dent) {
261+
if (resource_size(&cxlds->ram_res) &&
262+
range_contains(&ram_range, &dent->dpa_range))
263+
add_perf_entry(dev, dent, &mds->ram_perf_list);
264+
else if (resource_size(&cxlds->pmem_res) &&
265+
range_contains(&pmem_range, &dent->dpa_range))
266+
add_perf_entry(dev, dent, &mds->pmem_perf_list);
267+
else
268+
dev_dbg(dev, "no partition for dsmas dpa: %#llx\n",
269+
dent->dpa_range.start);
270+
}
271+
272+
devm_add_action_or_reset(&cxlds->cxlmd->dev, free_perf_ents, mds);
273+
}
274+
209275
static void discard_dsmas(struct xarray *xa)
210276
{
211277
unsigned long index;
@@ -221,6 +287,8 @@ DEFINE_FREE(dsmas, struct xarray *, if (_T) discard_dsmas(_T))
221287

222288
void cxl_endpoint_parse_cdat(struct cxl_port *port)
223289
{
290+
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
291+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
224292
struct xarray __dsmas_xa;
225293
struct xarray *dsmas_xa __free(dsmas) = &__dsmas_xa;
226294
int rc;
@@ -241,6 +309,7 @@ void cxl_endpoint_parse_cdat(struct cxl_port *port)
241309
return;
242310
}
243311

312+
cxl_memdev_set_qos_class(cxlds, dsmas_xa);
244313
}
245314
EXPORT_SYMBOL_NS_GPL(cxl_endpoint_parse_cdat, CXL);
246315

drivers/cxl/core/mbox.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,8 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)
14041404
mds->cxlds.reg_map.host = dev;
14051405
mds->cxlds.reg_map.resource = CXL_RESOURCE_NONE;
14061406
mds->cxlds.type = CXL_DEVTYPE_CLASSMEM;
1407+
INIT_LIST_HEAD(&mds->ram_perf_list);
1408+
INIT_LIST_HEAD(&mds->pmem_perf_list);
14071409

14081410
return mds;
14091411
}

drivers/cxl/cxlmem.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/cdev.h>
77
#include <linux/uuid.h>
88
#include <linux/rcuwait.h>
9+
#include <linux/node.h>
910
#include "cxl.h"
1011

1112
/* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
@@ -391,6 +392,20 @@ enum cxl_devtype {
391392
CXL_DEVTYPE_CLASSMEM,
392393
};
393394

395+
/**
396+
* struct cxl_dpa_perf - DPA performance property entry
397+
* @list - list entry
398+
* @dpa_range - range for DPA address
399+
* @coord - QoS performance data (i.e. latency, bandwidth)
400+
* @qos_class - QoS Class cookies
401+
*/
402+
struct cxl_dpa_perf {
403+
struct list_head list;
404+
struct range dpa_range;
405+
struct access_coordinate coord;
406+
int qos_class;
407+
};
408+
394409
/**
395410
* struct cxl_dev_state - The driver device state
396411
*
@@ -455,6 +470,8 @@ struct cxl_dev_state {
455470
* @security: security driver state info
456471
* @fw: firmware upload / activation state
457472
* @mbox_send: @dev specific transport for transmitting mailbox commands
473+
* @ram_perf_list: performance data entries matched to RAM
474+
* @pmem_perf_list: performance data entries matched to PMEM
458475
*
459476
* See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for
460477
* details on capacity parameters.
@@ -475,6 +492,10 @@ struct cxl_memdev_state {
475492
u64 active_persistent_bytes;
476493
u64 next_volatile_bytes;
477494
u64 next_persistent_bytes;
495+
496+
struct list_head ram_perf_list;
497+
struct list_head pmem_perf_list;
498+
478499
struct cxl_event_state event;
479500
struct cxl_poison_state poison;
480501
struct cxl_security_state security;

0 commit comments

Comments
 (0)