Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'riscv-soc-drivers-for-v6.8' of https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux into soc/drivers

RISC-V SoC drivers for v6.8

There's only one set of changes here, the addition of "Auto Update"
support for PolarFire SoC. Auto Update is one of the ways that the FPGA
bitstream can be updated, and the only one suitable for use from Linux
as it does not immediately initiate a reboot when started.
The driver was not accepted in the FPGA manager subsystem as the update
only occurs after a reboot and makes no use of the FPGA manager
framework.

Signed-off-by: Conor Dooley <conor.dooley@microchip.com>

* tag 'riscv-soc-drivers-for-v6.8' of https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux:
MAINTAINERS: add auto-update driver to mpfs entry
firmware: microchip: Replace of_device.h with explicit include
firmware: microchip: add PolarFire SoC Auto Update support
soc: microchip: mpfs: add auto-update subdev to system controller
soc: microchip: mpfs: print service status in warning message
soc: microchip: mpfs: enable access to the system controller's flash
dt-bindings: soc: microchip: add a property for system controller flash
firmware_loader: Expand Firmware upload error codes with firmware invalid error

Link: https://lore.kernel.org/r/20231221-droop-unblock-81e4fe14acee@spud
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+559 -3
+10
Documentation/devicetree/bindings/soc/microchip/microchip,mpfs-sys-controller.yaml
··· 26 26 compatible: 27 27 const: microchip,mpfs-sys-controller 28 28 29 + microchip,bitstream-flash: 30 + $ref: /schemas/types.yaml#/definitions/phandle 31 + description: 32 + The SPI flash connected to the system controller's QSPI controller. 33 + The system controller may retrieve FPGA bitstreams from this flash to 34 + perform In-Application Programming (IAP) or during device initialisation 35 + for Auto Update. The MSS and system controller have separate QSPI 36 + controllers and this flash is connected to both. Software running in the 37 + MSS can write bitstreams to the flash. 38 + 29 39 required: 30 40 - compatible 31 41 - mboxes
+1
MAINTAINERS
··· 18638 18638 F: arch/riscv/boot/dts/microchip/ 18639 18639 F: drivers/char/hw_random/mpfs-rng.c 18640 18640 F: drivers/clk/microchip/clk-mpfs*.c 18641 + F: drivers/firmware/microchip/mpfs-auto-update.c 18641 18642 F: drivers/i2c/busses/i2c-microchip-corei2c.c 18642 18643 F: drivers/mailbox/mailbox-mpfs.c 18643 18644 F: drivers/pci/controller/pcie-microchip-host.c
+1
drivers/base/firmware_loader/sysfs_upload.c
··· 27 27 [FW_UPLOAD_ERR_INVALID_SIZE] = "invalid-file-size", 28 28 [FW_UPLOAD_ERR_RW_ERROR] = "read-write-error", 29 29 [FW_UPLOAD_ERR_WEAROUT] = "flash-wearout", 30 + [FW_UPLOAD_ERR_FW_INVALID] = "firmware-invalid", 30 31 }; 31 32 32 33 static const char *fw_upload_progress(struct device *dev,
+1
drivers/firmware/Kconfig
··· 272 272 source "drivers/firmware/efi/Kconfig" 273 273 source "drivers/firmware/imx/Kconfig" 274 274 source "drivers/firmware/meson/Kconfig" 275 + source "drivers/firmware/microchip/Kconfig" 275 276 source "drivers/firmware/psci/Kconfig" 276 277 source "drivers/firmware/qcom/Kconfig" 277 278 source "drivers/firmware/smccc/Kconfig"
+1
drivers/firmware/Makefile
··· 28 28 obj-y += broadcom/ 29 29 obj-y += cirrus/ 30 30 obj-y += meson/ 31 + obj-y += microchip/ 31 32 obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ 32 33 obj-y += efi/ 33 34 obj-y += imx/
+12
drivers/firmware/microchip/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + config POLARFIRE_SOC_AUTO_UPDATE 4 + tristate "Microchip PolarFire SoC AUTO UPDATE" 5 + depends on POLARFIRE_SOC_SYS_CTRL 6 + select FW_LOADER 7 + select FW_UPLOAD 8 + help 9 + Support for reprogramming PolarFire SoC from within Linux, using the 10 + Auto Upgrade feature of the system controller. 11 + 12 + If built as a module, it will be called mpfs-auto-update.
+3
drivers/firmware/microchip/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + obj-$(CONFIG_POLARFIRE_SOC_AUTO_UPDATE) += mpfs-auto-update.o
+494
drivers/firmware/microchip/mpfs-auto-update.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Microchip Polarfire SoC "Auto Update" FPGA reprogramming. 4 + * 5 + * Documentation of this functionality is available in the "PolarFire® FPGA and 6 + * PolarFire SoC FPGA Programming" User Guide. 7 + * 8 + * Copyright (c) 2022-2023 Microchip Corporation. All rights reserved. 9 + * 10 + * Author: Conor Dooley <conor.dooley@microchip.com> 11 + */ 12 + #include <linux/debugfs.h> 13 + #include <linux/firmware.h> 14 + #include <linux/math.h> 15 + #include <linux/module.h> 16 + #include <linux/mtd/mtd.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/sizes.h> 19 + 20 + #include <soc/microchip/mpfs.h> 21 + 22 + #define AUTO_UPDATE_DEFAULT_MBOX_OFFSET 0u 23 + #define AUTO_UPDATE_DEFAULT_RESP_OFFSET 0u 24 + 25 + #define AUTO_UPDATE_FEATURE_CMD_OPCODE 0x05u 26 + #define AUTO_UPDATE_FEATURE_CMD_DATA_SIZE 0u 27 + #define AUTO_UPDATE_FEATURE_RESP_SIZE 33u 28 + #define AUTO_UPDATE_FEATURE_CMD_DATA NULL 29 + #define AUTO_UPDATE_FEATURE_ENABLED BIT(5) 30 + 31 + #define AUTO_UPDATE_AUTHENTICATE_CMD_OPCODE 0x22u 32 + #define AUTO_UPDATE_AUTHENTICATE_CMD_DATA_SIZE 0u 33 + #define AUTO_UPDATE_AUTHENTICATE_RESP_SIZE 1u 34 + #define AUTO_UPDATE_AUTHENTICATE_CMD_DATA NULL 35 + 36 + #define AUTO_UPDATE_PROGRAM_CMD_OPCODE 0x46u 37 + #define AUTO_UPDATE_PROGRAM_CMD_DATA_SIZE 0u 38 + #define AUTO_UPDATE_PROGRAM_RESP_SIZE 1u 39 + #define AUTO_UPDATE_PROGRAM_CMD_DATA NULL 40 + 41 + /* 42 + * SPI Flash layout example: 43 + * |------------------------------| 0x0000000 44 + * | 1 KiB | 45 + * | SPI "directories" | 46 + * |------------------------------| 0x0000400 47 + * | 1 MiB | 48 + * | Reserved area | 49 + * | Used for bitstream info | 50 + * |------------------------------| 0x0100400 51 + * | 20 MiB | 52 + * | Golden Image | 53 + * |------------------------------| 0x1500400 54 + * | 20 MiB | 55 + * | Auto Upgrade Image | 56 + * |------------------------------| 0x2900400 57 + * | 20 MiB | 58 + * | Reserved for multi-image IAP | 59 + * | Unused for Auto Upgrade | 60 + * |------------------------------| 0x3D00400 61 + * | ? B | 62 + * | Unused | 63 + * |------------------------------| 0x? 64 + */ 65 + #define AUTO_UPDATE_DIRECTORY_BASE 0u 66 + #define AUTO_UPDATE_DIRECTORY_WIDTH 4u 67 + #define AUTO_UPDATE_GOLDEN_INDEX 0u 68 + #define AUTO_UPDATE_UPGRADE_INDEX 1u 69 + #define AUTO_UPDATE_BLANK_INDEX 2u 70 + #define AUTO_UPDATE_GOLDEN_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UPDATE_GOLDEN_INDEX) 71 + #define AUTO_UPDATE_UPGRADE_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UPDATE_UPGRADE_INDEX) 72 + #define AUTO_UPDATE_BLANK_DIRECTORY (AUTO_UPDATE_DIRECTORY_WIDTH * AUTO_UPDATE_BLANK_INDEX) 73 + #define AUTO_UPDATE_DIRECTORY_SIZE SZ_1K 74 + #define AUTO_UPDATE_RESERVED_SIZE SZ_1M 75 + #define AUTO_UPDATE_BITSTREAM_BASE (AUTO_UPDATE_DIRECTORY_SIZE + AUTO_UPDATE_RESERVED_SIZE) 76 + 77 + #define AUTO_UPDATE_TIMEOUT_MS 60000 78 + 79 + struct mpfs_auto_update_priv { 80 + struct mpfs_sys_controller *sys_controller; 81 + struct device *dev; 82 + struct mtd_info *flash; 83 + struct fw_upload *fw_uploader; 84 + struct completion programming_complete; 85 + size_t size_per_bitstream; 86 + bool cancel_request; 87 + }; 88 + 89 + static enum fw_upload_err mpfs_auto_update_prepare(struct fw_upload *fw_uploader, const u8 *data, 90 + u32 size) 91 + { 92 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 93 + size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE; 94 + 95 + /* 96 + * Verifying the Golden Image is idealistic. It will be evaluated 97 + * against the currently programmed image and thus may fail - due to 98 + * either rollback protection (if its an older version than that in use) 99 + * or if the version is the same as that of the in-use image. 100 + * Extracting the information as to why a failure occurred is not 101 + * currently possible due to limitations of the system controller 102 + * driver. If those are fixed, verification of the Golden Image should 103 + * be added here. 104 + */ 105 + 106 + priv->flash = mpfs_sys_controller_get_flash(priv->sys_controller); 107 + if (!priv->flash) 108 + return FW_UPLOAD_ERR_HW_ERROR; 109 + 110 + erase_size = round_up(erase_size, (u64)priv->flash->erasesize); 111 + 112 + /* 113 + * We need to calculate if we have enough space in the flash for the 114 + * new image. 115 + * First, chop off the first 1 KiB as it's reserved for the directory. 116 + * The 1 MiB reserved for design info needs to be ignored also. 117 + * All that remains is carved into 3 & rounded down to the erasesize. 118 + * If this is smaller than the image size, we abort. 119 + * There's also no need to consume more than 20 MiB per image. 120 + */ 121 + priv->size_per_bitstream = priv->flash->size - SZ_1K - SZ_1M; 122 + priv->size_per_bitstream = round_down(priv->size_per_bitstream / 3, erase_size); 123 + if (priv->size_per_bitstream > 20 * SZ_1M) 124 + priv->size_per_bitstream = 20 * SZ_1M; 125 + 126 + if (priv->size_per_bitstream < size) { 127 + dev_err(priv->dev, 128 + "flash device has insufficient capacity to store this bitstream\n"); 129 + return FW_UPLOAD_ERR_INVALID_SIZE; 130 + } 131 + 132 + priv->cancel_request = false; 133 + 134 + return FW_UPLOAD_ERR_NONE; 135 + } 136 + 137 + static void mpfs_auto_update_cancel(struct fw_upload *fw_uploader) 138 + { 139 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 140 + 141 + priv->cancel_request = true; 142 + } 143 + 144 + static enum fw_upload_err mpfs_auto_update_poll_complete(struct fw_upload *fw_uploader) 145 + { 146 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 147 + int ret; 148 + 149 + /* 150 + * There is no meaningful way to get the status of the programming while 151 + * it is in progress, so attempting anything other than waiting for it 152 + * to complete would be misplaced. 153 + */ 154 + ret = wait_for_completion_timeout(&priv->programming_complete, 155 + msecs_to_jiffies(AUTO_UPDATE_TIMEOUT_MS)); 156 + if (ret) 157 + return FW_UPLOAD_ERR_TIMEOUT; 158 + 159 + return FW_UPLOAD_ERR_NONE; 160 + } 161 + 162 + static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader) 163 + { 164 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 165 + struct mpfs_mss_response *response; 166 + struct mpfs_mss_msg *message; 167 + u32 *response_msg; 168 + int ret; 169 + 170 + response_msg = devm_kzalloc(priv->dev, AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(response_msg), 171 + GFP_KERNEL); 172 + if (!response_msg) 173 + return -ENOMEM; 174 + 175 + response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL); 176 + if (!response) { 177 + ret = -ENOMEM; 178 + goto free_response_msg; 179 + } 180 + 181 + message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL); 182 + if (!message) { 183 + ret = -ENOMEM; 184 + goto free_response; 185 + } 186 + 187 + /* 188 + * The system controller can verify that an image in the flash is valid. 189 + * Rather than duplicate the check in this driver, call the relevant 190 + * service from the system controller instead. 191 + * This service has no command data and no response data. It overloads 192 + * mbox_offset with the image index in the flash's SPI directory where 193 + * the bitstream is located. 194 + */ 195 + response->resp_msg = response_msg; 196 + response->resp_size = AUTO_UPDATE_AUTHENTICATE_RESP_SIZE; 197 + message->cmd_opcode = AUTO_UPDATE_AUTHENTICATE_CMD_OPCODE; 198 + message->cmd_data_size = AUTO_UPDATE_AUTHENTICATE_CMD_DATA_SIZE; 199 + message->response = response; 200 + message->cmd_data = AUTO_UPDATE_AUTHENTICATE_CMD_DATA; 201 + message->mbox_offset = AUTO_UPDATE_UPGRADE_INDEX; 202 + message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; 203 + 204 + dev_info(priv->dev, "Running verification of Upgrade Image\n"); 205 + ret = mpfs_blocking_transaction(priv->sys_controller, message); 206 + if (ret | response->resp_status) { 207 + dev_warn(priv->dev, "Verification of Upgrade Image failed!\n"); 208 + ret = ret ? ret : -EBADMSG; 209 + } 210 + 211 + dev_info(priv->dev, "Verification of Upgrade Image passed!\n"); 212 + 213 + devm_kfree(priv->dev, message); 214 + free_response: 215 + devm_kfree(priv->dev, response); 216 + free_response_msg: 217 + devm_kfree(priv->dev, response_msg); 218 + 219 + return ret; 220 + } 221 + 222 + static int mpfs_auto_update_set_image_address(struct mpfs_auto_update_priv *priv, char *buffer, 223 + u32 image_address, loff_t directory_address) 224 + { 225 + struct erase_info erase; 226 + size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE; 227 + size_t bytes_written = 0, bytes_read = 0; 228 + int ret; 229 + 230 + erase_size = round_up(erase_size, (u64)priv->flash->erasesize); 231 + 232 + erase.addr = AUTO_UPDATE_DIRECTORY_BASE; 233 + erase.len = erase_size; 234 + 235 + /* 236 + * We need to write the "SPI DIRECTORY" to the first 1 KiB, telling 237 + * the system controller where to find the actual bitstream. Since 238 + * this is spi-nor, we have to read the first eraseblock, erase that 239 + * portion of the flash, modify the data and then write it back. 240 + * There's no need to do this though if things are already the way they 241 + * should be, so check and save the write in that case. 242 + */ 243 + ret = mtd_read(priv->flash, AUTO_UPDATE_DIRECTORY_BASE, erase_size, &bytes_read, 244 + (u_char *)buffer); 245 + if (ret) 246 + return ret; 247 + 248 + if (bytes_read != erase_size) 249 + return -EIO; 250 + 251 + if ((*(u32 *)(buffer + AUTO_UPDATE_UPGRADE_DIRECTORY) == image_address) && 252 + !(*(u32 *)(buffer + AUTO_UPDATE_BLANK_DIRECTORY))) 253 + return 0; 254 + 255 + ret = mtd_erase(priv->flash, &erase); 256 + if (ret) 257 + return ret; 258 + 259 + /* 260 + * Populate the image address and then zero out the next directory so 261 + * that the system controller doesn't complain if in "Single Image" 262 + * mode. 263 + */ 264 + memcpy(buffer + AUTO_UPDATE_UPGRADE_DIRECTORY, &image_address, 265 + AUTO_UPDATE_DIRECTORY_WIDTH); 266 + memset(buffer + AUTO_UPDATE_BLANK_DIRECTORY, 0x0, AUTO_UPDATE_DIRECTORY_WIDTH); 267 + 268 + dev_info(priv->dev, "Writing the image address (%x) to the flash directory (%llx)\n", 269 + image_address, directory_address); 270 + 271 + ret = mtd_write(priv->flash, 0x0, erase_size, &bytes_written, (u_char *)buffer); 272 + if (ret) 273 + return ret; 274 + 275 + if (bytes_written != erase_size) 276 + return ret; 277 + 278 + return 0; 279 + } 280 + 281 + static int mpfs_auto_update_write_bitstream(struct fw_upload *fw_uploader, const u8 *data, 282 + u32 offset, u32 size, u32 *written) 283 + { 284 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 285 + struct erase_info erase; 286 + char *buffer; 287 + loff_t directory_address = AUTO_UPDATE_UPGRADE_DIRECTORY; 288 + size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE; 289 + size_t bytes_written = 0; 290 + u32 image_address; 291 + int ret; 292 + 293 + erase_size = round_up(erase_size, (u64)priv->flash->erasesize); 294 + 295 + image_address = AUTO_UPDATE_BITSTREAM_BASE + 296 + AUTO_UPDATE_UPGRADE_INDEX * priv->size_per_bitstream; 297 + 298 + buffer = devm_kzalloc(priv->dev, erase_size, GFP_KERNEL); 299 + if (!buffer) 300 + return -ENOMEM; 301 + 302 + ret = mpfs_auto_update_set_image_address(priv, buffer, image_address, directory_address); 303 + if (ret) { 304 + dev_err(priv->dev, "failed to set image address in the SPI directory: %d\n", ret); 305 + goto out; 306 + } 307 + 308 + /* 309 + * Now the .spi image itself can be written to the flash. Preservation 310 + * of contents here is not important here, unlike the spi "directory" 311 + * which must be RMWed. 312 + */ 313 + erase.len = round_up(size, (size_t)priv->flash->erasesize); 314 + erase.addr = image_address; 315 + 316 + dev_info(priv->dev, "Erasing the flash at address (%x)\n", image_address); 317 + ret = mtd_erase(priv->flash, &erase); 318 + if (ret) 319 + goto out; 320 + 321 + /* 322 + * No parsing etc of the bitstream is required. The system controller 323 + * will do all of that itself - including verifying that the bitstream 324 + * is valid. 325 + */ 326 + dev_info(priv->dev, "Writing the image to the flash at address (%x)\n", image_address); 327 + ret = mtd_write(priv->flash, (loff_t)image_address, size, &bytes_written, data); 328 + if (ret) 329 + goto out; 330 + 331 + if (bytes_written != size) { 332 + ret = -EIO; 333 + goto out; 334 + } 335 + 336 + *written = bytes_written; 337 + 338 + out: 339 + devm_kfree(priv->dev, buffer); 340 + return ret; 341 + } 342 + 343 + static enum fw_upload_err mpfs_auto_update_write(struct fw_upload *fw_uploader, const u8 *data, 344 + u32 offset, u32 size, u32 *written) 345 + { 346 + struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle; 347 + enum fw_upload_err err = FW_UPLOAD_ERR_NONE; 348 + int ret; 349 + 350 + reinit_completion(&priv->programming_complete); 351 + 352 + ret = mpfs_auto_update_write_bitstream(fw_uploader, data, offset, size, written); 353 + if (ret) { 354 + err = FW_UPLOAD_ERR_RW_ERROR; 355 + goto out; 356 + } 357 + 358 + if (priv->cancel_request) { 359 + err = FW_UPLOAD_ERR_CANCELED; 360 + goto out; 361 + } 362 + 363 + ret = mpfs_auto_update_verify_image(fw_uploader); 364 + if (ret) 365 + err = FW_UPLOAD_ERR_FW_INVALID; 366 + 367 + out: 368 + complete(&priv->programming_complete); 369 + 370 + return err; 371 + } 372 + 373 + static const struct fw_upload_ops mpfs_auto_update_ops = { 374 + .prepare = mpfs_auto_update_prepare, 375 + .write = mpfs_auto_update_write, 376 + .poll_complete = mpfs_auto_update_poll_complete, 377 + .cancel = mpfs_auto_update_cancel, 378 + }; 379 + 380 + static int mpfs_auto_update_available(struct mpfs_auto_update_priv *priv) 381 + { 382 + struct mpfs_mss_response *response; 383 + struct mpfs_mss_msg *message; 384 + u32 *response_msg; 385 + int ret; 386 + 387 + response_msg = devm_kzalloc(priv->dev, AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(response_msg), 388 + GFP_KERNEL); 389 + if (!response_msg) 390 + return -ENOMEM; 391 + 392 + response = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_response), GFP_KERNEL); 393 + if (!response) 394 + return -ENOMEM; 395 + 396 + message = devm_kzalloc(priv->dev, sizeof(struct mpfs_mss_msg), GFP_KERNEL); 397 + if (!message) 398 + return -ENOMEM; 399 + 400 + /* 401 + * To verify that Auto Update is possible, the "Query Security Service 402 + * Request" is performed. 403 + * This service has no command data & does not overload mbox_offset. 404 + */ 405 + response->resp_msg = response_msg; 406 + response->resp_size = AUTO_UPDATE_FEATURE_RESP_SIZE; 407 + message->cmd_opcode = AUTO_UPDATE_FEATURE_CMD_OPCODE; 408 + message->cmd_data_size = AUTO_UPDATE_FEATURE_CMD_DATA_SIZE; 409 + message->response = response; 410 + message->cmd_data = AUTO_UPDATE_FEATURE_CMD_DATA; 411 + message->mbox_offset = AUTO_UPDATE_DEFAULT_MBOX_OFFSET; 412 + message->resp_offset = AUTO_UPDATE_DEFAULT_RESP_OFFSET; 413 + 414 + ret = mpfs_blocking_transaction(priv->sys_controller, message); 415 + if (ret) 416 + return ret; 417 + 418 + /* 419 + * Currently, the system controller's firmware does not generate any 420 + * interrupts for failed services, so mpfs_blocking_transaction() should 421 + * time out & therefore return an error. 422 + * Hitting this check is highly unlikely at present, but if the system 423 + * controller's behaviour changes so that it does generate interrupts 424 + * for failed services, it will be required. 425 + */ 426 + if (response->resp_status) 427 + return -EIO; 428 + 429 + /* 430 + * Bit 5 of byte 1 is "UL_Auto Update" & if it is set, Auto Update is 431 + * not possible. 432 + */ 433 + if (response_msg[1] & AUTO_UPDATE_FEATURE_ENABLED) 434 + return -EPERM; 435 + 436 + return 0; 437 + } 438 + 439 + static int mpfs_auto_update_probe(struct platform_device *pdev) 440 + { 441 + struct device *dev = &pdev->dev; 442 + struct mpfs_auto_update_priv *priv; 443 + struct fw_upload *fw_uploader; 444 + int ret; 445 + 446 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 447 + if (!priv) 448 + return -ENOMEM; 449 + 450 + priv->sys_controller = mpfs_sys_controller_get(dev); 451 + if (IS_ERR(priv->sys_controller)) 452 + return dev_err_probe(dev, PTR_ERR(priv->sys_controller), 453 + "Could not register as a sub device of the system controller\n"); 454 + 455 + priv->dev = dev; 456 + platform_set_drvdata(pdev, priv); 457 + 458 + ret = mpfs_auto_update_available(priv); 459 + if (ret) 460 + return dev_err_probe(dev, ret, 461 + "The current bitstream does not support auto-update\n"); 462 + 463 + init_completion(&priv->programming_complete); 464 + 465 + fw_uploader = firmware_upload_register(THIS_MODULE, dev, "mpfs-auto-update", 466 + &mpfs_auto_update_ops, priv); 467 + if (IS_ERR(fw_uploader)) 468 + return dev_err_probe(dev, PTR_ERR(fw_uploader), 469 + "Failed to register the bitstream uploader\n"); 470 + 471 + priv->fw_uploader = fw_uploader; 472 + 473 + return 0; 474 + } 475 + 476 + static void mpfs_auto_update_remove(struct platform_device *pdev) 477 + { 478 + struct mpfs_auto_update_priv *priv = platform_get_drvdata(pdev); 479 + 480 + firmware_upload_unregister(priv->fw_uploader); 481 + } 482 + 483 + static struct platform_driver mpfs_auto_update_driver = { 484 + .driver = { 485 + .name = "mpfs-auto-update", 486 + }, 487 + .probe = mpfs_auto_update_probe, 488 + .remove_new = mpfs_auto_update_remove, 489 + }; 490 + module_platform_driver(mpfs_auto_update_driver); 491 + 492 + MODULE_LICENSE("GPL"); 493 + MODULE_AUTHOR("Conor Dooley <conor.dooley@microchip.com>"); 494 + MODULE_DESCRIPTION("PolarFire SoC Auto Update FPGA reprogramming");
+1
drivers/soc/microchip/Kconfig
··· 1 1 config POLARFIRE_SOC_SYS_CTRL 2 2 tristate "POLARFIRE_SOC_SYS_CTRL" 3 3 depends on POLARFIRE_SOC_MAILBOX 4 + depends on MTD 4 5 help 5 6 This driver adds support for the PolarFire SoC (MPFS) system controller. 6 7
+30 -3
drivers/soc/microchip/mpfs-sys-controller.c
··· 12 12 #include <linux/kref.h> 13 13 #include <linux/module.h> 14 14 #include <linux/jiffies.h> 15 + #include <linux/mtd/mtd.h> 16 + #include <linux/spi/spi.h> 15 17 #include <linux/interrupt.h> 16 18 #include <linux/of.h> 17 19 #include <linux/mailbox_client.h> ··· 32 30 struct mbox_client client; 33 31 struct mbox_chan *chan; 34 32 struct completion c; 33 + struct mtd_info *flash; 35 34 struct kref consumers; 36 35 }; 37 36 ··· 66 63 */ 67 64 if (!wait_for_completion_timeout(&sys_controller->c, timeout)) { 68 65 ret = -EBADMSG; 69 - dev_warn(sys_controller->client.dev, "MPFS sys controller service failed\n"); 66 + dev_warn(sys_controller->client.dev, 67 + "MPFS sys controller service failed with status: %d\n", 68 + msg->response->resp_status); 70 69 } else { 71 70 ret = 0; 72 71 } ··· 104 99 kref_put(&sys_controller->consumers, mpfs_sys_controller_delete); 105 100 } 106 101 102 + struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_client) 103 + { 104 + return mpfs_client->flash; 105 + } 106 + EXPORT_SYMBOL(mpfs_sys_controller_get_flash); 107 + 107 108 static struct platform_device subdevs[] = { 108 109 { 109 110 .name = "mpfs-rng", ··· 118 107 { 119 108 .name = "mpfs-generic-service", 120 109 .id = -1, 121 - } 110 + }, 111 + { 112 + .name = "mpfs-auto-update", 113 + .id = -1, 114 + }, 122 115 }; 123 116 124 117 static int mpfs_sys_controller_probe(struct platform_device *pdev) 125 118 { 126 119 struct device *dev = &pdev->dev; 127 120 struct mpfs_sys_controller *sys_controller; 121 + struct device_node *np; 128 122 int i, ret; 129 123 130 124 sys_controller = kzalloc(sizeof(*sys_controller), GFP_KERNEL); 131 125 if (!sys_controller) 132 126 return -ENOMEM; 133 127 128 + np = of_parse_phandle(dev->of_node, "microchip,bitstream-flash", 0); 129 + if (!np) 130 + goto no_flash; 131 + 132 + sys_controller->flash = of_get_mtd_device_by_node(np); 133 + of_node_put(np); 134 + if (IS_ERR(sys_controller->flash)) 135 + return dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n"); 136 + 137 + no_flash: 134 138 sys_controller->client.dev = dev; 135 139 sys_controller->client.rx_callback = mpfs_sys_controller_rx_callback; 136 140 sys_controller->client.tx_block = 1U; ··· 164 138 165 139 platform_set_drvdata(pdev, sys_controller); 166 140 167 - dev_info(&pdev->dev, "Registered MPFS system controller\n"); 168 141 169 142 for (i = 0; i < ARRAY_SIZE(subdevs); i++) { 170 143 subdevs[i].dev.parent = dev; 171 144 if (platform_device_register(&subdevs[i])) 172 145 dev_warn(dev, "Error registering sub device %s\n", subdevs[i].name); 173 146 } 147 + 148 + dev_info(&pdev->dev, "Registered MPFS system controller\n"); 174 149 175 150 return 0; 176 151 }
+2
include/linux/firmware.h
··· 27 27 * @FW_UPLOAD_ERR_INVALID_SIZE: invalid firmware image size 28 28 * @FW_UPLOAD_ERR_RW_ERROR: read or write to HW failed, see kernel log 29 29 * @FW_UPLOAD_ERR_WEAROUT: FLASH device is approaching wear-out, wait & retry 30 + * @FW_UPLOAD_ERR_FW_INVALID: invalid firmware file 30 31 * @FW_UPLOAD_ERR_MAX: Maximum error code marker 31 32 */ 32 33 enum fw_upload_err { ··· 39 38 FW_UPLOAD_ERR_INVALID_SIZE, 40 39 FW_UPLOAD_ERR_RW_ERROR, 41 40 FW_UPLOAD_ERR_WEAROUT, 41 + FW_UPLOAD_ERR_FW_INVALID, 42 42 FW_UPLOAD_ERR_MAX 43 43 }; 44 44
+2
include/soc/microchip/mpfs.h
··· 38 38 39 39 struct mpfs_sys_controller *mpfs_sys_controller_get(struct device *dev); 40 40 41 + struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_client); 42 + 41 43 #endif /* if IS_ENABLED(CONFIG_POLARFIRE_SOC_SYS_CTRL) */ 42 44 43 45 #if IS_ENABLED(CONFIG_MCHP_CLK_MPFS)
+1
lib/test_firmware.c
··· 1132 1132 [FW_UPLOAD_ERR_INVALID_SIZE] = "invalid-file-size", 1133 1133 [FW_UPLOAD_ERR_RW_ERROR] = "read-write-error", 1134 1134 [FW_UPLOAD_ERR_WEAROUT] = "flash-wearout", 1135 + [FW_UPLOAD_ERR_FW_INVALID] = "firmware-invalid", 1135 1136 }; 1136 1137 1137 1138 static void upload_err_inject_error(struct test_firmware_upload *tst,