From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 89B3CC433E0 for ; Fri, 10 Jul 2020 05:56:28 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 893D72076A for ; Fri, 10 Jul 2020 05:56:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kE6fw/2R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 893D72076A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4B32NT6m7TzDqpL for ; Fri, 10 Jul 2020 15:56:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::441; helo=mail-wr1-x441.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=kE6fw/2R; dkim-atps=neutral Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4B31gc6rqszDrG2 for ; Fri, 10 Jul 2020 15:24:28 +1000 (AEST) Received: by mail-wr1-x441.google.com with SMTP id z2so4575754wrp.2 for ; Thu, 09 Jul 2020 22:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XUxLjLbDTYPDEi7E9qhfkUQ6YJD3u2Zjb67u2EA9IBc=; b=kE6fw/2RwwSg/v1dbkBpfE5n6B3vLNrOYwHjJMH8ylEIQnw2v1lR8u9ZrMm7et07hE KlNgXChltwD+oJplM0Ood9ozQPm8tnpFkEUgyViWVlUjQx+jT7t/RMD5h8EWIPilScQh nTWkOtMqD8GOTnklyghAP6EmElQJK3TYe7M4BNkodKfiTLB315vDrH3XAlCZm+FkYp4b R2W57705OzTpbZ4DzBHuViq6gOSEA0eQgfcbKGxXLCRiWGM+J9FAECT2fN56/ieeyRX4 ZeQsy7+BFs8BwEcLEL6lUiGoWi/atU5lhBepEzmWnXhAj0lj7rbGjUsxSrkLabWS9rLN O4PA== 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=XUxLjLbDTYPDEi7E9qhfkUQ6YJD3u2Zjb67u2EA9IBc=; b=o0FN6TUAUJAF/PBjVyevP0ecIKQmgiqN5mbb+3utw5Yq/85CbJmTpdpUMKwDRwOppJ +iTUyu0Hv4sreSSbZpfuPVORzZc+nr8ZRl2rWlll/GlcTQ57/Dpu28L62YKpMSmfaBek a6PakGftdvIYrTIjCP7SDYIGIG1ns6Cr2sLg6yHGPhHdvHsEFIsK85jHGFKG0NTFYOH8 /gNYF7NIQT1ODroDs4BRI7Y2seiyAZZFufyPD4qSGSjWbTsPPDKtdEbtNHb4DK4nzZWn m0C0p0QKu0gOvDktLdk+1AvKn/Z6I/WAgR3/fUeMpSqdynVhGDhzutIMHa82cF4F8X4u ctZA== X-Gm-Message-State: AOAM5327N2p53ULIOk26x+1FhVBP9NqjOFRmLBrGy9bw5RPV26oUfx1S 0Swgbfr3FCeclcsTjctxYQ3wuUu7R6c= X-Google-Smtp-Source: ABdhPJzEK3tKpjrNJfrUKkGMflNhBGQVQ6fLcw4ORQo8CENOszQSIqGClEIXBh+YEIVGEtGsTs3nmg== X-Received: by 2002:adf:efcc:: with SMTP id i12mr65354547wrp.349.1594358666020; Thu, 09 Jul 2020 22:24:26 -0700 (PDT) Received: from 192-168-1-18.tpgi.com.au ([220.240.245.68]) by smtp.gmail.com with ESMTPSA id 92sm9090941wrr.96.2020.07.09.22.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 22:24:25 -0700 (PDT) From: Oliver O'Halloran To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 13/15] powerpc/powernv/sriov: Move M64 BAR allocation into a helper Date: Fri, 10 Jul 2020 15:23:38 +1000 Message-Id: <20200710052340.737567-14-oohall@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200710052340.737567-1-oohall@gmail.com> References: <20200710052340.737567-1-oohall@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oliver O'Halloran Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" I want to refactor the loop this code is currently inside of. Hoist it on out. Signed-off-by: Oliver O'Halloran --- arch/powerpc/platforms/powernv/pci-sriov.c | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci-sriov.c b/arch/powerpc/platforms/powernv/pci-sriov.c index d5699cd2ab7a..2f967aa4fbf5 100644 --- a/arch/powerpc/platforms/powernv/pci-sriov.c +++ b/arch/powerpc/platforms/powernv/pci-sriov.c @@ -416,6 +416,23 @@ static int64_t pnv_ioda_map_m64_single(struct pnv_phb *phb, return rc; } +static int pnv_pci_alloc_m64_bar(struct pnv_phb *phb, struct pnv_iov_data *iov) +{ + int win; + + do { + win = find_next_zero_bit(&phb->ioda.m64_bar_alloc, + phb->ioda.m64_bar_idx + 1, 0); + + if (win >= phb->ioda.m64_bar_idx + 1) + return -1; + } while (test_and_set_bit(win, &phb->ioda.m64_bar_alloc)); + + set_bit(win, iov->used_m64_bar_mask); + + return win; +} + static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, u16 num_vfs) { struct pnv_iov_data *iov; @@ -443,17 +460,9 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, u16 num_vfs) continue; for (j = 0; j < m64_bars; j++) { - - /* allocate a window ID for this BAR */ - do { - win = find_next_zero_bit(&phb->ioda.m64_bar_alloc, - phb->ioda.m64_bar_idx + 1, 0); - - if (win >= phb->ioda.m64_bar_idx + 1) - goto m64_failed; - } while (test_and_set_bit(win, &phb->ioda.m64_bar_alloc)); - set_bit(win, iov->used_m64_bar_mask); - + win = pnv_pci_alloc_m64_bar(phb, iov); + if (win < 0) + goto m64_failed; if (iov->m64_single_mode) { int pe_num = iov->vf_pe_arr[j].pe_number; -- 2.26.2