From patchwork Fri Mar 10 00:18:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yi" X-Patchwork-Id: 9614387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D4D4602B4 for ; Fri, 10 Mar 2017 00:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F544286B4 for ; Fri, 10 Mar 2017 00:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63610286E5; Fri, 10 Mar 2017 00:23:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0039286B4 for ; Fri, 10 Mar 2017 00:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754139AbdCJAWw (ORCPT ); Thu, 9 Mar 2017 19:22:52 -0500 Received: from mga04.intel.com ([192.55.52.120]:56023 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754418AbdCJAWk (ORCPT ); Thu, 9 Mar 2017 19:22:40 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 16:22:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,137,1486454400"; d="scan'208";a="1120701764" Received: from yi-patch.an.intel.com ([10.122.105.158]) by fmsmga001.fm.intel.com with ESMTP; 09 Mar 2017 16:22:38 -0800 From: yi1.li@linux.intel.com To: ming.lei@canonical.com, mcgrof@kernel.org, gregkh@linuxfoundation.org, atull@opensource.altera.com, moritz.fischer@ettus.com, linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Cc: Yi Li Subject: [RFC 2/2] fpga manager: Add fpga_mgr_firmware_stream API Date: Thu, 9 Mar 2017 18:18:10 -0600 Message-Id: <1489105090-4996-3-git-send-email-yi1.li@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489105090-4996-1-git-send-email-yi1.li@linux.intel.com> References: <1489105090-4996-1-git-send-email-yi1.li@linux.intel.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yi Li Add fpga_mgr_firmware_stream API, which can load and program firmware in trucks to FPGA instead of the whole file. Signed-off-by: Yi Li --- drivers/fpga/fpga-mgr.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fpga/fpga-mgr.h | 4 +++ 2 files changed, 81 insertions(+) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 3206a53..bb55b80 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -27,10 +27,15 @@ #include #include #include +#include static DEFINE_IDA(fpga_mgr_ida); static struct class *fpga_mgr_class; +static int streamsize = SZ_4K; +module_param(streamsize, int, 0664); +MODULE_PARM_DESC(streamsize, "buffer size for firmware streaming"); + /* * Call the low level driver's write_init function. This will do the * device-specific things to get the FPGA into the state where it is ready to @@ -309,6 +314,78 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, } EXPORT_SYMBOL_GPL(fpga_mgr_firmware_load); +/** + * fpga_mgr_firmware_load - request firmware and load to fpga + * @mgr: fpga manager + * @info: fpga image specific information + * @image_name: name of image file on the firmware search path + * + * Request an FPGA image using the firmware class, then write out to the FPGA. + * Update the state before each step to provide info on what step failed if + * there is a failure. This code assumes the caller got the mgr pointer + * from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error + * code. + * + * Return: 0 on success, negative error code otherwise. + */ +int fpga_mgr_firmware_stream(struct fpga_manager *mgr, + struct fpga_image_info *info, + const char *image_name) +{ + struct device *dev = &mgr->dev; + const struct firmware *fw = NULL; + int ret; + size_t size = INT_MAX, offset = 0; + bool start_flag = 1; + + dev_info(dev, "writing %s to %s with buffer size %d\n", + image_name, mgr->name, streamsize); + + mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ; + + while (size > 0) { + ret = stream_firmware(&fw, image_name, dev, offset, streamsize); + if (ret) { + dev_err(dev, "Error reading firmware %d\n", ret); + mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR; + break; + } + + /* + * init. + */ + if (start_flag) { + ret = fpga_mgr_write_init_buf(mgr, info, fw->data, + fw->size); + start_flag = 0; + if (ret) + break; + } + + /* + * Write the FPGA image to the FPGA. + */ + mgr->state = FPGA_MGR_STATE_WRITE; + ret = mgr->mops->write(mgr, fw->data, fw->size); + if (ret) { + dev_err(dev, "Error while writing image data to FPGA\n"); + mgr->state = FPGA_MGR_STATE_WRITE_ERR; + break; + } + + offset += fw->size; + size -= fw->size; + if (fw->size < streamsize) + break; + } + + ret = fpga_mgr_write_complete(mgr, info); + + release_firmware(fw); + return ret; +} +EXPORT_SYMBOL_GPL(fpga_mgr_firmware_stream); + int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info) { if (info->firmware_name) diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 0f5072c..a25362e 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -151,6 +151,10 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, struct fpga_image_info *info, const char *image_name); +int fpga_mgr_firmware_stream(struct fpga_manager *mgr, + struct fpga_image_info *info, + const char *image_name); + int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info); int fpga_mgr_lock(struct fpga_manager *mgr);