Skip to content

Commit 594ff7d

Browse files
Christophe LombardFrederic Barrat
authored andcommitted
cxl: Support to flash a new image on the adapter from a guest
The new flash.c file contains the logic to flash a new image on the adapter, through a hcall. It is an iterative process, with chunks of data of 1M at a time. There are also 2 phases: write and verify. The flash operation itself is driven from a user-land tool. Once flashing is successful, an rtas call is made to update the device tree with the new properties values for the adapter and the AFU(s) Add a new char device for the adapter, so that the flash tool can access the card, even if there is no valid AFU on it. Co-authored-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com> Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com> Reviewed-by: Manoj Kumar <manoj@linux.vnet.ibm.com> Acked-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 4752876 commit 594ff7d

8 files changed

Lines changed: 653 additions & 5 deletions

File tree

‎Documentation/powerpc/cxl.txt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Work Element Descriptor (WED)
116116
User API
117117
========
118118

119+
1. AFU character devices
120+
119121
For AFUs operating in AFU directed mode, two character device
120122
files will be created. /dev/cxl/afu0.0m will correspond to a
121123
master context and /dev/cxl/afu0.0s will correspond to a slave
@@ -362,6 +364,59 @@ read
362364
reserved fields:
363365
For future extensions and padding
364366

367+
368+
2. Card character device (powerVM guest only)
369+
370+
In a powerVM guest, an extra character device is created for the
371+
card. The device is only used to write (flash) a new image on the
372+
FPGA accelerator. Once the image is written and verified, the
373+
device tree is updated and the card is reset to reload the updated
374+
image.
375+
376+
open
377+
----
378+
379+
Opens the device and allocates a file descriptor to be used with
380+
the rest of the API. The device can only be opened once.
381+
382+
ioctl
383+
-----
384+
385+
CXL_IOCTL_DOWNLOAD_IMAGE:
386+
CXL_IOCTL_VALIDATE_IMAGE:
387+
Starts and controls flashing a new FPGA image. Partial
388+
reconfiguration is not supported (yet), so the image must contain
389+
a copy of the PSL and AFU(s). Since an image can be quite large,
390+
the caller may have to iterate, splitting the image in smaller
391+
chunks.
392+
393+
Takes a pointer to a struct cxl_adapter_image:
394+
struct cxl_adapter_image {
395+
__u64 flags;
396+
__u64 data;
397+
__u64 len_data;
398+
__u64 len_image;
399+
__u64 reserved1;
400+
__u64 reserved2;
401+
__u64 reserved3;
402+
__u64 reserved4;
403+
};
404+
405+
flags:
406+
These flags indicate which optional fields are present in
407+
this struct. Currently all fields are mandatory.
408+
409+
data:
410+
Pointer to a buffer with part of the image to write to the
411+
card.
412+
413+
len_data:
414+
Size of the buffer pointed to by data.
415+
416+
len_image:
417+
Full size of the image.
418+
419+
365420
Sysfs Class
366421
===========
367422

‎drivers/misc/cxl/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ccflags-$(CONFIG_PPC_WERROR) += -Werror
44
cxl-y += main.o file.o irq.o fault.o native.o
55
cxl-y += context.o sysfs.o debugfs.o pci.o trace.o
66
cxl-y += vphb.o api.o
7-
cxl-$(CONFIG_PPC_PSERIES) += guest.o of.o hcalls.o
7+
cxl-$(CONFIG_PPC_PSERIES) += flash.o guest.o of.o hcalls.o
88
obj-$(CONFIG_CXL) += cxl.o
99
obj-$(CONFIG_CXL_BASE) += base.o
1010

‎drivers/misc/cxl/base.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,10 @@ void unregister_cxl_calls(struct cxl_calls *calls)
8484
synchronize_rcu();
8585
}
8686
EXPORT_SYMBOL_GPL(unregister_cxl_calls);
87+
88+
int cxl_update_properties(struct device_node *dn,
89+
struct property *new_prop)
90+
{
91+
return of_update_property(dn, new_prop);
92+
}
93+
EXPORT_SYMBOL_GPL(cxl_update_properties);

