a04b19b157342d34411ab91ca90ff9ddb48bf9ab
[openwrt/staging/blogic.git] /
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
4 firmware via a pointer
5
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.
11
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.
14
15 Tested with ath11k and WCN6855 hw2.0.
16
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>
23 ---
24
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:
28 }
29
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)
34 {
35 - size_t remainder = firmware->size;
36 size_t to_cpy;
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;
40
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;
44 const char *fw_name;
45 + const u8 *fw_data;
46 void *buf;
47 dma_addr_t dma_addr;
48 - size_t size;
49 + size_t size, fw_sz;
50 int i, ret;
51
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;
56
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");
62 + goto error_fw_load;
63 + }
64 +
65 + size = mhi_cntrl->sbl_size;
66 + fw_data = mhi_cntrl->fw_data;
67 + fw_sz = mhi_cntrl->fw_sz;
68 + goto skip_req_fw;
69 + }
70 +
71 if (!fw_name || (mhi_cntrl->fbc_download && (!mhi_cntrl->sbl_size ||
72 !mhi_cntrl->seg_len))) {
73 dev_err(dev,
74 @@ -446,6 +459,10 @@ void mhi_fw_load_handler(struct mhi_cont
75 if (size > firmware->size)
76 size = firmware->size;
77
78 + fw_data = firmware->data;
79 + fw_sz = firmware->size;
80 +
81 +skip_req_fw:
82 buf = dma_alloc_coherent(mhi_cntrl->cntrl_dev, size, &dma_addr,
83 GFP_KERNEL);
84 if (!buf) {
85 @@ -454,7 +471,7 @@ void mhi_fw_load_handler(struct mhi_cont
86 }
87
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);
93
94 @@ -466,7 +483,7 @@ void mhi_fw_load_handler(struct mhi_cont
95 }
96
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;
102 }
103 @@ -480,15 +497,14 @@ void mhi_fw_load_handler(struct mhi_cont
104 * device transitioning into MHI READY state
105 */
106 if (mhi_cntrl->fbc_download) {
107 - ret = mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->fbc_image,
108 - firmware->size);
109 + ret = mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->fbc_image, fw_sz);
110 if (ret) {
111 release_firmware(firmware);
112 goto error_fw_load;
113 }
114
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);
118 }
119
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;
138 + const u8 *fw_data;
139 + size_t fw_sz;
140 const char *edl_image;
141 size_t rddm_size;
142 size_t sbl_size;