Skip to content

Commit 44cd71e

Browse files
davejiangdjbw
authored andcommitted
cxl: Convert find_cxl_root() to return a 'struct cxl_root *'
Commit 7908159 ("cxl: Add support for _DSM Function for retrieving QTG ID") introduced 'struct cxl_root', however all usages have been worked indirectly through cxl_port. Refactor code such as find_cxl_root() function to use 'struct cxl_root' directly. Suggested-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/170449246044.3779673.13035770941393418591.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 98856b2 commit 44cd71e

6 files changed

Lines changed: 28 additions & 23 deletions

File tree

drivers/cxl/acpi.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,12 @@ cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct access_coordinate *coord,
295295
return rc;
296296
}
297297

298-
static int cxl_acpi_qos_class(struct cxl_port *root_port,
298+
static int cxl_acpi_qos_class(struct cxl_root *cxl_root,
299299
struct access_coordinate *coord, int entries,
300300
int *qos_class)
301301
{
302+
struct device *dev = cxl_root->port.uport_dev;
302303
acpi_handle handle;
303-
struct device *dev;
304-
305-
dev = root_port->uport_dev;
306304

307305
if (!dev_is_platform(dev))
308306
return -ENODEV;

drivers/cxl/core/cdat.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
162162
struct xarray *dsmas_xa)
163163
{
164164
struct access_coordinate c;
165-
struct cxl_port *root_port;
166165
struct cxl_root *cxl_root;
167166
struct dsmas_entry *dent;
168167
int valid_entries = 0;
@@ -175,8 +174,7 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
175174
return rc;
176175
}
177176

178-
root_port = find_cxl_root(port);
179-
cxl_root = to_cxl_root(root_port);
177+
cxl_root = find_cxl_root(port);
180178
if (!cxl_root->ops || !cxl_root->ops->qos_class)
181179
return -EOPNOTSUPP;
182180

@@ -193,7 +191,8 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port,
193191
dent->coord.write_bandwidth);
194192

195193
dent->entries = 1;
196-
rc = cxl_root->ops->qos_class(root_port, &dent->coord, 1, &qos_class);
194+
rc = cxl_root->ops->qos_class(cxl_root, &dent->coord, 1,
195+
&qos_class);
197196
if (rc != 1)
198197
continue;
199198

@@ -349,15 +348,19 @@ static int cxl_qos_class_verify(struct cxl_memdev *cxlmd)
349348
{
350349
struct cxl_dev_state *cxlds = cxlmd->cxlds;
351350
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
352-
struct cxl_port *root_port __free(put_device) = NULL;
353351
LIST_HEAD(__discard);
354352
struct list_head *discard __free(dpa_perf) = &__discard;
353+
struct cxl_port *root_port;
355354
int rc;
356355

357-
root_port = find_cxl_root(cxlmd->endpoint);
358-
if (!root_port)
356+
struct cxl_root *cxl_root __free(put_cxl_root) =
357+
find_cxl_root(cxlmd->endpoint);
358+
359+
if (!cxl_root)
359360
return -ENODEV;
360361

362+
root_port = &cxl_root->port;
363+
361364
/* Check that the QTG IDs are all sane between end device and root decoders */
362365
cxl_qos_match(root_port, &mds->ram_perf_list, discard);
363366
cxl_qos_match(root_port, &mds->pmem_perf_list, discard);

drivers/cxl/core/pmem.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ static int match_nvdimm_bridge(struct device *dev, void *data)
6464

6565
struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_memdev *cxlmd)
6666
{
67-
struct cxl_port *port = find_cxl_root(cxlmd->endpoint);
67+
struct cxl_root *cxl_root = find_cxl_root(cxlmd->endpoint);
68+
struct cxl_port *port;
6869
struct device *dev;
6970

70-
if (!port)
71+
if (!cxl_root)
7172
return NULL;
7273

74+
port = &cxl_root->port;
7375
dev = device_find_child(&port->dev, NULL, match_nvdimm_bridge);
7476
put_device(&port->dev);
7577

drivers/cxl/core/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static bool dev_is_cxl_root_child(struct device *dev)
972972
return false;
973973
}
974974

975-
struct cxl_port *find_cxl_root(struct cxl_port *port)
975+
struct cxl_root *find_cxl_root(struct cxl_port *port)
976976
{
977977
struct cxl_port *iter = port;
978978

@@ -982,7 +982,7 @@ struct cxl_port *find_cxl_root(struct cxl_port *port)
982982
if (!iter)
983983
return NULL;
984984
get_device(&iter->dev);
985-
return iter;
985+
return to_cxl_root(iter);
986986
}
987987
EXPORT_SYMBOL_NS_GPL(find_cxl_root, CXL);
988988

drivers/cxl/cxl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,6 @@ struct cxl_port {
617617
long pci_latency;
618618
};
619619

620-
struct cxl_root_ops {
621-
int (*qos_class)(struct cxl_port *root_port,
622-
struct access_coordinate *coord, int entries,
623-
int *qos_class);
624-
};
625-
626620
/**
627621
* struct cxl_root - logical collection of root cxl_port items
628622
*
@@ -640,6 +634,12 @@ to_cxl_root(const struct cxl_port *port)
640634
return container_of(port, struct cxl_root, port);
641635
}
642636

637+
struct cxl_root_ops {
638+
int (*qos_class)(struct cxl_root *cxl_root,
639+
struct access_coordinate *coord, int entries,
640+
int *qos_class);
641+
};
642+
643643
static inline struct cxl_dport *
644644
cxl_find_dport_by_dev(struct cxl_port *port, const struct device *dport_dev)
645645
{
@@ -734,7 +734,7 @@ struct cxl_port *devm_cxl_add_port(struct device *host,
734734
struct cxl_dport *parent_dport);
735735
struct cxl_root *devm_cxl_add_root(struct device *host,
736736
const struct cxl_root_ops *ops);
737-
struct cxl_port *find_cxl_root(struct cxl_port *port);
737+
struct cxl_root *find_cxl_root(struct cxl_port *port);
738738
void put_cxl_root(struct cxl_root *cxl_root);
739739
DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_cxl_root(_T))
740740

drivers/cxl/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
9494
struct cxl_endpoint_dvsec_info info = { .port = port };
9595
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
9696
struct cxl_dev_state *cxlds = cxlmd->cxlds;
97+
struct cxl_root *cxl_root;
9798
struct cxl_hdm *cxlhdm;
9899
struct cxl_port *root;
99100
int rc;
@@ -130,7 +131,8 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
130131
* This can't fail in practice as CXL root exit unregisters all
131132
* descendant ports and that in turn synchronizes with cxl_port_probe()
132133
*/
133-
root = find_cxl_root(port);
134+
cxl_root = find_cxl_root(port);
135+
root = &cxl_root->port;
134136

135137
/*
136138
* Now that all endpoint decoders are successfully enumerated, try to

0 commit comments

Comments
 (0)