‎drivers/misc/cxl/cxl.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
324324
#define CXL_MODE_TIME_SLICED 0x4
325325
#define CXL_SUPPORTED_MODES (CXL_MODE_DEDICATED | CXL_MODE_DIRECTED)
326326

327+
#define CXL_DEV_MINORS 13 /* 1 control + 4 AFUs * 3 (dedicated/master/shared) */
328+
#define CXL_CARD_MINOR(adapter) (adapter->adapter_num * CXL_DEV_MINORS)
329+
#define CXL_DEVT_ADAPTER(dev) (MINOR(dev) / CXL_DEV_MINORS)
330+
327331
enum cxl_context_status {
328332
CLOSED,
329333
OPENED,
@@ -692,12 +696,14 @@ struct cxl_calls {
692696
};
693697
int register_cxl_calls(struct cxl_calls *calls);
694698
void unregister_cxl_calls(struct cxl_calls *calls);
699+
int cxl_update_properties(struct device_node *dn, struct property *new_prop);
695700

696701
void cxl_remove_adapter_nr(struct cxl *adapter);
697702

698703
int cxl_alloc_spa(struct cxl_afu *afu);
699704
void cxl_release_spa(struct cxl_afu *afu);
700705

706+
dev_t cxl_get_dev(void);
701707
int cxl_file_init(void);
702708
void cxl_file_exit(void);
703709
int cxl_register_adapter(struct cxl *adapter);

‎drivers/misc/cxl/file.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@
2626
#include "trace.h"
2727

2828
#define CXL_NUM_MINORS 256 /* Total to reserve */
29-
#define CXL_DEV_MINORS 13 /* 1 control + 4 AFUs * 3 (dedicated/master/shared) */
3029

31-
#define CXL_CARD_MINOR(adapter) (adapter->adapter_num * CXL_DEV_MINORS)
3230
#define CXL_AFU_MINOR_D(afu) (CXL_CARD_MINOR(afu->adapter) + 1 + (3 * afu->slice))
3331
#define CXL_AFU_MINOR_M(afu) (CXL_AFU_MINOR_D(afu) + 1)
3432
#define CXL_AFU_MINOR_S(afu) (CXL_AFU_MINOR_D(afu) + 2)
3533
#define CXL_AFU_MKDEV_D(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_D(afu))
3634
#define CXL_AFU_MKDEV_M(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_M(afu))
3735
#define CXL_AFU_MKDEV_S(afu) MKDEV(MAJOR(cxl_dev), CXL_AFU_MINOR_S(afu))
3836

39-
#define CXL_DEVT_ADAPTER(dev) (MINOR(dev) / CXL_DEV_MINORS)
4037
#define CXL_DEVT_AFU(dev) ((MINOR(dev) % CXL_DEV_MINORS - 1) / 3)
4138

4239
#define CXL_DEVT_IS_CARD(dev) (MINOR(dev) % CXL_DEV_MINORS == 0)
@@ -446,7 +443,8 @@ static const struct file_operations afu_master_fops = {
446443

447444
static char *cxl_devnode(struct device *dev, umode_t *mode)
448445
{
449-
if (CXL_DEVT_IS_CARD(dev->devt)) {
446+
if (cpu_has_feature(CPU_FTR_HVMODE) &&
447+
CXL_DEVT_IS_CARD(dev->devt)) {
450448
/*
451449
* These minor numbers will eventually be used to program the
452450
* PSL and AFUs once we have dynamic reprogramming support
@@ -547,6 +545,11 @@ int cxl_register_adapter(struct cxl *adapter)
547545
return device_register(&adapter->dev);
548546
}
549547

548+
dev_t cxl_get_dev(void)
549+
{
550+
return cxl_dev;
551+
}
552+
550553
int __init cxl_file_init(void)
551554
{
552555
int rc;

0 commit comments

Comments
 (0)