Skip to content

Commit 13e68d8

Browse files
daxtensmpe
authored andcommitted
cxl: Allow the kernel to trust that an image won't change on PERST.
Provide a kernel API and a sysfs entry which allow a user to specify that when a card is PERSTed, it's image will stay the same, allowing it to participate in EEH. cxl_reset is used to reflash the card. In that case, we cannot safely assert that the image will not change. Therefore, disallow cxl_reset if the flag is set. Signed-off-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 4e1efb4 commit 13e68d8

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed

Documentation/ABI/testing/sysfs-class-cxl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,13 @@ Description: write only
223223
Writing 1 will issue a PERST to card which may cause the card
224224
to reload the FPGA depending on load_image_on_perst.
225225
Users: https://github.com/ibm-capi/libcxl
226+
227+
What: /sys/class/cxl/<card>/perst_reloads_same_image
228+
Date: July 2015
229+
Contact: linuxppc-dev@lists.ozlabs.org
230+
Description: read/write
231+
Trust that when an image is reloaded via PERST, it will not
232+
have changed.
233+
0 = don't trust, the image may be different (default)
234+
1 = trust that the image will not change.
235+
Users: https://github.com/ibm-capi/libcxl

drivers/misc/cxl/api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,10 @@ int cxl_afu_reset(struct cxl_context *ctx)
327327
return cxl_afu_check_and_enable(afu);
328328
}
329329
EXPORT_SYMBOL_GPL(cxl_afu_reset);
330+
331+
void cxl_perst_reloads_same_image(struct cxl_afu *afu,
332+
bool perst_reloads_same_image)
333+
{
334+
afu->adapter->perst_same_image = perst_reloads_same_image;
335+
}
336+
EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image);

drivers/misc/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct cxl {
493493
bool user_image_loaded;
494494
bool perst_loads_image;
495495
bool perst_select_user;
496+
bool perst_same_image;
496497
};
497498

498499
int cxl_alloc_one_irq(struct cxl *adapter);

drivers/misc/cxl/pci.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,12 @@ int cxl_reset(struct cxl *adapter)
878878
int i;
879879
u32 val;
880880

881+
if (adapter->perst_same_image) {
882+
dev_warn(&dev->dev,
883+
"cxl: refusing to reset/reflash when perst_reloads_same_image is set.\n");
884+
return -EINVAL;
885+
}
886+
881887
dev_info(&dev->dev, "CXL reset\n");
882888

883889
/* pcie_warm_reset requests a fundamental pci reset which includes a
@@ -1151,6 +1157,7 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)
11511157
* configure/reconfigure
11521158
*/
11531159
adapter->perst_loads_image = true;
1160+
adapter->perst_same_image = false;
11541161

11551162
rc = cxl_configure_adapter(adapter, dev);
11561163
if (rc) {

drivers/misc/cxl/sysfs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,38 @@ static ssize_t load_image_on_perst_store(struct device *device,
112112
return count;
113113
}
114114

115+
static ssize_t perst_reloads_same_image_show(struct device *device,
116+
struct device_attribute *attr,
117+
char *buf)
118+
{
119+
struct cxl *adapter = to_cxl_adapter(device);
120+
121+
return scnprintf(buf, PAGE_SIZE, "%i\n", adapter->perst_same_image);
122+
}
123+
124+
static ssize_t perst_reloads_same_image_store(struct device *device,
125+
struct device_attribute *attr,
126+
const char *buf, size_t count)
127+
{
128+
struct cxl *adapter = to_cxl_adapter(device);
129+
int rc;
130+
int val;
131+
132+
rc = sscanf(buf, "%i", &val);
133+
if ((rc != 1) || !(val == 1 || val == 0))
134+
return -EINVAL;
135+
136+
adapter->perst_same_image = (val == 1 ? true : false);
137+
return count;
138+
}
139+
115140
static struct device_attribute adapter_attrs[] = {
116141
__ATTR_RO(caia_version),
117142
__ATTR_RO(psl_revision),
118143
__ATTR_RO(base_image),
119144
__ATTR_RO(image_loaded),
120145
__ATTR_RW(load_image_on_perst),
146+
__ATTR_RW(perst_reloads_same_image),
121147
__ATTR(reset, S_IWUSR, NULL, reset_adapter_store),
122148
};
123149

include/misc/cxl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,14 @@ unsigned int cxl_fd_poll(struct file *file, struct poll_table_struct *poll);
200200
ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
201201
loff_t *off);
202202

203+
/*
204+
* For EEH, a driver may want to assert a PERST will reload the same image
205+
* from flash into the FPGA.
206+
*
207+
* This is a property of the entire adapter, not a single AFU, so drivers
208+
* should set this property with care!
209+
*/
210+
void cxl_perst_reloads_same_image(struct cxl_afu *afu,
211+
bool perst_reloads_same_image);
212+
203213
#endif /* _MISC_CXL_H */

0 commit comments

Comments
 (0)