Skip to content

Commit 021b7e4

Browse files
Davidlohr Buesodavejiang
authored andcommitted
cxl/pci: Introduce cxl_gpf_get_dvsec()
Add a helper to fetch the port/device GPF dvsecs. This is currently only used for ports, but a later patch to export dirty count to users will make use of the device one. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Reviewed-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://patch.msgid.link/20250220220235.276831-2-dave@stgolabs.net Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent a52b6a2 commit 021b7e4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

drivers/cxl/core/pci.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,22 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
10721072
#define GPF_TIMEOUT_BASE_MAX 2
10731073
#define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
10741074

1075+
u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port)
1076+
{
1077+
u16 dvsec;
1078+
1079+
if (!dev_is_pci(dev))
1080+
return 0;
1081+
1082+
dvsec = pci_find_dvsec_capability(to_pci_dev(dev), PCI_VENDOR_ID_CXL,
1083+
is_port ? CXL_DVSEC_PORT_GPF : CXL_DVSEC_DEVICE_GPF);
1084+
if (!dvsec)
1085+
dev_warn(dev, "%s GPF DVSEC not present\n",
1086+
is_port ? "Port" : "Device");
1087+
return dvsec;
1088+
}
1089+
EXPORT_SYMBOL_NS_GPL(cxl_gpf_get_dvsec, "CXL");
1090+
10751091
static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
10761092
{
10771093
u64 base, scale;
@@ -1116,26 +1132,20 @@ int cxl_gpf_port_setup(struct device *dport_dev, struct cxl_port *port)
11161132
{
11171133
struct pci_dev *pdev;
11181134

1119-
if (!dev_is_pci(dport_dev))
1120-
return 0;
1121-
1122-
pdev = to_pci_dev(dport_dev);
1123-
if (!pdev || !port)
1135+
if (!port)
11241136
return -EINVAL;
11251137

11261138
if (!port->gpf_dvsec) {
11271139
int dvsec;
11281140

1129-
dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
1130-
CXL_DVSEC_PORT_GPF);
1131-
if (!dvsec) {
1132-
pci_warn(pdev, "Port GPF DVSEC not present\n");
1141+
dvsec = cxl_gpf_get_dvsec(dport_dev, true);
1142+
if (!dvsec)
11331143
return -EINVAL;
1134-
}
11351144

11361145
port->gpf_dvsec = dvsec;
11371146
}
11381147

1148+
pdev = to_pci_dev(dport_dev);
11391149
update_gpf_port_dvsec(pdev, port->gpf_dvsec, 1);
11401150
update_gpf_port_dvsec(pdev, port->gpf_dvsec, 2);
11411151

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,6 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port);
922922
#define __mock static
923923
#endif
924924

925+
u16 cxl_gpf_get_dvsec(struct device *dev, bool is_port);
926+
925927
#endif /* __CXL_H__ */

0 commit comments

Comments
 (0)