Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9117508rwl; Wed, 11 Jan 2023 01:29:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXseDOG/Emz0PaHQujxLvzt1eZIMaQVsqjYk4dLMQsEfXymgHIlb8eqd4M9L8iP4gIscuWel X-Received: by 2002:a17:902:8f97:b0:192:ad96:10d4 with SMTP id z23-20020a1709028f9700b00192ad9610d4mr40832544plo.7.1673429348808; Wed, 11 Jan 2023 01:29:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673429348; cv=none; d=google.com; s=arc-20160816; b=jtb5LovWSOFP+wuGTempAK2xhaz9rOPb8J3mbkto3Mv+LqVrG+ipQL4LE3cWk0bXOh HOk4TtzbuazRE6fbhkjptoW7gIt6omdQfjjAXs/CCbg74I16VgwL/QcizTuw2VRS4un6 b97DpWigSOQqVivc/NzZESoiRZJPOojdx8TZWnmrMSKh8sXV0C+JO6IzX6Ap3gSWc7Qd d/HoTOTw21Es6jwmjEQVLKgctq0ojuRydhl1ptS7sFop4G6hi+oWvtsnfS9Dz39KNWrw X2V/k1sBvfzNaLcMd9qDc8RzguDsbGtD5hIzzNSFd20eSsWlvP1f88YMOG1xsO1pXTBE vZkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D8IntLh9y8qn2ucxzjveDOAYhwIzdFW6FiC5I1CL14g=; b=KICdd1ewaJPQYJHzLoE+fpNKOnGUZhTYF1gv0dGj8VcsauWUFUw2qrKyQbgSwMp/9f Gm7naD3aG3+jn0ibfxmneJKbQ6mDdX3nY81btnL98vW/sMNFWOiY6PHX3Dwzji3IyBYm JZn343vjwIwiNS2X8bDj6heE/C9Uhkx3fHHzg5MJcVYcRjTC4DSqfTVqhRzKOjsWj8XL vuViXUxVcDWw+QPHCSJmpoOZyhJnXa/aOKuew0imdVUd7mEQvooK2iL2EF0uPr14vgtn 0qxiMJQMO+DsfLv5pqgmv4+cfvyF6csdj8FIHz9WU8cRIZGB96erKK7hNxCFlbPOGEFM EBOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a+XENMxi; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902ec8100b00189e2b9e630si14815847plg.270.2023.01.11.01.29.01; Wed, 11 Jan 2023 01:29:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a+XENMxi; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjAKJ1E (ORCPT + 65 others); Wed, 11 Jan 2023 04:27:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbjAKJ0Z (ORCPT ); Wed, 11 Jan 2023 04:26:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD16F4F for ; Wed, 11 Jan 2023 01:25:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 247C161B20 for ; Wed, 11 Jan 2023 09:25:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8171C433EF; Wed, 11 Jan 2023 09:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673429153; bh=kLmYwShz2xeYyy2k3zaai252O8SuZ5TMqTM79yByxjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a+XENMxiE9l20MOiRkQQLJN+wOCXWd6JKAiaEPmd6t2L/rXY2wBDtmzHrWSE9oegk KOWTAIWM73r4C9eNmevh8d4mElEimXA6entZrGT97OQauO9V90RrJrM2XL4jpw8gcM eZkQmFZdJsukCaM67/6Dpy1C2eBFfcD/kWzEQm48PQCXJWfInuaGM/u61h9vp9mHJE iQt+wKfQpheN97XlvmwkXIsv7KOYe5rB4LcmB7cuG0Iwa44ursxv6is2eX04C85Un7 3OSPq+yQSTj1qnAc6buhEGZ4UZ2w4SxJdh5wLPgwyPHXmuFkPKpw8vVduyj0ahpicA e380YpBc+uP0Q== From: Kalle Valo To: mhi@lists.linux.dev Cc: ath11k@lists.infradead.org, linux-wireless@vger.kernel.org Subject: [PATCH 1/3] mhi: allow MHI client drivers to provide the firmware via a pointer Date: Wed, 11 Jan 2023 11:25:45 +0200 Message-Id: <20230111092547.21425-2-kvalo@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230111092547.21425-1-kvalo@kernel.org> References: <20230111092547.21425-1-kvalo@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Kalle Valo Currently MHI loads the firmware image from the path provided by client devices. ath11k needs to support firmware image embedded along with meta data (named as firmware-2.bin). So allow the client driver to request the firmware file from user space on it's own and provide the firmware image data and size to MHI via a pointer struct mhi_controller::fw_data. This is an optional feature, if fw_data is NULL MHI load the firmware using the name from struct mhi_controller::fw_image string as before. Tested with ath11k and WCN6855 hw2.0. Signed-off-by: Kalle Valo --- drivers/bus/mhi/host/boot.c | 27 +++++++++++++++++++-------- include/linux/mhi.h | 6 ++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c index 1c69feee1703..d6d5f424491e 100644 --- a/drivers/bus/mhi/host/boot.c +++ b/drivers/bus/mhi/host/boot.c @@ -365,12 +365,10 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl, } static void mhi_firmware_copy(struct mhi_controller *mhi_cntrl, - const struct firmware *firmware, + const u8 *buf, size_t remainder, struct image_info *img_info) { - size_t remainder = firmware->size; size_t to_cpy; - const u8 *buf = firmware->data; struct mhi_buf *mhi_buf = img_info->mhi_buf; struct bhi_vec_entry *bhi_vec = img_info->bhi_vec; @@ -392,9 +390,10 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) const struct firmware *firmware = NULL; struct device *dev = &mhi_cntrl->mhi_dev->dev; const char *fw_name; + const u8 *fw_data; void *buf; dma_addr_t dma_addr; - size_t size; + size_t size, fw_sz; int i, ret; if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) { @@ -424,6 +423,14 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) fw_name = (mhi_cntrl->ee == MHI_EE_EDL) ? mhi_cntrl->edl_image : mhi_cntrl->fw_image; + if (!fw_name && mhi_cntrl->fbc_download && + mhi_cntrl->fw_data && mhi_cntrl->fw_sz) { + size = mhi_cntrl->sbl_size; + fw_data = mhi_cntrl->fw_data; + fw_sz = mhi_cntrl->fw_sz; + goto skip_req_fw; + } + if (!fw_name || (mhi_cntrl->fbc_download && (!mhi_cntrl->sbl_size || !mhi_cntrl->seg_len))) { dev_err(dev, @@ -443,6 +450,10 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) if (size > firmware->size) size = firmware->size; + fw_data = firmware->data; + fw_sz = firmware->size; + +skip_req_fw: buf = dma_alloc_coherent(mhi_cntrl->cntrl_dev, size, &dma_addr, GFP_KERNEL); if (!buf) { @@ -451,7 +462,7 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) } /* Download image using BHI */ - memcpy(buf, firmware->data, size); + memcpy(buf, fw_data, size); ret = mhi_fw_load_bhi(mhi_cntrl, dma_addr, size); dma_free_coherent(mhi_cntrl->cntrl_dev, size, buf, dma_addr); @@ -463,7 +474,7 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) } /* Wait for ready since EDL image was loaded */ - if (fw_name == mhi_cntrl->edl_image) { + if (fw_name && fw_name == mhi_cntrl->edl_image) { release_firmware(firmware); goto fw_load_ready_state; } @@ -478,14 +489,14 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) */ if (mhi_cntrl->fbc_download) { ret = mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->fbc_image, - firmware->size); + fw_sz); if (ret) { release_firmware(firmware); goto error_fw_load; } /* Load the firmware into BHIE vec table */ - mhi_firmware_copy(mhi_cntrl, firmware, mhi_cntrl->fbc_image); + mhi_firmware_copy(mhi_cntrl, fw_data, fw_sz, mhi_cntrl->fbc_image); } release_firmware(firmware); diff --git a/include/linux/mhi.h b/include/linux/mhi.h index a5441ad33c74..0d11fe22633e 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -299,6 +299,10 @@ struct mhi_controller_config { * @iova_start: IOMMU starting address for data (required) * @iova_stop: IOMMU stop address for data (required) * @fw_image: Firmware image name for normal booting (optional) + * @fw_data: Firmware image data content for normal booting, used only + * if fw_image is NULL (optional) + * @fw_sz: Firmware image data size for normal booting, used only if fw_image + * is NULL (optional) * @edl_image: Firmware image name for emergency download mode (optional) * @rddm_size: RAM dump size that host should allocate for debugging purpose * @sbl_size: SBL image size downloaded through BHIe (optional) @@ -384,6 +388,8 @@ struct mhi_controller { dma_addr_t iova_start; dma_addr_t iova_stop; const char *fw_image; + const u8 *fw_data; + size_t fw_sz; const char *edl_image; size_t rddm_size; size_t sbl_size; -- 2.30.2