Skip to content

Commit 5c6e3d5

Browse files
YanfeiXudavejiang
authored andcommitted
cxl/pci: Remove duplicated implementation of waiting for memory_info_valid
commit ce17ad0 ("cxl: Wait Memory_Info_Valid before access memory related info") added another implementation, which is cxl_dvsec_mem_range_valid(), of waiting for memory_info_valid without realizing it duplicated wait_for_valid(). Remove wait_for_valid() and retain cxl_dvsec_mem_range_valid() as the former is hardcoded to check only the Memory_Info_Valid bit of DVSEC range 1, while the latter allows for selection between DVSEC range 1 or 2 via parameter. Suggested-by: Dan Williams <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Yanfei Xu <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 55e2686 commit 5c6e3d5

File tree

4 files changed

+9
-40
lines changed

4 files changed

+9
-40
lines changed

drivers/cxl/core/pci.c

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -211,37 +211,6 @@ int cxl_await_media_ready(struct cxl_dev_state *cxlds)
211211
}
212212
EXPORT_SYMBOL_NS_GPL(cxl_await_media_ready, CXL);
213213

214-
static int wait_for_valid(struct pci_dev *pdev, int d)
215-
{
216-
u32 val;
217-
int rc;
218-
219-
/*
220-
* Memory_Info_Valid: When set, indicates that the CXL Range 1 Size high
221-
* and Size Low registers are valid. Must be set within 1 second of
222-
* deassertion of reset to CXL device. Likely it is already set by the
223-
* time this runs, but otherwise give a 1.5 second timeout in case of
224-
* clock skew.
225-
*/
226-
rc = pci_read_config_dword(pdev, d + CXL_DVSEC_RANGE_SIZE_LOW(0), &val);
227-
if (rc)
228-
return rc;
229-
230-
if (val & CXL_DVSEC_MEM_INFO_VALID)
231-
return 0;
232-
233-
msleep(1500);
234-
235-
rc = pci_read_config_dword(pdev, d + CXL_DVSEC_RANGE_SIZE_LOW(0), &val);
236-
if (rc)
237-
return rc;
238-
239-
if (val & CXL_DVSEC_MEM_INFO_VALID)
240-
return 0;
241-
242-
return -ETIMEDOUT;
243-
}
244-
245214
static int cxl_set_mem_enable(struct cxl_dev_state *cxlds, u16 val)
246215
{
247216
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
@@ -322,11 +291,13 @@ static int devm_cxl_enable_hdm(struct device *host, struct cxl_hdm *cxlhdm)
322291
return devm_add_action_or_reset(host, disable_hdm, cxlhdm);
323292
}
324293

325-
int cxl_dvsec_rr_decode(struct device *dev, int d,
294+
int cxl_dvsec_rr_decode(struct device *dev, struct cxl_port *port,
326295
struct cxl_endpoint_dvsec_info *info)
327296
{
328297
struct pci_dev *pdev = to_pci_dev(dev);
298+
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
329299
int hdm_count, rc, i, ranges = 0;
300+
int d = cxlds->cxl_dvsec;
330301
u16 cap, ctrl;
331302

332303
if (!d) {
@@ -353,11 +324,9 @@ int cxl_dvsec_rr_decode(struct device *dev, int d,
353324
if (!hdm_count || hdm_count > 2)
354325
return -EINVAL;
355326

356-
rc = wait_for_valid(pdev, d);
357-
if (rc) {
358-
dev_dbg(dev, "Failure awaiting MEM_INFO_VALID (%d)\n", rc);
327+
rc = cxl_dvsec_mem_range_valid(cxlds, 0);
328+
if (rc)
359329
return rc;
360-
}
361330

362331
/*
363332
* The current DVSEC values are moot if the memory capability is

drivers/cxl/cxl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
811811
int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
812812
struct cxl_endpoint_dvsec_info *info);
813813
int devm_cxl_add_passthrough_decoder(struct cxl_port *port);
814-
int cxl_dvsec_rr_decode(struct device *dev, int dvsec,
814+
int cxl_dvsec_rr_decode(struct device *dev, struct cxl_port *port,
815815
struct cxl_endpoint_dvsec_info *info);
816816

817817
bool is_cxl_region(struct device *dev);

drivers/cxl/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
9898
struct cxl_port *root;
9999
int rc;
100100

101-
rc = cxl_dvsec_rr_decode(cxlds->dev, cxlds->cxl_dvsec, &info);
101+
rc = cxl_dvsec_rr_decode(cxlds->dev, port, &info);
102102
if (rc < 0)
103103
return rc;
104104

tools/testing/cxl/test/mock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
228228
}
229229
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_hdm_decode_init, CXL);
230230

231-
int __wrap_cxl_dvsec_rr_decode(struct device *dev, int dvsec,
231+
int __wrap_cxl_dvsec_rr_decode(struct device *dev, struct cxl_port *port,
232232
struct cxl_endpoint_dvsec_info *info)
233233
{
234234
int rc = 0, index;
@@ -237,7 +237,7 @@ int __wrap_cxl_dvsec_rr_decode(struct device *dev, int dvsec,
237237
if (ops && ops->is_mock_dev(dev))
238238
rc = 0;
239239
else
240-
rc = cxl_dvsec_rr_decode(dev, dvsec, info);
240+
rc = cxl_dvsec_rr_decode(dev, port, info);
241241
put_cxl_mock_ops(index);
242242

243243
return rc;

0 commit comments

Comments
 (0)