From patchwork Tue Jun 8 19:55:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 12308063 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=-16.9 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 9FEA4C4743F for ; Tue, 8 Jun 2021 19:58:10 +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 686046024A for ; Tue, 8 Jun 2021 19:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 686046024A 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=Zkn83wFmoCJSyph5ejHYFbfDFyZQfizLAHEA1GD0Hfo=; b=uiVe/YQol016gZ +yBE8FzcXcKZCN5crxHL2LLMOBDY3DoSDhaKhjti/A6dDYsBMXi4UgqqCxzDDh8LK9+EAmYOe31mv p4hvVsTkASchGupVVnMvznwSU20jQ1AH8d8SuX1kj6NxbYgwVkhyXKprYWtu10KtaOslaxvpKmR2E niXAeLJ8YpGFHbCOow4GOfOs8g6M1MckAlGOCEei7PBiwfBQ+xyCzEG6njn3H5Vv1XyNcxHpQCRgf 73y9r4YfnN7L6FDIudgo1zQI9xCnKGK1fpbZETiHUNme+fN62BiN53W3P9//H9Cn/pWlc/CN0zVA/ e/CdgZufAo0P2fElSfJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqhpZ-00AJkU-8k; Tue, 08 Jun 2021 19:56:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqhol-00AIhw-IM for linux-arm-kernel@lists.infradead.org; Tue, 08 Jun 2021 19:55:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623182118; 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=F+ieZpNx5CLGtvApXLWeUj3JhBAH5I6pceFuxGmJ04c=; b=aW1Ju9fn9klY+i12pZ3mYxo8xqV7vDjMFK+RkTLr6VC3swvbAVen2K16Z7dtD/1b6bu7nG ojy15X9wtaKbYjcT5xxJbgII8Gq5WrFb2FVMvVVw8rIp1dqKeSq8uKMjrFqqXQgeNJ6HkE +pGGzfKKpZSWISMitKmbUNr3WcCtrQg= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-iq1BRAZyMJWWqt-7Tq0kWg-1; Tue, 08 Jun 2021 15:55:17 -0400 X-MC-Unique: iq1BRAZyMJWWqt-7Tq0kWg-1 Received: by mail-oi1-f200.google.com with SMTP id l136-20020acaed8e0000b02901f3ebfedbf2so4454660oih.11 for ; Tue, 08 Jun 2021 12:55:16 -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=F+ieZpNx5CLGtvApXLWeUj3JhBAH5I6pceFuxGmJ04c=; b=Ob5rD5fUkMIqfFH2wbRfld02Ga6vadlwQrd2aiI0DKe47Znqnze6I6Ts/e7w+oWaYi T6SSKtFOqAkFG3sL3lZb069fs18ae1OtOVC3yA67ntViQvMwRNcXT7cj5XnfyPFUtd55 Iy1rNQ5BFxayEYUHImCO9LwWn+Sj5+4K9mqLi6vwRzvWdvRsk2vMXyMto/h3wLRkqPFT OXoeFktjPOgiwiTvG7vBN/O1Zmc+X9EQQiwIS2Gl3iV5i7Dic/CUrNFCIiEhT3x5mIvn XkqtApDIbqX1C6rF4D+D3vm9kQeK+8U1ICJrGZ9nptmt010w6xi4KKg0r4sk8myzo0Pc VUYg== X-Gm-Message-State: AOAM532LXZki9BqWU1SY0AQaU+4NJ9RCma/S90qleMfQwM/t/f1qK/ay rzgFqCiuP2BnvNcIso5WAMDs8nPvJ5fB6Mrtx0zd3zLWZCpsgPAp6prKbJYV3E5aEfLe3LeIYY5 pQHeOzhpGpyto6qbJlGhb+jK7S7mti5/HeKk= X-Received: by 2002:a9d:6d01:: with SMTP id o1mr3273295otp.285.1623182116397; Tue, 08 Jun 2021 12:55:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzSar9h1GULVkRSGLcpyrS0rYxMTcGF2lkZPgA01LIMglsS8alL7LOIgUpvolCuPMbXVdeVw== X-Received: by 2002:a9d:6d01:: with SMTP id o1mr3273286otp.285.1623182116240; Tue, 08 Jun 2021 12:55:16 -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 s17sm3024046oog.31.2021.06.08.12.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 12:55:15 -0700 (PDT) From: trix@redhat.com To: hao.wu@intel.com, mdf@kernel.org, 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 v2 3/7] fpga-mgr: wrap the write() op Date: Tue, 8 Jun 2021 12:55:02 -0700 Message-Id: <20210608195506.3022550-5-trix@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210608195506.3022550-1-trix@redhat.com> References: <20210608195506.3022550-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-20210608_125519_736406_7D146A4D X-CRM114-Status: GOOD ( 13.78 ) 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 An FPGA manager should not be required to provide a write function. Move the op check to the wrapper. Default to -EOPNOTSUP so its users will fail gracefully. Signed-off-by: Tom Rix --- drivers/fpga/fpga-mgr.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index dadad24015020..c484b4309b2f4 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -167,6 +167,13 @@ static int fpga_mgr_write_complete(struct fpga_manager *mgr, return 0; } +static int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count) +{ + if (mgr->mops && mgr->mops->write) + return mgr->mops->write(mgr, buf, count); + return -EOPNOTSUPP; +} + /** * fpga_mgr_buf_load_sg - load fpga from image in buffer from a scatter list * @mgr: fpga manager @@ -203,7 +210,7 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG); while (sg_miter_next(&miter)) { - ret = mgr->mops->write(mgr, miter.addr, miter.length); + ret = fpga_mgr_write(mgr, miter.addr, miter.length); if (ret) break; } @@ -233,7 +240,7 @@ 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 = mgr->mops->write(mgr, buf, count); + ret = fpga_mgr_write(mgr, buf, count); if (ret) { dev_err(&mgr->dev, "Error while writing image data to FPGA\n"); mgr->state = FPGA_MGR_STATE_WRITE_ERR; @@ -577,9 +584,7 @@ struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name, struct fpga_manager *mgr; int id, ret; - if (!mops || !mops->state || - (!mops->write && !mops->write_sg) || - (mops->write && mops->write_sg)) { + if (!mops || !mops->state) { dev_err(dev, "Attempt to register without fpga_manager_ops\n"); return NULL; }