// SPDX-License-Identifier: GPL-2.0-only /* * ISHTP firmware loader function * * Copyright (c) 2024, Intel Corporation. * * This module implements the functionality to load the main ISH firmware from the host, starting * with the Lunar Lake generation. It leverages a new method that enhances space optimization and * flexibility by dividing the ISH firmware into a bootloader and main firmware. * * Please refer to the [Documentation](Documentation/hid/intel-ish-hid.rst) for the details on * flows. * * Additionally, address potential error scenarios to ensure graceful failure handling. * - Firmware Image Not Found: * Occurs when `request_firmware()` cannot locate the firmware image. The ISH firmware will * remain in a state awaiting firmware loading from the host, with no further action from * the ISHTP driver. * Recovery: Re-insmod the ISH drivers allows for a retry of the firmware loading from the host. * * - DMA Buffer Allocation Failure: * This happens if allocating a DMA buffer during `prepare_dma_bufs()` fails. The ISH firmware * will stay in a waiting state, and the ISHTP driver will release any allocated DMA buffers and * firmware without further actions. * Recovery: Re-insmod the ISH drivers allows for a retry of the firmware loading from the host. * * - Incorrect Firmware Image: * Using an incorrect firmware image will initiate the firmware loading process but will * eventually be refused by the ISH firmware after three unsuccessful attempts, indicated by * returning an error code. The ISHTP driver will stop attempting after three tries. * Recovery: A platform reset is required to retry firmware loading from the host. */ #define dev_fmt(fmt) … #include <linux/cacheflush.h> #include <linux/container_of.h> #include <linux/dev_printk.h> #include <linux/dma-mapping.h> #include <linux/errno.h> #include <linux/firmware.h> #include <linux/gfp_types.h> #include <linux/math.h> #include <linux/module.h> #include <linux/pfn.h> #include <linux/string.h> #include <linux/types.h> #include <linux/wait.h> #include "hbm.h" #include "loader.h" /** * loader_write_message() - Write a message to the ISHTP device * @dev: The ISHTP device * @buf: The buffer containing the message * @len: The length of the message * * Return: 0 on success, negative error code on failure */ static int loader_write_message(struct ishtp_device *dev, void *buf, int len) { … } /** * loader_xfer_cmd() - Transfer a command to the ISHTP device * @dev: The ISHTP device * @req: The request buffer * @req_len: The length of the request * @resp: The response buffer * @resp_len: The length of the response * * Return: 0 on success, negative error code on failure */ static int loader_xfer_cmd(struct ishtp_device *dev, void *req, int req_len, void *resp, int resp_len) { … } /** * release_dma_bufs() - Release the DMA buffer for transferring firmware fragments * @dev: The ISHTP device * @fragment: The ISHTP firmware fragment descriptor * @dma_bufs: The array of DMA fragment buffers * @fragment_size: The size of a single DMA fragment */ static void release_dma_bufs(struct ishtp_device *dev, struct loader_xfer_dma_fragment *fragment, void **dma_bufs, u32 fragment_size) { … } /** * prepare_dma_bufs() - Prepare the DMA buffer for transferring firmware fragments * @dev: The ISHTP device * @ish_fw: The ISH firmware * @fragment: The ISHTP firmware fragment descriptor * @dma_bufs: The array of DMA fragment buffers * @fragment_size: The size of a single DMA fragment * @fragment_count: Number of fragments * * Return: 0 on success, negative error code on failure */ static int prepare_dma_bufs(struct ishtp_device *dev, const struct firmware *ish_fw, struct loader_xfer_dma_fragment *fragment, void **dma_bufs, u32 fragment_size, u32 fragment_count) { … } /** * ishtp_loader_work() - Load the ISHTP firmware * @work: The work structure * * The ISH Loader attempts to load firmware by sending a series of commands * to the ISH device. If a command fails to be acknowledged by the ISH device, * the loader will retry sending the command, up to a maximum of * ISHTP_LOADER_RETRY_TIMES. * * After the maximum number of retries has been reached without success, the * ISH bootloader will return an error status code and will no longer respond * to the driver's commands. This behavior indicates that the ISH Loader has * encountered a critical error during the firmware loading process. * * In such a case, where the ISH bootloader is unresponsive after all retries * have been exhausted, a platform reset is required to restore communication * with the ISH device and to recover from this error state. */ void ishtp_loader_work(struct work_struct *work) { … }