From patchwork Fri Jun 25 19:58:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 12345863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EC20C2B9F4 for ; Fri, 25 Jun 2021 20:02:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 573C26195D for ; Fri, 25 Jun 2021 20:02:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 573C26195D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f8K8iZAzreyWCprSUJ0lABUXrimjUWjVJRU5X4h7TOM=; b=usxtMH/tXDEAUY QSeVhoG+9BF2oFBqZmEo4Iv7aVERUuVIPahaF1eP1KPDSq0Ma3LFrQ19PDvDFgwg33sNLqJ5Y3NuX ckVmKea/F+JlavUTgfp3J/yUJOjWKOLD4s805kjCzCouyVb21jtNL1slCzDK4sp3dqf9zgxwQ4GBM Hn4ciM/fbwMqhmSOeeTa0EIIS3zJKRMzX91LJLPTomwWq5VRU0H4MzeCx/YXmCS33YIgvPv421V2o sWjuzGrB31epZ9/bDyKxvRYPTi6RcR6CjSo/atkyPYvxajNmglwbgklbwRVcHVvkwsHe+HnK26ft8 /QPpvTA1DsfPiEieCTFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lws07-002lW0-8G; Fri, 25 Jun 2021 20:00:32 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwryo-002l6A-IH for linux-arm-kernel@lists.infradead.org; Fri, 25 Jun 2021 19:59:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624651149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rqSN7YKNu7jB+HrLuLUg+PFT/fO3y/oLnfYjNwzT7ZY=; b=GrkWYZbgLp2n1WUU6vJYoTQla9cqcqd2H0vnHt9HlRi+jaq2uAnHlC0v/uYOdCDuHgQMIB nLA92BJrrZrHIJy+xtamx/H9XmA/PBhnCjvbxvA2bkB60E32/mgBENHbr3aA9YLuIkF17k qMWwNa/Rij3GYGYZDI0CdmlSqf1Aey0= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-Exbd_5U0NyaSXMT1v5uuVg-1; Fri, 25 Jun 2021 15:59:08 -0400 X-MC-Unique: Exbd_5U0NyaSXMT1v5uuVg-1 Received: by mail-oo1-f72.google.com with SMTP id l13-20020a4aa78d0000b0290245c8f11ac2so6423242oom.11 for ; Fri, 25 Jun 2021 12:59:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rqSN7YKNu7jB+HrLuLUg+PFT/fO3y/oLnfYjNwzT7ZY=; b=p043mUQSZ0i2sVxyrVO535n3Ql2OWZxFWDlEMUoHMj1QzC6kMZETrURTp6fSJdSz8S wDJ6NZe5mQfsTVyxpK8yb10C2etAyOV9Tlv2l3Bu/AOQ0ZuKgVBoYiwvEjsPJWTAoM9G c6XVn4QP9yuwwAuHXqpWjjpRJmzRihP3EZoBM9H+En8gROh+Wn2/ZbmX06QQljAn75nB Nf0XDnLdpmf/CWH1w2+AwbNeOdgvqV6kbdlSc8OiDhsEEmUapqtHJeeL3qHrPFcRUYMX LZnpulSUhtQ/JRsdAxWqohb5t0IgabLaThSsM7rvfXSUZmORt0oinVMEd3dMLxwYMshW guWw== X-Gm-Message-State: AOAM532ds4QQ9CvUdUmP6a9ruaO4gPRxgHbmsEY/dNyzqqhbDovZcTjI SO4bfmgnePJZkzRlqlmIIvtsi28hgpzuvUNYGCLW38XI8rikccLFSBfKg6RONszKs9G8cd2mIBM t0Kq7WfaX6UgGqhHYyLev5DyQMagKua9nRn4= X-Received: by 2002:a9d:7748:: with SMTP id t8mr10592305otl.110.1624651147439; Fri, 25 Jun 2021 12:59:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu34MbJmcblH8cUFKOa/B1UaUgiD0OGN1o/K/VsRr/ozopnaksdv0CoB7hGyKwnTfZVZXWwg== X-Received: by 2002:a9d:7748:: with SMTP id t8mr10592285otl.110.1624651147242; Fri, 25 Jun 2021 12:59:07 -0700 (PDT) Received: from localhost.localdomain.com (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id r204sm1467374oih.11.2021.06.25.12.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 12:59:06 -0700 (PDT) From: trix@redhat.com To: mdf@kernel.org, hao.wu@intel.com, michal.simek@xilinx.com Cc: linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Tom Rix Subject: [PATCH v5 3/4] fpga: pass fpga_manager_update_ops to the fpga_manager_write functions Date: Fri, 25 Jun 2021 12:58:48 -0700 Message-Id: <20210625195849.837976-5-trix@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210625195849.837976-1-trix@redhat.com> References: <20210625195849.837976-1-trix@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=trix@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210625_125910_768767_01689A76 X-CRM114-Status: GOOD ( 21.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Tom Rix Refactor fpga_manager_write* functions for reimaging, pass the update_ops as a parameter. Continue the passing of the update_ops to the write wrapper functions. Only do the reconfig ops. Signed-off-by: Tom Rix --- drivers/fpga/fpga-mgr.c | 90 ++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 31c51d7e07cc8..c8a6bfa037933 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -45,10 +45,12 @@ static inline u64 fpga_mgr_status(struct fpga_manager *mgr) return 0; } -static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count) +static inline int fpga_mgr_write(struct fpga_manager *mgr, + const char *buf, size_t count, + const struct fpga_manager_update_ops *uops) { if (mgr->mops->reconfig.write) - return mgr->mops->reconfig.write(mgr, buf, count); + return uops->write(mgr, buf, count); return -EOPNOTSUPP; } @@ -57,13 +59,14 @@ static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size * finish and set the FPGA into operating mode. */ static inline int fpga_mgr_write_complete(struct fpga_manager *mgr, - struct fpga_image_info *info) + struct fpga_image_info *info, + const struct fpga_manager_update_ops *uops) { int ret = 0; mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE; - if (mgr->mops->reconfig.write_complete) - ret = mgr->mops->reconfig.write_complete(mgr, info); + if (uops->write_complete) + ret = uops->write_complete(mgr, info); if (ret) { dev_err(&mgr->dev, "Error after writing image data to FPGA\n"); mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR; @@ -76,18 +79,20 @@ static inline int fpga_mgr_write_complete(struct fpga_manager *mgr, static inline int fpga_mgr_write_init(struct fpga_manager *mgr, struct fpga_image_info *info, - const char *buf, size_t count) + const char *buf, size_t count, + const struct fpga_manager_update_ops *uops) { - if (mgr->mops->reconfig.write_init) - return mgr->mops->reconfig.write_init(mgr, info, buf, count); + if (uops->write_init) + return uops->write_init(mgr, info, buf, count); return 0; } static inline int fpga_mgr_write_sg(struct fpga_manager *mgr, - struct sg_table *sgt) + struct sg_table *sgt, + const struct fpga_manager_update_ops *uops) { - if (mgr->mops->reconfig.write_sg) - return mgr->mops->reconfig.write_sg(mgr, sgt); + if (uops->write_sg) + return uops->write_sg(mgr, sgt); return -EOPNOTSUPP; } @@ -143,16 +148,17 @@ EXPORT_SYMBOL_GPL(fpga_image_info_free); */ static int fpga_mgr_write_init_buf(struct fpga_manager *mgr, struct fpga_image_info *info, - const char *buf, size_t count) + const char *buf, size_t count, + const struct fpga_manager_update_ops *uops) { int ret; mgr->state = FPGA_MGR_STATE_WRITE_INIT; if (!mgr->mops->initial_header_size) - ret = fpga_mgr_write_init(mgr, info, NULL, 0); + ret = fpga_mgr_write_init(mgr, info, NULL, 0, uops); else ret = fpga_mgr_write_init( - mgr, info, buf, min(mgr->mops->initial_header_size, count)); + mgr, info, buf, min(mgr->mops->initial_header_size, count), uops); if (ret) { dev_err(&mgr->dev, "Error preparing FPGA for writing\n"); @@ -165,7 +171,8 @@ static int fpga_mgr_write_init_buf(struct fpga_manager *mgr, static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, struct fpga_image_info *info, - struct sg_table *sgt) + struct sg_table *sgt, + const struct fpga_manager_update_ops *uops) { struct sg_mapping_iter miter; size_t len; @@ -173,7 +180,7 @@ static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, int ret; if (!mgr->mops->initial_header_size) - return fpga_mgr_write_init_buf(mgr, info, NULL, 0); + return fpga_mgr_write_init_buf(mgr, info, NULL, 0, uops); /* * First try to use miter to map the first fragment to access the @@ -183,7 +190,7 @@ static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, if (sg_miter_next(&miter) && miter.length >= mgr->mops->initial_header_size) { ret = fpga_mgr_write_init_buf(mgr, info, miter.addr, - miter.length); + miter.length, uops); sg_miter_stop(&miter); return ret; } @@ -196,7 +203,7 @@ static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, len = sg_copy_to_buffer(sgt->sgl, sgt->nents, buf, mgr->mops->initial_header_size); - ret = fpga_mgr_write_init_buf(mgr, info, buf, len); + ret = fpga_mgr_write_init_buf(mgr, info, buf, len, uops); kfree(buf); @@ -208,6 +215,7 @@ static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, * @mgr: fpga manager * @info: fpga image specific information * @sgt: scatterlist table + * @uops: which update ops to use * * Step the low level fpga manager through the device-specific steps of getting * an FPGA ready to be configured, writing the image to it, then doing whatever @@ -222,24 +230,25 @@ static int fpga_mgr_write_init_sg(struct fpga_manager *mgr, */ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, struct fpga_image_info *info, - struct sg_table *sgt) + struct sg_table *sgt, + const struct fpga_manager_update_ops *uops) { int ret; - ret = fpga_mgr_write_init_sg(mgr, info, sgt); + ret = fpga_mgr_write_init_sg(mgr, info, sgt, uops); if (ret) return ret; /* Write the FPGA image to the FPGA. */ mgr->state = FPGA_MGR_STATE_WRITE; - if (mgr->mops->reconfig.write_sg) { - ret = fpga_mgr_write_sg(mgr, sgt); + if (uops->write_sg) { + ret = fpga_mgr_write_sg(mgr, sgt, uops); } else { struct sg_mapping_iter miter; sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG); while (sg_miter_next(&miter)) { - ret = fpga_mgr_write(mgr, miter.addr, miter.length); + ret = fpga_mgr_write(mgr, miter.addr, miter.length, uops); if (ret) break; } @@ -252,16 +261,17 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, return ret; } - return fpga_mgr_write_complete(mgr, info); + return fpga_mgr_write_complete(mgr, info, uops); } static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, struct fpga_image_info *info, - const char *buf, size_t count) + const char *buf, size_t count, + const struct fpga_manager_update_ops *uops) { int ret; - ret = fpga_mgr_write_init_buf(mgr, info, buf, count); + ret = fpga_mgr_write_init_buf(mgr, info, buf, count, uops); if (ret) return ret; @@ -269,14 +279,14 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, * Write the FPGA image to the FPGA. */ mgr->state = FPGA_MGR_STATE_WRITE; - ret = fpga_mgr_write(mgr, buf, count); + ret = fpga_mgr_write(mgr, buf, count, uops); if (ret) { dev_err(&mgr->dev, "Error while writing image data to FPGA\n"); mgr->state = FPGA_MGR_STATE_WRITE_ERR; return ret; } - return fpga_mgr_write_complete(mgr, info); + return fpga_mgr_write_complete(mgr, info, uops); } /** @@ -285,6 +295,7 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, * @info: fpga image info * @buf: buffer contain fpga image * @count: byte count of buf + * @uops: which update ops to use * * Step the low level fpga manager through the device-specific steps of getting * an FPGA ready to be configured, writing the image to it, then doing whatever @@ -295,7 +306,8 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, */ static int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info, - const char *buf, size_t count) + const char *buf, size_t count, + const struct fpga_manager_update_ops *uops) { struct page **pages; struct sg_table sgt; @@ -309,8 +321,8 @@ static int fpga_mgr_buf_load(struct fpga_manager *mgr, * contiguous kernel buffer and the driver doesn't require SG, non-SG * drivers will still work on the slow path. */ - if (mgr->mops->reconfig.write) - return fpga_mgr_buf_load_mapped(mgr, info, buf, count); + if (uops && uops->write) + return fpga_mgr_buf_load_mapped(mgr, info, buf, count, uops); /* * Convert the linear kernel pointer into a sg_table of pages for use @@ -345,7 +357,7 @@ static int fpga_mgr_buf_load(struct fpga_manager *mgr, if (rc) return rc; - rc = fpga_mgr_buf_load_sg(mgr, info, &sgt); + rc = fpga_mgr_buf_load_sg(mgr, info, &sgt, uops); sg_free_table(&sgt); return rc; @@ -356,6 +368,7 @@ static int fpga_mgr_buf_load(struct fpga_manager *mgr, * @mgr: fpga manager * @info: fpga image specific information * @image_name: name of image file on the firmware search path + * @uops: which update ops to use * * 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 @@ -367,7 +380,8 @@ static int fpga_mgr_buf_load(struct fpga_manager *mgr, */ static int fpga_mgr_firmware_load(struct fpga_manager *mgr, struct fpga_image_info *info, - const char *image_name) + const char *image_name, + const struct fpga_manager_update_ops *uops) { struct device *dev = &mgr->dev; const struct firmware *fw; @@ -384,7 +398,7 @@ static int fpga_mgr_firmware_load(struct fpga_manager *mgr, return ret; } - ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size); + ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size, uops); release_firmware(fw); @@ -403,12 +417,14 @@ static int fpga_mgr_firmware_load(struct fpga_manager *mgr, */ int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info) { + const struct fpga_manager_update_ops *uops = &mgr->mops->reconfig; + if (info->sgt) - return fpga_mgr_buf_load_sg(mgr, info, info->sgt); + return fpga_mgr_buf_load_sg(mgr, info, info->sgt, uops); if (info->buf && info->count) - return fpga_mgr_buf_load(mgr, info, info->buf, info->count); + return fpga_mgr_buf_load(mgr, info, info->buf, info->count, uops); if (info->firmware_name) - return fpga_mgr_firmware_load(mgr, info, info->firmware_name); + return fpga_mgr_firmware_load(mgr, info, info->firmware_name, uops); return -EINVAL; } EXPORT_SYMBOL_GPL(fpga_mgr_load);