^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ISH-TP client driver for ISH firmware loading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2019, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/intel-ish-client-if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* Number of times we attempt to load the firmware before giving up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define MAX_LOAD_ATTEMPTS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* ISH TX/RX ring buffer pool size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define LOADER_CL_RX_RING_SIZE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define LOADER_CL_TX_RING_SIZE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * ISH Shim firmware loader reserves 4 Kb buffer in SRAM. The buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * used to temporarily hold the data transferred from host to Shim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * firmware loader. Reason for the odd size of 3968 bytes? Each IPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * transfer is 128 bytes (= 4 bytes header + 124 bytes payload). So the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * 4 Kb buffer can hold maximum of 32 IPC transfers, which means we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * have a max payload of 3968 bytes (= 32 x 124 payload).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define LOADER_SHIM_IPC_BUF_SIZE 3968
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * enum ish_loader_commands - ISH loader host commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * LOADER_CMD_XFER_QUERY Query the Shim firmware loader for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * LOADER_CMD_XFER_FRAGMENT Transfer one firmware image fragment at a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * time. The command may be executed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * multiple times until the entire firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * image is downloaded to SRAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * LOADER_CMD_START Start executing the main firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) enum ish_loader_commands {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) LOADER_CMD_XFER_QUERY = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) LOADER_CMD_XFER_FRAGMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) LOADER_CMD_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Command bit mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define CMD_MASK GENMASK(6, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define IS_RESPONSE BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * ISH firmware max delay for one transmit failure is 1 Hz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * and firmware will retry 2 times, so 3 Hz is used for timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define ISHTP_SEND_TIMEOUT (3 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Loader transfer modes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * LOADER_XFER_MODE_ISHTP mode uses the existing ISH-TP mechanism to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * transfer data. This may use IPC or DMA if supported in firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * The buffer size is limited to 4 Kb by the IPC/ISH-TP protocol for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * both IPC & DMA (legacy).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * LOADER_XFER_MODE_DIRECT_DMA - firmware loading is a bit different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * from the sensor data streaming. Here we download a large (300+ Kb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * image directly to ISH SRAM memory. There is limited benefit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * DMA'ing 300 Kb image in 4 Kb chucks limit. Hence, we introduce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * this "direct dma" mode, where we do not use ISH-TP for DMA, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * instead manage the DMA directly in kernel driver and Shim firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * loader (allocate buffer, break in chucks and transfer). This allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * to overcome 4 Kb limit, and optimize the data flow path in firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define LOADER_XFER_MODE_DIRECT_DMA BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define LOADER_XFER_MODE_ISHTP BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* ISH Transport Loader client unique GUID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static const guid_t loader_ishtp_guid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) GUID_INIT(0xc804d06a, 0x55bd, 0x4ea7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 0xad, 0xed, 0x1e, 0x31, 0x22, 0x8c, 0x76, 0xdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define FILENAME_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * The firmware loading latency will be minimum if we can DMA the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * entire ISH firmware image in one go. This requires that we allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * a large DMA buffer in kernel, which could be problematic on some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * platforms. So here we limit the DMA buffer size via a module_param.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * We default to 4 pages, but a customer can set it to higher limit if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * deemed appropriate for his platform.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int dma_buf_size_limit = 4 * PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * struct loader_msg_hdr - Header for ISH Loader commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * @command: LOADER_CMD* commands. Bit 7 is the response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * @status: Command response status. Non 0, is error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * This structure is used as header for every command/data sent/received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * between Host driver and ISH Shim firmware loader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct loader_msg_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u8 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u8 reserved[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct loader_xfer_query {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct loader_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u32 image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct ish_fw_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u16 major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u16 minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) u16 hotfix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) u16 build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) union loader_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u8 major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u8 minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u8 hotfix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 build;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct loader_capability {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u32 max_fw_image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u32 xfer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u32 max_dma_buf_size; /* only for dma mode, multiples of cacheline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct shim_fw_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct ish_fw_version ish_fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u32 protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) union loader_version ldr_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct loader_capability ldr_capability;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct loader_xfer_query_response {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct loader_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct shim_fw_info fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct loader_xfer_fragment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct loader_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 xfer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) u32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u32 is_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct loader_xfer_ipc_fragment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct loader_xfer_fragment fragment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u8 data[] ____cacheline_aligned; /* variable length payload here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct loader_xfer_dma_fragment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct loader_xfer_fragment fragment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u64 ddr_phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct loader_start {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct loader_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * struct response_info - Encapsulate firmware response related
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * information for passing between function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * loader_cl_send() and process_recv() callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * @data Copy the data received from firmware here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @max_size Max size allocated for the @data buffer. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * received data exceeds this value, we log an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * @size Actual size of data received from firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * @error Returns 0 for success, negative error code for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * failure in function process_recv().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * @received Set to true on receiving a valid firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * response to host command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @wait_queue Wait queue for Host firmware loading where the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * client sends message to ISH firmware and waits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * for response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct response_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) size_t max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) bool received;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) wait_queue_head_t wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * struct ishtp_cl_data - Encapsulate per ISH-TP Client Data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * @work_ishtp_reset: Work queue for reset handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * @work_fw_load: Work queue for host firmware loading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * @flag_retry Flag for indicating host firmware loading should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * be retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * @retry_count Count the number of retries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * This structure is used to store data per client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct ishtp_cl_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct ishtp_cl *loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct ishtp_cl_device *cl_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * Used for passing firmware response information between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * loader_cl_send() and process_recv() callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct response_info response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct work_struct work_ishtp_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct work_struct work_fw_load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * In certain failure scenrios, it makes sense to reset the ISH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * subsystem and retry Host firmware loading (e.g. bad message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * packet, ENOMEM, etc.). On the other hand, failures due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * protocol mismatch, etc., are not recoverable. We do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * retry them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * If set, the flag indicates that we should re-try the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * particular failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) bool flag_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define IPC_FRAGMENT_DATA_PREAMBLE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) offsetof(struct loader_xfer_ipc_fragment, data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define cl_data_to_dev(client_data) ishtp_device((client_data)->cl_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * get_firmware_variant() - Gets the filename of firmware image to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * loaded based on platform variant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * @client_data Client data instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * @filename Returns firmware filename.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Queries the firmware-name device property string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int get_firmware_variant(struct ishtp_cl_data *client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) char *filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) const char *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct device *devc = ishtp_get_pci_device(client_data->cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) rv = device_property_read_string(devc, "firmware-name", &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) dev_err(devc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) "Error: ISH firmware-name device property required\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return snprintf(filename, FILENAME_SIZE, "intel/%s", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * loader_cl_send() Send message from host to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * @client_data: Client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * @out_msg Message buffer to be sent to firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @out_size Size of out going message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * @in_msg Message buffer where the incoming data copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * This buffer is allocated by calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @in_size Max size of incoming message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * Return: Number of bytes copied in the in_msg on success, negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int loader_cl_send(struct ishtp_cl_data *client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) u8 *out_msg, size_t out_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) u8 *in_msg, size_t in_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct loader_msg_hdr *out_hdr = (struct loader_msg_hdr *)out_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) "%s: command=%02lx is_response=%u status=%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) out_hdr->command & CMD_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) out_hdr->command & IS_RESPONSE ? 1 : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) out_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* Setup in coming buffer & size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) client_data->response.data = in_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) client_data->response.max_size = in_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) client_data->response.error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) client_data->response.received = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) rv = ishtp_cl_send(loader_ishtp_cl, out_msg, out_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) "ishtp_cl_send error %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) wait_event_interruptible_timeout(client_data->response.wait_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) client_data->response.received,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ISHTP_SEND_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (!client_data->response.received) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) "Timed out for response to command=%02lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out_hdr->command & CMD_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (client_data->response.error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return client_data->response.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return client_data->response.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * process_recv() - Receive and parse incoming packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * @loader_ishtp_cl: Client instance to get stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * @rb_in_proc: ISH received message buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * Parse the incoming packet. If it is a response packet then it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * update received and wake up the caller waiting to for the response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static void process_recv(struct ishtp_cl *loader_ishtp_cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct ishtp_cl_rb *rb_in_proc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct loader_msg_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) size_t data_len = rb_in_proc->buf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct ishtp_cl_data *client_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ishtp_get_client_data(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (!client_data->response.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) "Receiving buffer is null. Should be allocated by calling function\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) client_data->response.error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (client_data->response.received) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) "Previous firmware message not yet processed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) client_data->response.error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * All firmware messages have a header. Check buffer size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * before accessing elements inside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!rb_in_proc->buffer.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) dev_warn(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) "rb_in_proc->buffer.data returned null");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) client_data->response.error = -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (data_len < sizeof(struct loader_msg_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) "data size %zu is less than header %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) data_len, sizeof(struct loader_msg_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) client_data->response.error = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) hdr = (struct loader_msg_hdr *)rb_in_proc->buffer.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) "%s: command=%02lx is_response=%u status=%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) hdr->command & CMD_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) hdr->command & IS_RESPONSE ? 1 : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (((hdr->command & CMD_MASK) != LOADER_CMD_XFER_QUERY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ((hdr->command & CMD_MASK) != LOADER_CMD_XFER_FRAGMENT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ((hdr->command & CMD_MASK) != LOADER_CMD_START)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) "Invalid command=%02lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) hdr->command & CMD_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) client_data->response.error = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (data_len > client_data->response.max_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) "Received buffer size %zu is larger than allocated buffer %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) data_len, client_data->response.max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) client_data->response.error = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* We expect only "response" messages from firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (!(hdr->command & IS_RESPONSE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) "Invalid response to command\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) client_data->response.error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (hdr->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) "Loader returned status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) client_data->response.error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* Update the actual received buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) client_data->response.size = data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * Copy the buffer received in firmware response for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * calling thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) memcpy(client_data->response.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) rb_in_proc->buffer.data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Set flag before waking up the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) client_data->response.received = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Free the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ishtp_cl_io_rb_recycle(rb_in_proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) rb_in_proc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Wake the calling thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) wake_up_interruptible(&client_data->response.wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * loader_cl_event_cb() - bus driver callback for incoming message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * @device: Pointer to the ishtp client device for which this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * message is targeted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * Remove the packet from the list and process the message by calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * process_recv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void loader_cl_event_cb(struct ishtp_cl_device *cl_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct ishtp_cl_rb *rb_in_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) while ((rb_in_proc = ishtp_cl_rx_get_rb(loader_ishtp_cl)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* Process the data packet from firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) process_recv(loader_ishtp_cl, rb_in_proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * ish_query_loader_prop() - Query ISH Shim firmware loader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * @client_data: Client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * @fw: Poiner to firmware data struct in host memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * @fw_info: Loader firmware properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * This function queries the ISH Shim firmware loader for capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int ish_query_loader_prop(struct ishtp_cl_data *client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) const struct firmware *fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct shim_fw_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct loader_xfer_query ldr_xfer_query;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct loader_xfer_query_response ldr_xfer_query_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) memset(&ldr_xfer_query, 0, sizeof(ldr_xfer_query));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ldr_xfer_query.hdr.command = LOADER_CMD_XFER_QUERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) ldr_xfer_query.image_size = fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) rv = loader_cl_send(client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) (u8 *)&ldr_xfer_query,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) sizeof(ldr_xfer_query),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) (u8 *)&ldr_xfer_query_resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) sizeof(ldr_xfer_query_resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) *fw_info = (struct shim_fw_info){};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* On success, the return value is the received buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (rv != sizeof(struct loader_xfer_query_response)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) "data size %d is not equal to size of loader_xfer_query_response %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) rv, sizeof(struct loader_xfer_query_response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) *fw_info = (struct shim_fw_info){};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* Save fw_info for use outside this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) *fw_info = ldr_xfer_query_resp.fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* Loader firmware properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) "ish_fw_version: major=%d minor=%d hotfix=%d build=%d protocol_version=0x%x loader_version=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) fw_info->ish_fw_version.major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) fw_info->ish_fw_version.minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) fw_info->ish_fw_version.hotfix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) fw_info->ish_fw_version.build,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) fw_info->protocol_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) fw_info->ldr_version.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) "loader_capability: max_fw_image_size=0x%x xfer_mode=%d max_dma_buf_size=0x%x dma_buf_size_limit=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) fw_info->ldr_capability.max_fw_image_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) fw_info->ldr_capability.xfer_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) fw_info->ldr_capability.max_dma_buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) dma_buf_size_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* Sanity checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (fw_info->ldr_capability.max_fw_image_size < fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) "ISH firmware size %zu is greater than Shim firmware loader max supported %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) fw->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) fw_info->ldr_capability.max_fw_image_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /* For DMA the buffer size should be multiple of cacheline size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if ((fw_info->ldr_capability.xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) (fw_info->ldr_capability.max_dma_buf_size % L1_CACHE_BYTES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) "Shim firmware loader buffer size %d should be multiple of cacheline\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) fw_info->ldr_capability.max_dma_buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * ish_fw_xfer_ishtp() Loads ISH firmware using ishtp interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * @client_data: Client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * @fw: Pointer to firmware data struct in host memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * This function uses ISH-TP to transfer ISH firmware from host to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * ISH SRAM. Lower layers may use IPC or DMA depending on firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static int ish_fw_xfer_ishtp(struct ishtp_cl_data *client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) const struct firmware *fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) u32 fragment_offset, fragment_size, payload_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct loader_xfer_ipc_fragment *ldr_xfer_ipc_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct loader_msg_hdr ldr_xfer_ipc_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) payload_max_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) LOADER_SHIM_IPC_BUF_SIZE - IPC_FRAGMENT_DATA_PREAMBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ldr_xfer_ipc_frag = kzalloc(LOADER_SHIM_IPC_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (!ldr_xfer_ipc_frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ldr_xfer_ipc_frag->fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ldr_xfer_ipc_frag->fragment.xfer_mode = LOADER_XFER_MODE_ISHTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /* Break the firmware image into fragments and send as ISH-TP payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) fragment_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) while (fragment_offset < fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (fragment_offset + payload_max_size < fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) fragment_size = payload_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ldr_xfer_ipc_frag->fragment.is_last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) fragment_size = fw->size - fragment_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) ldr_xfer_ipc_frag->fragment.is_last = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) ldr_xfer_ipc_frag->fragment.offset = fragment_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ldr_xfer_ipc_frag->fragment.size = fragment_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) memcpy(ldr_xfer_ipc_frag->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) &fw->data[fragment_offset],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) fragment_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) "xfer_mode=ipc offset=0x%08x size=0x%08x is_last=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ldr_xfer_ipc_frag->fragment.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ldr_xfer_ipc_frag->fragment.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) ldr_xfer_ipc_frag->fragment.is_last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) rv = loader_cl_send(client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) (u8 *)ldr_xfer_ipc_frag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) IPC_FRAGMENT_DATA_PREAMBLE + fragment_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) (u8 *)&ldr_xfer_ipc_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) sizeof(ldr_xfer_ipc_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) goto end_err_resp_buf_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) fragment_offset += fragment_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) kfree(ldr_xfer_ipc_frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) end_err_resp_buf_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* Free ISH buffer if not done already, in error case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) kfree(ldr_xfer_ipc_frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * ish_fw_xfer_direct_dma() - Loads ISH firmware using direct dma
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * @client_data: Client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * @fw: Pointer to firmware data struct in host memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * @fw_info: Loader firmware properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * Host firmware load is a unique case where we need to download
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * a large firmware image (200+ Kb). This function implements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * direct DMA transfer in kernel and ISH firmware. This allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * us to overcome the ISH-TP 4 Kb limit, and allows us to DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * directly to ISH UMA at location of choice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * Function depends on corresponding support in ISH firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) const struct firmware *fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) const struct shim_fw_info fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) void *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dma_addr_t dma_buf_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) u32 fragment_offset, fragment_size, payload_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct loader_msg_hdr ldr_xfer_dma_frag_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct loader_xfer_dma_fragment ldr_xfer_dma_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct device *devc = ishtp_get_pci_device(client_data->cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) u32 shim_fw_buf_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) fw_info.ldr_capability.max_dma_buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * payload_max_size should be set to minimum of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * (1) Size of firmware to be loaded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * (2) Max DMA buffer size supported by Shim firmware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * (3) DMA buffer size limit set by boot_param dma_buf_size_limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) payload_max_size = min3(fw->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) (size_t)shim_fw_buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) (size_t)dma_buf_size_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * Buffer size should be multiple of cacheline size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * if it's not, select the previous cacheline boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) payload_max_size &= ~(L1_CACHE_BYTES - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) dma_buf = dma_alloc_coherent(devc, payload_max_size, &dma_buf_phy, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (!dma_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ldr_xfer_dma_frag.fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) ldr_xfer_dma_frag.fragment.xfer_mode = LOADER_XFER_MODE_DIRECT_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) ldr_xfer_dma_frag.ddr_phys_addr = (u64)dma_buf_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* Send the firmware image in chucks of payload_max_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) fragment_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) while (fragment_offset < fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (fragment_offset + payload_max_size < fw->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) fragment_size = payload_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) ldr_xfer_dma_frag.fragment.is_last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) fragment_size = fw->size - fragment_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) ldr_xfer_dma_frag.fragment.is_last = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) ldr_xfer_dma_frag.fragment.offset = fragment_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ldr_xfer_dma_frag.fragment.size = fragment_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) memcpy(dma_buf, &fw->data[fragment_offset], fragment_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* Flush cache to be sure the data is in main memory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) clflush_cache_range(dma_buf, payload_max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) dev_dbg(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) "xfer_mode=dma offset=0x%08x size=0x%x is_last=%d ddr_phys_addr=0x%016llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) ldr_xfer_dma_frag.fragment.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) ldr_xfer_dma_frag.fragment.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) ldr_xfer_dma_frag.fragment.is_last,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ldr_xfer_dma_frag.ddr_phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) rv = loader_cl_send(client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) (u8 *)&ldr_xfer_dma_frag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) sizeof(ldr_xfer_dma_frag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) (u8 *)&ldr_xfer_dma_frag_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) sizeof(ldr_xfer_dma_frag_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto end_err_resp_buf_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) fragment_offset += fragment_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) end_err_resp_buf_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) dma_free_coherent(devc, payload_max_size, dma_buf, dma_buf_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) * ish_fw_start() Start executing ISH main firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * @client_data: client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * This function sends message to Shim firmware loader to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * the execution of ISH main firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static int ish_fw_start(struct ishtp_cl_data *client_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct loader_start ldr_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct loader_msg_hdr ldr_start_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) memset(&ldr_start, 0, sizeof(ldr_start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) ldr_start.hdr.command = LOADER_CMD_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return loader_cl_send(client_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) (u8 *)&ldr_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) sizeof(ldr_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) (u8 *)&ldr_start_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) sizeof(ldr_start_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * load_fw_from_host() Loads ISH firmware from host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) * @client_data: Client data instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * This function loads the ISH firmware to ISH SRAM and starts execution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * Return: 0 for success, negative error code for failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) static int load_fw_from_host(struct ishtp_cl_data *client_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) u32 xfer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct shim_fw_info fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct ishtp_cl *loader_ishtp_cl = client_data->loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) client_data->flag_retry = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) filename = kzalloc(FILENAME_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (!filename) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) client_data->flag_retry = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) rv = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) goto end_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) /* Get filename of the ISH firmware to be loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) rv = get_firmware_variant(client_data, filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) goto end_err_filename_buf_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) rv = request_firmware(&fw, filename, cl_data_to_dev(client_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) goto end_err_filename_buf_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) /* Step 1: Query Shim firmware loader properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) rv = ish_query_loader_prop(client_data, fw, &fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) goto end_err_fw_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) /* Step 2: Send the main firmware image to be loaded, to ISH SRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) xfer_mode = fw_info.ldr_capability.xfer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (xfer_mode & LOADER_XFER_MODE_DIRECT_DMA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) rv = ish_fw_xfer_direct_dma(client_data, fw, fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) } else if (xfer_mode & LOADER_XFER_MODE_ISHTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) rv = ish_fw_xfer_ishtp(client_data, fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) "No transfer mode selected in firmware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) rv = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) goto end_err_fw_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Step 3: Start ISH main firmware exeuction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) rv = ish_fw_start(client_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) goto end_err_fw_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) dev_info(cl_data_to_dev(client_data), "ISH firmware %s loaded\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) kfree(filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) end_err_fw_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) end_err_filename_buf_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) kfree(filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) end_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /* Keep a count of retries, and give up after 3 attempts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (client_data->flag_retry &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) client_data->retry_count++ < MAX_LOAD_ATTEMPTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) dev_warn(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) "ISH host firmware load failed %d. Resetting ISH, and trying again..\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) ish_hw_reset(ishtp_get_ishtp_device(loader_ishtp_cl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) "ISH host firmware load failed %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) static void load_fw_from_host_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) struct ishtp_cl_data *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) client_data = container_of(work, struct ishtp_cl_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) work_fw_load);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) load_fw_from_host(client_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * loader_init() - Init function for ISH-TP client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * @loader_ishtp_cl: ISH-TP client instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * @reset: true if called for init after reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * Return: 0 for success, negative error code for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) static int loader_init(struct ishtp_cl *loader_ishtp_cl, int reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct ishtp_fw_client *fw_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct ishtp_cl_data *client_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ishtp_get_client_data(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) dev_dbg(cl_data_to_dev(client_data), "reset flag: %d\n", reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) rv = ishtp_cl_link(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) dev_err(cl_data_to_dev(client_data), "ishtp_cl_link failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* Connect to firmware client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) ishtp_set_tx_ring_size(loader_ishtp_cl, LOADER_CL_TX_RING_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ishtp_set_rx_ring_size(loader_ishtp_cl, LOADER_CL_RX_RING_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) fw_client =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) ishtp_fw_cl_get_client(ishtp_get_ishtp_device(loader_ishtp_cl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) &loader_ishtp_guid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!fw_client) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) dev_err(cl_data_to_dev(client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) "ISH client uuid not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) rv = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) goto err_cl_unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ishtp_cl_set_fw_client_id(loader_ishtp_cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) ishtp_get_fw_client_id(fw_client));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_CONNECTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) rv = ishtp_cl_connect(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) dev_err(cl_data_to_dev(client_data), "Client connect fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) goto err_cl_unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) dev_dbg(cl_data_to_dev(client_data), "Client connected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ishtp_register_event_cb(client_data->cl_device, loader_cl_event_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) err_cl_unlink:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) ishtp_cl_unlink(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) static void loader_deinit(struct ishtp_cl *loader_ishtp_cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ishtp_set_connection_state(loader_ishtp_cl, ISHTP_CL_DISCONNECTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) ishtp_cl_disconnect(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) ishtp_cl_unlink(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) ishtp_cl_flush_queues(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) /* Disband and free all Tx and Rx client-level rings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) ishtp_cl_free(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) static void reset_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct ishtp_cl_data *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct ishtp_cl *loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) struct ishtp_cl_device *cl_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) client_data = container_of(work, struct ishtp_cl_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) work_ishtp_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) loader_ishtp_cl = client_data->loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) cl_device = client_data->cl_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) /* Unlink, flush queues & start again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ishtp_cl_unlink(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) ishtp_cl_flush_queues(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) ishtp_cl_free(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) loader_ishtp_cl = ishtp_cl_allocate(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (!loader_ishtp_cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) ishtp_set_drvdata(cl_device, loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) ishtp_set_client_data(loader_ishtp_cl, client_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) client_data->loader_ishtp_cl = loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) client_data->cl_device = cl_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) rv = loader_init(loader_ishtp_cl, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) dev_err(ishtp_device(cl_device), "Reset Failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) /* ISH firmware loading from host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) load_fw_from_host(client_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * loader_ishtp_cl_probe() - ISH-TP client driver probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * @cl_device: ISH-TP client device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) * This function gets called on device create on ISH-TP bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) * Return: 0 for success, negative error code for failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) static int loader_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct ishtp_cl *loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) struct ishtp_cl_data *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) client_data = devm_kzalloc(ishtp_device(cl_device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) sizeof(*client_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (!client_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) loader_ishtp_cl = ishtp_cl_allocate(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (!loader_ishtp_cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) ishtp_set_drvdata(cl_device, loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) ishtp_set_client_data(loader_ishtp_cl, client_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) client_data->loader_ishtp_cl = loader_ishtp_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) client_data->cl_device = cl_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) init_waitqueue_head(&client_data->response.wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) INIT_WORK(&client_data->work_ishtp_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) reset_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) INIT_WORK(&client_data->work_fw_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) load_fw_from_host_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) rv = loader_init(loader_ishtp_cl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) ishtp_cl_free(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) ishtp_get_device(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) client_data->retry_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /* ISH firmware loading from host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) schedule_work(&client_data->work_fw_load);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * loader_ishtp_cl_remove() - ISH-TP client driver remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * @cl_device: ISH-TP client device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * This function gets called on device remove on ISH-TP bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * Return: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static int loader_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct ishtp_cl_data *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) client_data = ishtp_get_client_data(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * The sequence of the following two cancel_work_sync() is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * important. The work_fw_load can in turn schedue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) * work_ishtp_reset, so first cancel work_fw_load then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * cancel work_ishtp_reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) cancel_work_sync(&client_data->work_fw_load);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) cancel_work_sync(&client_data->work_ishtp_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) loader_deinit(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) ishtp_put_device(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) * loader_ishtp_cl_reset() - ISH-TP client driver reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) * @cl_device: ISH-TP client device instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) * This function gets called on device reset on ISH-TP bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * Return: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) static int loader_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct ishtp_cl_data *client_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) struct ishtp_cl *loader_ishtp_cl = ishtp_get_drvdata(cl_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) client_data = ishtp_get_client_data(loader_ishtp_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) schedule_work(&client_data->work_ishtp_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) static struct ishtp_cl_driver loader_ishtp_cl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) .name = "ish-loader",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) .guid = &loader_ishtp_guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) .probe = loader_ishtp_cl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) .remove = loader_ishtp_cl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) .reset = loader_ishtp_cl_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static int __init ish_loader_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) return ishtp_cl_driver_register(&loader_ishtp_cl_driver, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) static void __exit ish_loader_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) ishtp_cl_driver_unregister(&loader_ishtp_cl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) late_initcall(ish_loader_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) module_exit(ish_loader_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) module_param(dma_buf_size_limit, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) MODULE_PARM_DESC(dma_buf_size_limit, "Limit the DMA buf size to this value in bytes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) MODULE_DESCRIPTION("ISH ISH-TP Host firmware Loader Client Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) MODULE_AUTHOR("Rushikesh S Kadam <rushikesh.s.kadam@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) MODULE_ALIAS("ishtp:*");