From patchwork Fri Jun 25 19:51:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rix X-Patchwork-Id: 12345831 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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 895C8C2B9F4 for ; Fri, 25 Jun 2021 19:54:30 +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 5403260FDB for ; Fri, 25 Jun 2021 19:54:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5403260FDB 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=IRZOTGIUq/TBEeiw5c1QQrOUSKIz/1KcszBgoQjBbZM=; b=kjQca4eCM3INKg I5wxmyduINVI+V3K3RodCa5RoLJy6plQxqb34k8WjRp7slVPpm2h0hPGMQUnlaZY1vq7fvHj7S11L /MnArztCXkpRY/zkTtfo/UtgYePFK4jEJzwtk/G8v3bvBVayHxtPCmLwBHhBjhrSDmQzT3OWpdwGn vEQgrb+qRmntnbo29WneEhNpCmB9vSPhvo/nYw4qFhxIPmrWEiMOL7U//8p57QfMKwOO+De+CP0kn iHYQCQCnIVDgppohb1AoY9oXRRS5ASkNGDlElhniFHomw6kUUa9xo5DzkqKJGdhh7yGweP9LBjYpD mVHm7450IG8XPAyMXsvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwrsT-002ibS-74; Fri, 25 Jun 2021 19:52:37 +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 1lwrs5-002iWA-JV for linux-arm-kernel@lists.infradead.org; Fri, 25 Jun 2021 19:52:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624650732; 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=zmCqJFhviJpySBAFzJy5r5IMKlvduxQc5V68S9Vd+94=; b=cvY7S6BPqSoFyQBi7gEVp4bIpY59lktA8toNFI650tzlI0k7BfJuEROxGW9/tZm00FCe5D ERj8JnmhSibPtp5QMVhXGLj8O5wpILhl5slu+imMAnQRQUa/emYigT9/g6WGwIF39uu9/S RWDv8NEnvHv7I0/Ra6VFZTiT9+hi5XQ= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-VfSU4LLZNvKHm9paLnqlNg-1; Fri, 25 Jun 2021 15:52:11 -0400 X-MC-Unique: VfSU4LLZNvKHm9paLnqlNg-1 Received: by mail-oi1-f199.google.com with SMTP id b12-20020a056808010cb029021dde407eb3so6536504oie.13 for ; Fri, 25 Jun 2021 12:52:11 -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=zmCqJFhviJpySBAFzJy5r5IMKlvduxQc5V68S9Vd+94=; b=EgS8IPZ0GpTYucBkY12L6kIgJ2t71eG/ikk62jKClswWIzprcSX9NN15MPuf6rKfIO 9eXOL2F8YnkmqmNbbIDhDGN/XaHo0xN5CK+qJ4KXvXOSmCieChN9WI8zQmjNVM4BzrKx n6hwyJsCeCTB+30/Z9nv/ZROWgU68PQ52Qw1YA3nEyR3p9WUanmLBC8ub/nvQm4CP9T6 Rle7LRGa+VOfVTCRYLvdn+j05CrGf4mpOSuk51+JeoWtNFeV8cnTIpLvThuClfk680c8 6IZyYBlULuWAk6zN0+5vKiDhghqEODNM8svK1ag71Y1uzjxQX36J7iwvr/QsLR7JRsbR KJIg== X-Gm-Message-State: AOAM533qb3FePzhNMHLD2Ecv9IkWgN0CLw3glhUFMQIZI2jvcrYiC298 +Oq9Db5IeRpuGMaid+5qoP1GFo4tdqO4jupPDs+4NnCYP8rgeBJs0CdG4HIIRaPrqPQ3fU1xYaW ewQrsvZEGqMStIXLpydUX5UOuCUdTUI5lWjY= X-Received: by 2002:a9d:6f10:: with SMTP id n16mr11442604otq.165.1624650730698; Fri, 25 Jun 2021 12:52:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyrgSs3HSrKX/eB4qtz68tFE9zA+wja/zPnCCLulswoCm4r95WfyEGRwhxQDpXEZZe+Gx01A== X-Received: by 2002:a9d:6f10:: with SMTP id n16mr11442598otq.165.1624650730534; Fri, 25 Jun 2021 12:52:10 -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 o25sm1535446ood.20.2021.06.25.12.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 12:52:10 -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 v4 3/7] fpga-mgr: wrap the write() op Date: Fri, 25 Jun 2021 12:51:44 -0700 Message-Id: <20210625195148.837230-5-trix@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210625195148.837230-1-trix@redhat.com> References: <20210625195148.837230-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_125213_774585_51FBF4EB X-CRM114-Status: GOOD ( 14.67 ) 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 05a69ab3ecb9e..8d5536d748081 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -25,6 +25,13 @@ struct fpga_mgr_devres { struct fpga_manager *mgr; }; +static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count) +{ + if (mgr->mops->write) + return mgr->mops->write(mgr, buf, count); + return -EOPNOTSUPP; +} + /* * After all the FPGA image has been written, do the device specific steps to * finish and set the FPGA into operating mode. @@ -204,7 +211,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; } @@ -234,7 +241,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; @@ -578,9 +585,7 @@ struct fpga_manager *fpga_mgr_create(struct device *parent, 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(parent, "Attempt to register without fpga_manager_ops\n"); return NULL; }