add Intel Stratix10 remote system update driver
v3 cover add Intel Stratix10 remote system update driver
From: Richard Gong <[email protected]>
Since version 2 submission is too late for kernel 5.2, I submit version 3 of Intel Stratix10 Remote System Update (RSU) drive for kernel 5.3.
There is only one additional change in version 3 patch sets, which updates kernel version to 5.3 in sysfs interface document.
Intel Stratix10 remote system update driver patches have been reviewed by Alan Tull and other colleagues at Intel.
The Intel Stratix10 Remote System Update driver exposes interfaces access through the Intel Stratix10 Service Layer to user space via sysfs interface. The RSU interfaces report and control some of the optional RSU features on Intel Stratix 10 SoC.
The RSU feature provides a way for customers to update the boot configuration of a Intel Stratix 10 SoC device with significantly reduced risk of corrupting the bitstream storage and bricking the system.
v3: changed kernel version from 5.2 to 5.3 in RSU sysfs interface document
v2: removed compatible = "intel,stratix10-rsu"
added intel stratix10 RSU device
changed to support RSU in handling watchdog timeout s/attr_group/ATTRIBUTE_GROUPS, use devm_device_add_groups() and devm_device_remove_groups()
added check the return value from rsu_send_msg()
removed RSU binding text file
other corrections/changes
Richard Gong (4):
firmware: stratix10-svc: extend svc to support RSU notify and WD
features
firmware: add Intel Stratix10 remote system update driver
firmware: rsu: document sysfs interface
MAINTAINERS: add maintainer for Intel Stratix10 FW drivers
.../testing/sysfs-devices-platform-stratix10-rsu | 100 +++++ MAINTAINERS | 11 + drivers/firmware/Kconfig | 18 + drivers/firmware/Makefile | 1 + drivers/firmware/stratix10-rsu.c | 409 +++++++++++++++++++++ drivers/firmware/stratix10-svc.c | 74 +++- include/linux/firmware/intel/stratix10-smc.h | 48 ++- .../linux/firmware/intel/stratix10-svc-client.h | 12 +- 8 files changed, 663 insertions(+), 10 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu create mode 100644 drivers/firmware/stratix10-rsu.c
Signature · 1 line
2.7.4
PATCH v3 1/4 firmware: stratix10-svc: extend svc to support RSU notify and WD features
From: Richard Gong <[email protected]>
Entend Intel Stratix10 service layer driver to support RSU notify and watchdog timeout features.
RSU is used to provide our customers with protection against loading bad bitstream onto their devices when those devices are booting from flash
RSU notifies provides users with an API to notify the firmware of the state of hard processor system.
RSU instructs firmware what to do when rebooting due to a watchdog timer expiration, the firmware can reboot with the current running image or reboot with the normal RSU flow.
---
v2: changed to add intel stratix10 RSU device
changed to support RSU in handling a watchdog timeout
v3: no change
--- drivers/firmware/stratix10-svc.c | 74 +++++++++++++++++++++- include/linux/firmware/intel/stratix10-smc.h | 48 ++++++++++++-- .../linux/firmware/intel/stratix10-svc-client.h | 12 +++- 3 files changed, 124 insertions(+), 10 deletions(-)
drivers/firmware/stratix10-svc.c +71 -3
@@ -38,6 +38,9 @@#define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 200#define FPGA_CONFIG_STATUS_TIMEOUT_SEC 30 +/* stratix10 service layer clients */ +#define STRATIX10_RSU "stratix10-rsu" + typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long,
@@ -45,6 +48,14 @@ typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long,struct stratix10_svc_chan ;/** +* struct stratix10_svc - svc private data +* @stratix10_svc_rsu: pointer to stratix10 RSU device +*/ +struct stratix10_svc { +struct platform_device *stratix10_svc_rsu; +}; + +/** * struct stratix10_svc_sh_memory - service shared memory structure * @sync_complete: state for a completion * @addr: physical address of shared memory block
@@ -295,7 +306,10 @@ static void svc_thread_recv_status_ok(struct stratix10_svc_data *p_data,case COMMAND_RECONFIG_STATUS : cb_data->status =BIT (SVC_STATUS_RECONFIG_COMPLETED );break ; +case COMMAND_RSU_STATUS :case COMMAND_RSU_UPDATE : +case COMMAND_RSU_NOTIFY : +case COMMAND_RSU_WD : cb_data->status =BIT (SVC_STATUS_RSU_OK );break ;default :
@@ -386,6 +400,16 @@ static int svc_normal_to_secure_thread(void *data) a1 = pdata->arg[0 ]; a2 =0 ;break ; +case COMMAND_RSU_NOTIFY : + a0 =INTEL_SIP_SMC_RSU_NOTIFY ; + a1 = pdata->arg[0 ]; + a2 =0 ; +break ; +case COMMAND_RSU_WD : + a0 =INTEL_SIP_SMC_RSU_WD ; + a1 = pdata->arg[0 ]; + a2 =0 ; +break ;default :pr_warn ("it shouldn't happen\n" );break ;
@@ -438,7 +462,28 @@ static int svc_normal_to_secure_thread(void *data)pr_debug ("%s: STATUS_REJECTED\n" , __func__);break ;case INTEL_SIP_SMC_FPGA_CONFIG_STATUS_ERROR : +case INTEL_SIP_SMC_RSU_ERROR :pr_err ("%s: STATUS_ERROR\n" , __func__); +switch (pdata->command) { +/* for FPGA mgr */ +case COMMAND_RECONFIG_DATA_CLAIM : +case COMMAND_RECONFIG : +case COMMAND_RECONFIG_DATA_SUBMIT : +case COMMAND_RECONFIG_STATUS : + cbdata->status = +BIT (SVC_STATUS_RECONFIG_ERROR ); +break ; + +/* for RSU */ +case COMMAND_RSU_STATUS : +case COMMAND_RSU_UPDATE : +case COMMAND_RSU_NOTIFY : +case COMMAND_RSU_WD : + cbdata->status = +BIT (SVC_STATUS_RSU_ERROR ); +break ; + } + cbdata->status =BIT (SVC_STATUS_RECONFIG_ERROR ); cbdata->kaddr1 =NULL ; cbdata->kaddr2 =NULL ;
@@ -530,7 +575,7 @@ static int svc_get_sh_memory(struct platform_device *pdev,if (!sh_memory->addr || !sh_memory->size) {dev_err (dev, -"fails to get shared memory info from secure world\n" ); +"failed to get shared memory info from secure world\n" );return -ENOMEM ; }
@@ -768,7 +813,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg) "svc_smc_hvc_thread");if (IS_ERR (chan->ctrl->task)) {dev_err (chan->ctrl->dev, -"fails to create svc_smc_hvc_thread\n" ); +"failed to create svc_smc_hvc_thread\n" );kfree (p_data);return -EINVAL ; }
@@ -913,6 +958,8 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)struct stratix10_svc_chan *chans;struct gen_pool *genpool;struct stratix10_svc_sh_memory *sh_memory; +struct stratix10_svc *svc; +svc_invoke_fn *invoke_fn;size_t fifo_size;int ret;
@@ -957,7 +1004,7 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev) fifo_size =sizeof (struct stratix10_svc_data ) *SVC_NUM_DATA_IN_FIFO ; ret =kfifo_alloc (&controller->svc_fifo, fifo_size,GFP_KERNEL );if (ret) { -dev_err (dev,"fails to allocate FIFO\n" ); +dev_err (dev,"failed to allocate FIFO\n" );return ret; }spin_lock_init (&controller->svc_fifo_lock);
@@ -975,6 +1022,24 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)list_add_tail (&controller->node, &svc_ctrl);platform_set_drvdata (pdev, controller); +/* add svc client device(s) */ + svc =devm_kzalloc (dev,sizeof (*svc),GFP_KERNEL ); +if (!svc) +return -ENOMEM ; + + svc->stratix10_svc_rsu =platform_device_alloc (STRATIX10_RSU ,0 ); +if (!svc->stratix10_svc_rsu) { +dev_err (dev,"failed to allocate %s device\n" ,STRATIX10_RSU ); +return -ENOMEM ; + } + + ret =platform_device_add (svc->stratix10_svc_rsu); +if (ret) { +platform_device_put (svc->stratix10_svc_rsu); +return ret; + } +dev_set_drvdata (dev, svc); +pr_info ("Intel Service Layer Driver Initialized\n" );return ret;
@@ -982,8 +1047,11 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)static int stratix10_svc_drv_remove (struct platform_device *pdev) { +struct stratix10_svc *svc =dev_get_drvdata (&pdev->dev);struct stratix10_svc_controller *ctrl =platform_get_drvdata (pdev); +platform_device_unregister (svc->stratix10_svc_rsu); +kfifo_free (&ctrl->svc_fifo);if (ctrl->task) {kthread_stop (ctrl->task);
include/linux/firmware/intel/stratix10-smc.h +42 -6
87 lines not on this page · raw message
include/linux/firmware/intel/stratix10-svc-client.h +11 -1
@@ -95,6 +95,14 @@ struct stratix10_svc_chan;* * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot, * return status is SVC_STATUS_RSU_OK or SVC_STATUS_RSU_ERROR +* +* @COMMAND_RSU_NOTIFY: report the status of hard processor system +* software to firmware, return status is SVC_STATUS_RSU_OK or +* SVC_STATUS_RSU_ERROR +* +* @COMMAND_RSU_WD: instruct firmware what to do when rebooting due to a +* watchdog timer expiration, return status is SVC_STATUS_RSU_OK or +* SVC_STATUS_RSU_ERROR */ enum stratix10_svc_command_code {COMMAND_NOOP =0 ,
@@ -103,7 +111,9 @@ enum stratix10_svc_command_code {COMMAND_RECONFIG_DATA_CLAIM ,COMMAND_RECONFIG_STATUS ,COMMAND_RSU_STATUS , - COMMAND_RSU_UPDATE +COMMAND_RSU_UPDATE , +COMMAND_RSU_NOTIFY , + COMMAND_RSU_WD, };/**
Signature · 1 line
2.7.4
PATCH v3 2/4 firmware: add Intel Stratix10 remote system update driver
In reply to [email protected]From: Richard Gong <[email protected]>
The Intel Remote System Update (RSU) driver exposes interfaces access through the Intel Service Layer to user space via sysfs interface. The RSU interfaces report and control some of the optional RSU features on Intel Stratix 10 SoC.
The RSU feature provides a way for customers to update the boot configuration of a Intel Stratix 10 SoC device with significantly reduced risk of corrupting the bitstream storage and bricking the system.
---
v2: s/SysFS/sysfs, s/scnprintf/sprintf,
s/attr_group/ATTRIBUTE_GROUPS, use devm_device_add_groups() and devm_device_remove_groups()
added check the return value from rsu_send_msg() removed a pr_info in stratix10_rsu_probe()
removed compatible = "intel,stratix10-rsu"
v3: no change
--- drivers/firmware/Kconfig | 18 ++ drivers/firmware/Makefile | 1 + drivers/firmware/stratix10-rsu.c | 409 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 428 insertions(+) create mode 100644 drivers/firmware/stratix10-rsu.c
drivers/firmware/Kconfig +18 -0
@@ -214,6 +214,24 @@ config INTEL_STRATIX10_SERVICE Say Y here if you want Stratix10 service layer support. +config INTEL_STRATIX10_RSU + tristate "Intel Stratix10 Remote System Update" + depends on INTEL_STRATIX10_SERVICE + help + The Intel Remote System Update (RSU) driver exposes interfaces + access through the Intel Service Layer to user space via sysfs + device attribute nodes. The RSU interfaces report/control some of + the optional RSU features of the Stratix 10 SoC FPGA. + + The RSU provides a way for customers to update the boot + configuration of a Stratix 10 SoC device with significantly reduced + risk of corrupting the bitstream storage and bricking the system. + + Enable RSU support if you are using an Intel SoC FPGA with the RSU + feature enabled and you want Linux user space control. + + Say Y here if you want Intel RSU support. + config QCOM_SCM bool depends on ARM || ARM64
drivers/firmware/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_PCDP) += pcdp.o obj-$(CONFIG_DMIID) += dmi-id.o obj-$(CONFIG_INTEL_STRATIX10_SERVICE) += stratix10-svc.o +obj-$(CONFIG_INTEL_STRATIX10_RSU) += stratix10-rsu.o obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o
drivers/firmware/stratix10-rsu.c new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCHv3 2/4] firmware: add Intel Stratix10 remote system update driver
Quoted 45 lines · On Thu, May 23, 2019 at 08:03:28AM -0500, [email protected] wrote:
drivers/firmware/stratix10-rsu.c new file +45
-0+static int stratix10_rsu_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct stratix10_rsu_priv *priv; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->client.dev = dev; + priv->client.receive_cb =NULL ; + priv->client.priv = priv; + priv->status.current_image =0 ; + priv->status.fail_image =0 ; + priv->status.error_location =0 ; + priv->status.error_details =0 ; + priv->status.version =0 ; + priv->status.state =0 ; + +mutex_init (&priv->lock); + priv->chan =stratix10_svc_request_channel_byname (&priv->client, +SVC_CLIENT_RSU ); +if (IS_ERR (priv->chan)) { +dev_err (dev,"couldn't get service channel %s\n" , +SVC_CLIENT_RSU ); +return PTR_ERR (priv->chan); + } + +init_completion (&priv->completion); +platform_set_drvdata (pdev, priv); + +/* status is only updated after reboot */ + ret =rsu_send_msg (priv,COMMAND_RSU_STATUS , +0 , rsu_status_callback); +if (ret) { +dev_err (dev,"Error, getting RSU status %i\n" , ret); +stratix10_svc_free_channel (priv->chan); + } + + ret =devm_device_add_groups (dev, rsu_groups); +if (ret) { +dev_err (dev,"unable to create sysfs group" ); +stratix10_svc_free_channel (priv->chan); + }
drivers/firmware/stratix10-rsu.c line 393
Quoted 10 lines
drivers/firmware/stratix10-rsu.c new file +10
-0+ +return ret; +} + +static int stratix10_rsu_remove (struct platform_device *pdev) +{ +struct stratix10_rsu_priv *priv =platform_get_drvdata (pdev); + +stratix10_svc_free_channel (priv->chan); +devm_device_remove_groups (&pdev->dev, rsu_groups);
When you are the only caller of a function in the kernel, that's a HUGE flag that maybe you should not be calling it...
Which reminds me, I need to go remove this...
Anyway, no, don't do this, you are racing userspace with your sysfs files. Reference the groups in the platform_driver structure and the driver core will properly create, and remove, them for you, and userspace will be happy they show up at the correct time.
This also makes your probe/remove function smaller.
thanks,
greg k-h
PATCH v3 3/4 firmware: rsu: document sysfs interface
In reply to [email protected]From: Richard Gong <[email protected]>
Describe Intel Stratix10 Remote System Update (RSU) device attributes
---
v2: changed to use tab everywhere and wrap lines at 72 colums
s/soc:firmware:svc:rsu/stratix10-rsu.0
added for watchdog
v3: s/KernelVersion:5.2/KernelVersion:5.3
--- .../testing/sysfs-devices-platform-stratix10-rsu | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu
Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu new file +100 -0
@@ -0,0 +1,100 @@ + Intel Stratix10 Remote System Update (RSU) device attributes + +What: /sys/devices/platform/stratix10-rsu.0/current_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the address of image currently running in flash. + +What: /sys/devices/platform/stratix10-rsu.0/fail_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the address of failed image in flash. + +What: /sys/devices/platform/stratix10-rsu.0/state +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the state of RSU system. + The state field has two parts: major error code in upper 16 bits and + minor error code in lower 16 bits. + + Major error code: + 0xF001 bitstream error + 0xF002 hardware access failure + 0xF003 bitstream corruption + 0xF004 internal error + 0xF005 device error + 0xF006 CPU watchdog timeout + 0xF007 internal unknown error + Minor error code: + Currently used only when major error is 0xF006 + (CPU watchdog timeout), in which case the minor + error code is the value reported by CPU to + firmware through the RSU notify command before + the watchdog timeout occurs. + +What: /sys/devices/platform/stratix10-rsu.0/fail_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the version number of RSU firmware. + +What: /sys/devices/platform/stratix10-rsu.0/error_location +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the error offset inside the image that failed. + +What: /sys/devices/platform/stratix10-rsu.0/error_details +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) error code. + +What: /sys/devices/platform/stratix10-rsu.0/reboot_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (WO) the address of image to be loaded on next reboot command. + +What: /sys/devices/platform/stratix10-rsu.0/notify +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (WO) inform firmware that the current software state as + a 16-bit numerical value below: + 0 is for the first stage bootloader didn't run + or didn't reach the point of launching second + stage bootloader. + 1 is for failed in second bootloader or didn't + get to the point of launching the operating + system. + 2 is for both first and second stage bootloader + ran and the operating system launch was + attempted. + +What: /sys/devices/platform/stratix10-rsu.0/watchdog +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (WO) instruct firmware what to do when rebooting due to + a watchdog timer expiration. The attribute takes a + 32 bits word as the parameter indicating the action for + firmware to take: + + b[0] is set to 0, the firmware should reboot + with the normal RSU flow. + b[0] is set to 1, the firmware shall always + reboot with the current running image. + b[31:1] reserved.
Signature · 1 line
2.7.4
Re: [PATCHv3 3/4] firmware: rsu: document sysfs interface
Quoted 66 lines · On Thu, May 23, 2019 at 08:03:29AM -0500, [email protected] wrote:
From: Richard Gong <[email protected]>
Describe Intel Stratix10 Remote System Update (RSU) device attributes
Signed-off-by Richard Gong <[email protected]>Reviewed-by Alan Tull <[email protected]>---
v2: changed to use tab everywhere and wrap lines at 72 colums
s/soc:firmware:svc:rsu/stratix10-rsu.0
added for watchdog
v3: s/KernelVersion:5.2/KernelVersion:5.3--- .../testing/sysfs-devices-platform-stratix10-rsu | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsuDocumentation/ABI/testing/sysfs-devices-platform-stratix10-rsu new file +44
-0@@ -0,0 +1,100 @@ + Intel Stratix10 Remote System Update (RSU) device attributes + +What: /sys/devices/platform/stratix10-rsu.0/current_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the address of image currently running in flash. + +What: /sys/devices/platform/stratix10-rsu.0/fail_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the address of failed image in flash. + +What: /sys/devices/platform/stratix10-rsu.0/state +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the state of RSU system. + The state field has two parts: major error code in upper 16 bits and + minor error code in lower 16 bits. + + Major error code: + 0xF001 bitstream error + 0xF002 hardware access failure + 0xF003 bitstream corruption + 0xF004 internal error + 0xF005 device error + 0xF006 CPU watchdog timeout + 0xF007 internal unknown error + Minor error code: + Currently used only when major error is 0xF006 + (CPU watchdog timeout), in which case the minor + error code is the value reported by CPU to + firmware through the RSU notify command before + the watchdog timeout occurs. + +What: /sys/devices/platform/stratix10-rsu.0/fail_image +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]>
Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu line 54
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu new file +10
-0+Description: + (RO) the version number of RSU firmware. + +What: /sys/devices/platform/stratix10-rsu.0/error_location +Date: May 2019 +KernelVersion: 5.3 +Contact: Richard Gong <[email protected]> +Description: + (RO) the error offset inside the image that failed. +
You are mixing tabs and spaces in this file. Please always just use tabs.
thanks,
greg k-h
PATCH v3 4/4 MAINTAINERS: add maintainer for Intel Stratix10 FW drivers
In reply to [email protected]From: Richard Gong <[email protected]>
Add myself as maintainer for the newly created Intel Stratix10 firmware drivers.
---
v2: removed RSU binding text file
v3: no change
--- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
@@ -8101,6 +8101,17 @@ S: Supported F: drivers/infiniband/hw/i40iw/ F: include/uapi/rdma/i40iw-abi.h +INTEL STRATIX10 FIRMWARE DRIVERS +M: Richard Gong <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/stratix10-rsu.c +F: drivers/firmware/stratix10-svc.c +F: include/linux/firmware/intel/stratix10-smc.h +F: include/linux/firmware/intel/stratix10-svc-client.h +F: Documentation/ABI/testing/sysfs-devices-platform-stratix10-rsu +F: Documentation/devicetree/bindings/firmware/intel,stratix10-svc.txt + INTEL TELEMETRY DRIVER M: Rajneesh Bhardwaj <[email protected]> M: "David E. Box" <[email protected]>
Signature · 1 line
2.7.4