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=-11.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 A26CFC433E2 for ; Wed, 15 Jul 2020 00:42:48 +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 D9E1320674 for ; Wed, 15 Jul 2020 00:42:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ozlabs-ru.20150623.gappssmtp.com header.i=@ozlabs-ru.20150623.gappssmtp.com header.b="acZsiaC0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9E1320674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru 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 4B5zBF65X3zDqcS for ; Wed, 15 Jul 2020 10:42:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=2607:f8b0:4864:20::1041; helo=mail-pj1-x1041.google.com; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ozlabs-ru.20150623.gappssmtp.com header.i=@ozlabs-ru.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=acZsiaC0; dkim-atps=neutral Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (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 4B5z862QkxzDqXb for ; Wed, 15 Jul 2020 10:40:51 +1000 (AEST) Received: by mail-pj1-x1041.google.com with SMTP id ch3so720676pjb.5 for ; Tue, 14 Jul 2020 17:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=MMhhlrOlDMJWw529RkMnkW2xX3T2OucyhtjKJ1ZiCmU=; b=acZsiaC0wF5v4Wp9tn0dCYOdOaYWzeg5karcie1Nu1CP0OLFJmuiRmmrQDbE3vAp37 Ms4aEvNJHfcs6RWerpmJ7arf0XWFAtl7FtyFMrklISWTU8SWeofgPXNLAPTEf/jPx9p+ 6pnFlcqD6xkYjJzrEsZol32ZEhyNh7vvwiCjcv0jys4Dcwbn2HAdJG41FiFc5X60XGJy 0UctrS3cSjcvoWxVK42/n+G0TbcyJ+BC7MYRmRG+NCdykzWQC/2fjnLB+12WpoYHeKaL pRm6VYGJOxVDYj+JclLAI1hF+teB8UlO8LNFgC9RyaszEUeebAoW5VbLNnIs29YwkFN9 7ZnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MMhhlrOlDMJWw529RkMnkW2xX3T2OucyhtjKJ1ZiCmU=; b=WtU0en/j+1dQ7yOFvr+ao+BrMgbI3EAbsWf7RSZpRJOefBo0BYnvnxp9G+K5OWKH3j dxz/ATy0l0XPcYky4wO/4wNQmHvdWD07FPtzUTcNdmoEin5PeEra7Ait85U8f4dwMHry FQ53NbV7qPu1ZCyR0q1OVQxBb7S2C8Xm/QuwrXPnE3of2xNwlagCfWfuXMXelOkaLTvq dfkzfevgFG8oYwDLIgsZtm1pE+6uXRoLGZrGGfDMt6JGGKC9qseZoyIAkv/v18xWwvkw 61TtI7pLNk1TgAu7xwLMT65x0ln/7HldvGrTcn3khPzL5RnGAnlN9hj5HyOtQAuuBl/i lK3Q== X-Gm-Message-State: AOAM530hBV9+q2z2L5fh6Vn0s+ei/c2XQTTIs6d/ZBEn+kHK4ttoXfAK xD//01rDWMVQbzg1MjDFcAUvMwhcliu9Lw== X-Google-Smtp-Source: ABdhPJyokL4Fv4GfazQRNXGElvh5V4Ra24/+OYjvKilfT9lpJIAAHnuKCbQR8/tOhTvSCt244S63Gw== X-Received: by 2002:a17:902:d911:: with SMTP id c17mr5842267plz.227.1594773648088; Tue, 14 Jul 2020 17:40:48 -0700 (PDT) Received: from [192.168.10.94] (124-171-83-152.dyn.iinet.net.au. [124.171.83.152]) by smtp.gmail.com with ESMTPSA id n63sm272824pfd.209.2020.07.14.17.40.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jul 2020 17:40:47 -0700 (PDT) Subject: Re: [PATCH 06/15] powerpc/powernv/sriov: Explain how SR-IOV works on PowerNV To: Oliver O'Halloran , linuxppc-dev@lists.ozlabs.org References: <20200710052340.737567-1-oohall@gmail.com> <20200710052340.737567-7-oohall@gmail.com> From: Alexey Kardashevskiy Autocrypt: addr=aik@ozlabs.ru; keydata= m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z92oyZXHq81+k5Fj/YA1y2PI4MdHO4QobzgREoPGDkn6QlbJUBf4To pEbIGgW5LRPLuFlOPWHmIS/sdXDrllPc29aX2P7zdD/ivHABslHmt7vN3QY+hG0xgsCO1JG5 pLORF2N5XpM95zxkZqvYfC5tS/qhKyMcn1kC0fcRySVVeR3tUkU8/caCqxOqeMe2B6yTiU1P aNDq25qYFLeYxg67D/4w/P6BvNxNxk8hx6oQ10TOlnmeWp1q0cuutccblU3ryRFLDJSngTEu ZgnOt5dUFuOZxmMkqXGPHP1iOb+YDznHmC0FYZFG2KAc9pO0WuO7uT70lL6larTQrEneTDxQ CMQLP3qAJ/2aBH6SzHIQ7sfbsxy/63jAiHiT3cOaxAKsWkoV2HQpnmPOJ9u02TPjYmdpeIfa X2tXyeBixa3i/6dWJ4nIp3vGQicQkut1YBwR7dJq67/FCV3Mlj94jI0myHT5PIrCS2S8LtWX ikTJSxWUKmh7OP5mrqhwNe0ezgGiWxxvyNwThOHc5JvpzJLd32VDFilbxgu4Hhnf6LcgZJ2c Zd44XWqUu7FzVOYaSgIvTP0hNrBYm/E6M7yrLbs3JY74fGzPWGRbBUHTZXQEqQnZglXaVB5V ZhSFtHopZnBSCUSNDbB+QGy4B/E++Bb02IBTGl/JxmOwG+kZUnymsPvTtnNIeTLHxN/H/ae0 c7E5M+/NpslPCmYnDjs5qg0/3ihh6XuOGggZQOqrYPC3PnsNs3NxirwOkVPQgO6mXxpuifvJ DG9EMkK8IBXnLulqVk54kf7fE0jT/d8RTtJIA92GzsgdK2rpT1MBKKVffjRFGwN7nQVOzi4T XrB5p+6ML7Bd84xOEGsj/vdaXmz1esuH7BOZAGEZfLRCHJ0GVCSssg== Message-ID: <2d0aadde-be32-2cfb-fa77-9ba8cccb7746@ozlabs.ru> Date: Wed, 15 Jul 2020 10:40:44 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200710052340.737567-7-oohall@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 10/07/2020 15:23, Oliver O'Halloran wrote: > SR-IOV support on PowerNV is a byzantine maze of hooks. I have no idea > how anyone is supposed to know how it works except through a lot of > stuffering. Write up some docs about the overall story to help out > the next sucker^Wperson who needs to tinker with it. Sounds about right :) Reviewed-by: Alexey Kardashevskiy > > Signed-off-by: Oliver O'Halloran > --- > arch/powerpc/platforms/powernv/pci-sriov.c | 130 +++++++++++++++++++++ > 1 file changed, 130 insertions(+) > > diff --git a/arch/powerpc/platforms/powernv/pci-sriov.c b/arch/powerpc/platforms/powernv/pci-sriov.c > index 080ea39f5a83..f4c74ab1284d 100644 > --- a/arch/powerpc/platforms/powernv/pci-sriov.c > +++ b/arch/powerpc/platforms/powernv/pci-sriov.c > @@ -12,6 +12,136 @@ > /* for pci_dev_is_added() */ > #include "../../../../drivers/pci/pci.h" > > +/* > + * The majority of the complexity in supporting SR-IOV on PowerNV comes from > + * the need to put the MMIO space for each VF into a separate PE. Internally > + * the PHB maps MMIO addresses to a specific PE using the "Memory BAR Table". > + * The MBT historically only applied to the 64bit MMIO window of the PHB > + * so it's common to see it referred to as the "M64BT". > + * > + * An MBT entry stores the mapped range as an , pair. This forces > + * the address range that we want to map to be power-of-two sized and aligned. > + * For conventional PCI devices this isn't really an issue since PCI device BARs > + * have the same requirement. > + * > + * For a SR-IOV BAR things are a little more awkward since size and alignment > + * are not coupled. The alignment is set based on the the per-VF BAR size, but > + * the total BAR area is: number-of-vfs * per-vf-size. The number of VFs > + * isn't necessarily a power of two, so neither is the total size. To fix that > + * we need to finesse (read: hack) the Linux BAR allocator so that it will > + * allocate the SR-IOV BARs in a way that lets us map them using the MBT. > + * > + * The changes to size and alignment that we need to do depend on the "mode" > + * of MBT entry that we use. We only support SR-IOV on PHB3 (IODA2) and above, > + * so as a baseline we can assume that we have the following BAR modes > + * available: > + * > + * NB: $PE_COUNT is the number of PEs that the PHB supports. > + * > + * a) A segmented BAR that splits the mapped range into $PE_COUNT equally sized > + * segments. The n'th segment is mapped to the n'th PE. > + * b) An un-segmented BAR that maps the whole address range to a specific PE. > + * > + * > + * We prefer to use mode a) since it only requires one MBT entry per SR-IOV BAR > + * For comparison b) requires one entry per-VF per-BAR, or: > + * (num-vfs * num-sriov-bars) in total. To use a) we need the size of each segment > + * to equal the size of the per-VF BAR area. So: > + * > + * new_size = per-vf-size * number-of-PEs > + * > + * The alignment for the SR-IOV BAR also needs to be changed from per-vf-size > + * to "new_size", calculated above. Implementing this is a convoluted process > + * which requires several hooks in the PCI core: > + * > + * 1. In pcibios_add_device() we call pnv_pci_ioda_fixup_iov(). > + * > + * At this point the device has been probed and the device's BARs are sized, > + * but no resource allocations have been done. The SR-IOV BARs are sized > + * based on the maximum number of VFs supported by the device and we need > + * to increase that to new_size. > + * > + * 2. Later, when Linux actually assigns resources it tries to make the resource > + * allocations for each PCI bus as compact as possible. As a part of that it > + * sorts the BARs on a bus by their required alignment, which is calculated > + * using pci_resource_alignment(). > + * > + * For IOV resources this goes: > + * pci_resource_alignment() > + * pci_sriov_resource_alignment() > + * pcibios_sriov_resource_alignment() > + * pnv_pci_iov_resource_alignment() > + * > + * Our hook overrides the default alignment, equal to the per-vf-size, with > + * new_size computed above. > + * > + * 3. When userspace enables VFs for a device: > + * > + * sriov_enable() > + * pcibios_sriov_enable() > + * pnv_pcibios_sriov_enable() > + * > + * This is where we actually allocate PE numbers for each VF and setup the > + * MBT mapping for each SR-IOV BAR. In steps 1) and 2) we setup an "arena" > + * where each MBT segment is equal in size to the VF BAR so we can shift > + * around the actual SR-IOV BAR location within this arena. We need this > + * ability because the PE space is shared by all devices on the same PHB. > + * When using mode a) described above segment 0 in maps to PE#0 which might > + * be already being used by another device on the PHB. > + * > + * As a result we need allocate a contigious range of PE numbers, then shift > + * the address programmed into the SR-IOV BAR of the PF so that the address > + * of VF0 matches up with the segment corresponding to the first allocated > + * PE number. This is handled in pnv_pci_vf_resource_shift(). > + * > + * Once all that is done we return to the PCI core which then enables VFs, > + * scans them and creates pci_devs for each. The init process for a VF is > + * largely the same as a normal device, but the VF is inserted into the IODA > + * PE that we allocated for it rather than the PE associated with the bus. > + * > + * 4. When userspace disables VFs we unwind the above in > + * pnv_pcibios_sriov_disable(). Fortunately this is relatively simple since > + * we don't need to validate anything, just tear down the mappings and > + * move SR-IOV resource back to its "proper" location. > + * > + * That's how mode a) works. In theory mode b) (single PE mapping) is less work > + * since we can map each individual VF with a separate BAR. However, there's a > + * few limitations: > + * > + * 1) For IODA2 mode b) has a minimum alignment requirement of 32MB. This makes > + * it only usable for devices with very large per-VF BARs. Such devices are > + * similar to Big Foot. They definitely exist, but I've never seen one. > + * > + * 2) The number of MBT entries that we have is limited. PHB3 and PHB4 only > + * 16 total and some are needed for. Most SR-IOV capable network cards can support > + * more than 16 VFs on each port. > + * > + * We use b) when using a) would use more than 1/4 of the entire 64 bit MMIO > + * window of the PHB. > + * > + * > + * > + * PHB4 (IODA3) added a few new features that would be useful for SR-IOV. It > + * allowed the MBT to map 32bit MMIO space in addition to 64bit which allows > + * us to support SR-IOV BARs in the 32bit MMIO window. This is useful since > + * the Linux BAR allocation will place any BAR marked as non-prefetchable into > + * the non-prefetchable bridge window, which is 32bit only. It also added two > + * new modes: > + * > + * c) A segmented BAR similar to a), but each segment can be individually > + * mapped to any PE. This is matches how the 32bit MMIO window worked on > + * IODA1&2. > + * > + * d) A segmented BAR with 8, 64, or 128 segments. This works similarly to a), > + * but with fewer segments and configurable base PE. > + * > + * i.e. The n'th segment maps to the (n + base)'th PE. > + * > + * The base PE is also required to be a multiple of the window size. > + * > + * Unfortunately, the OPAL API doesn't currently (as of skiboot v6.6) allow us > + * to exploit any of the IODA3 features. > + */ > > static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev) > { > -- Alexey