1 From: Kalle Valo <quic_kvalo@quicinc.com>
2 Date: Thu, 27 Jul 2023 13:04:28 +0300
3 Subject: [PATCH] bus: mhi: host: allow MHI client drivers to provide the
6 Currently MHI loads the firmware image from the path provided by client
7 devices. ath11k needs to support firmware image embedded along with meta
8 data (named as firmware-2.bin). So allow the client driver to request the
9 firmware file from user space on it's own and provide the firmware image
10 data and size to MHI via a pointer struct mhi_controller::fw_data.
12 This is an optional feature, if fw_data is NULL MHI load the firmware using
13 the name from struct mhi_controller::fw_image string as before.
15 Tested with ath11k and WCN6855 hw2.0.
17 Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
18 Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
19 Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
20 Link: https://lore.kernel.org/r/20230727100430.3603551-2-kvalo@kernel.org
21 [mani: wrapped commit message to 75 columns]
22 Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
25 --- a/drivers/bus/mhi/host/boot.c
26 +++ b/drivers/bus/mhi/host/boot.c
27 @@ -367,12 +367,10 @@ error_alloc_mhi_buf:
30 static void mhi_firmware_copy(struct mhi_controller *mhi_cntrl,
31 - const struct firmware *firmware,
32 + const u8 *buf, size_t remainder,
33 struct image_info *img_info)
35 - size_t remainder = firmware->size;
37 - const u8 *buf = firmware->data;
38 struct mhi_buf *mhi_buf = img_info->mhi_buf;
39 struct bhi_vec_entry *bhi_vec = img_info->bhi_vec;
41 @@ -395,9 +393,10 @@ void mhi_fw_load_handler(struct mhi_cont
42 struct device *dev = &mhi_cntrl->mhi_dev->dev;
43 enum mhi_pm_state new_state;
52 if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
53 @@ -427,6 +426,20 @@ void mhi_fw_load_handler(struct mhi_cont
54 fw_name = (mhi_cntrl->ee == MHI_EE_EDL) ?
55 mhi_cntrl->edl_image : mhi_cntrl->fw_image;
57 + /* check if the driver has already provided the firmware data */
58 + if (!fw_name && mhi_cntrl->fbc_download &&
59 + mhi_cntrl->fw_data && mhi_cntrl->fw_sz) {
60 + if (!mhi_cntrl->sbl_size) {
61 + dev_err(dev, "fw_data provided but no sbl_size\n");
65 + size = mhi_cntrl->sbl_size;
66 + fw_data = mhi_cntrl->fw_data;
67 + fw_sz = mhi_cntrl->fw_sz;
71 if (!fw_name || (mhi_cntrl->fbc_download && (!mhi_cntrl->sbl_size ||
72 !mhi_cntrl->seg_len))) {
74 @@ -446,6 +459,10 @@ void mhi_fw_load_handler(struct mhi_cont
75 if (size > firmware->size)
76 size = firmware->size;
78 + fw_data = firmware->data;
79 + fw_sz = firmware->size;
82 buf = dma_alloc_coherent(mhi_cntrl->cntrl_dev, size, &dma_addr,
85 @@ -454,7 +471,7 @@ void mhi_fw_load_handler(struct mhi_cont
88 /* Download image using BHI */
89 - memcpy(buf, firmware->data, size);
90 + memcpy(buf, fw_data, size);
91 ret = mhi_fw_load_bhi(mhi_cntrl, dma_addr, size);
92 dma_free_coherent(mhi_cntrl->cntrl_dev, size, buf, dma_addr);
94 @@ -466,7 +483,7 @@ void mhi_fw_load_handler(struct mhi_cont
97 /* Wait for ready since EDL image was loaded */
98 - if (fw_name == mhi_cntrl->edl_image) {
99 + if (fw_name && fw_name == mhi_cntrl->edl_image) {
100 release_firmware(firmware);
101 goto fw_load_ready_state;
103 @@ -480,15 +497,14 @@ void mhi_fw_load_handler(struct mhi_cont
104 * device transitioning into MHI READY state
106 if (mhi_cntrl->fbc_download) {
107 - ret = mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->fbc_image,
109 + ret = mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->fbc_image, fw_sz);
111 release_firmware(firmware);
115 /* Load the firmware into BHIE vec table */
116 - mhi_firmware_copy(mhi_cntrl, firmware, mhi_cntrl->fbc_image);
117 + mhi_firmware_copy(mhi_cntrl, fw_data, fw_sz, mhi_cntrl->fbc_image);
120 release_firmware(firmware);
121 --- a/include/linux/mhi.h
122 +++ b/include/linux/mhi.h
123 @@ -301,6 +301,10 @@ struct mhi_controller_config {
124 * @iova_start: IOMMU starting address for data (required)
125 * @iova_stop: IOMMU stop address for data (required)
126 * @fw_image: Firmware image name for normal booting (optional)
127 + * @fw_data: Firmware image data content for normal booting, used only
128 + * if fw_image is NULL and fbc_download is true (optional)
129 + * @fw_sz: Firmware image data size for normal booting, used only if fw_image
130 + * is NULL and fbc_download is true (optional)
131 * @edl_image: Firmware image name for emergency download mode (optional)
132 * @rddm_size: RAM dump size that host should allocate for debugging purpose
133 * @sbl_size: SBL image size downloaded through BHIe (optional)
134 @@ -387,6 +391,8 @@ struct mhi_controller {
135 dma_addr_t iova_start;
136 dma_addr_t iova_stop;
137 const char *fw_image;
140 const char *edl_image;