Skip to content

Commit 4beb542

Browse files
Ryan Grimmmpe
authored andcommitted
cxl: Use image state defaults for reloading FPGA
Select defaults such that a PERST causes flash image reload. Select which image based on what the card is set up to load. CXL_VSEC_PERST_LOADS_IMAGE selects whether PERST assertion causes flash image load. CXL_VSEC_PERST_SELECT_USER selects which image is loaded on the next PERST. cxl_update_image_control writes these bits into the VSEC. Signed-off-by: Ryan Grimm <[email protected]> Acked-by: Ian Munsie <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 49fd644 commit 4beb542

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

drivers/misc/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ void cxl_release_one_irq(struct cxl *adapter, int hwirq);
488488
int cxl_alloc_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter, unsigned int num);
489489
void cxl_release_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter);
490490
int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq, unsigned int virq);
491+
int cxl_update_image_control(struct cxl *adapter);
491492

492493
/* common == phyp + powernv */
493494
struct cxl_process_element_common {

drivers/misc/cxl/pci.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,41 @@ int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq,
361361
return pnv_cxl_ioda_msi_setup(dev, hwirq, virq);
362362
}
363363

364+
int cxl_update_image_control(struct cxl *adapter)
365+
{
366+
struct pci_dev *dev = to_pci_dev(adapter->dev.parent);
367+
int rc;
368+
int vsec;
369+
u8 image_state;
370+
371+
if (!(vsec = find_cxl_vsec(dev))) {
372+
dev_err(&dev->dev, "ABORTING: CXL VSEC not found!\n");
373+
return -ENODEV;
374+
}
375+
376+
if ((rc = CXL_READ_VSEC_IMAGE_STATE(dev, vsec, &image_state))) {
377+
dev_err(&dev->dev, "failed to read image state: %i\n", rc);
378+
return rc;
379+
}
380+
381+
if (adapter->perst_loads_image)
382+
image_state |= CXL_VSEC_PERST_LOADS_IMAGE;
383+
else
384+
image_state &= ~CXL_VSEC_PERST_LOADS_IMAGE;
385+
386+
if (adapter->perst_select_user)
387+
image_state |= CXL_VSEC_PERST_SELECT_USER;
388+
else
389+
image_state &= ~CXL_VSEC_PERST_SELECT_USER;
390+
391+
if ((rc = CXL_WRITE_VSEC_IMAGE_STATE(dev, vsec, image_state))) {
392+
dev_err(&dev->dev, "failed to update image control: %i\n", rc);
393+
return rc;
394+
}
395+
396+
return 0;
397+
}
398+
364399
int cxl_alloc_one_irq(struct cxl *adapter)
365400
{
366401
struct pci_dev *dev = to_pci_dev(adapter->dev.parent);
@@ -770,8 +805,8 @@ static int cxl_read_vsec(struct cxl *adapter, struct pci_dev *dev)
770805
CXL_READ_VSEC_BASE_IMAGE(dev, vsec, &adapter->base_image);
771806
CXL_READ_VSEC_IMAGE_STATE(dev, vsec, &image_state);
772807
adapter->user_image_loaded = !!(image_state & CXL_VSEC_USER_IMAGE_LOADED);
773-
adapter->perst_loads_image = !!(image_state & CXL_VSEC_PERST_LOADS_IMAGE);
774-
adapter->perst_select_user = !!(image_state & CXL_VSEC_PERST_SELECT_USER);
808+
adapter->perst_loads_image = true;
809+
adapter->perst_select_user = !!(image_state & CXL_VSEC_USER_IMAGE_LOADED);
775810

776811
CXL_READ_VSEC_NAFUS(dev, vsec, &adapter->slices);
777812
CXL_READ_VSEC_AFU_DESC_OFF(dev, vsec, &afu_desc_off);
@@ -879,6 +914,9 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)
879914
if ((rc = cxl_vsec_looks_ok(adapter, dev)))
880915
goto err2;
881916

917+
if ((rc = cxl_update_image_control(adapter)))
918+
goto err2;
919+
882920
if ((rc = cxl_map_adapter_regs(adapter, dev)))
883921
goto err2;
884922

0 commit comments

Comments
 (0)