From patchwork Wed Jun 12 11:27:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivasharan Srikanteshwara X-Patchwork-Id: 13694854 X-Patchwork-Delegate: bhelgaas@google.com Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75C6416F27B for ; Wed, 12 Jun 2024 11:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718192302; cv=none; b=KnUH4PJ2dKeb8cZSVooBuDOfWNKkVKxeUJ5ktuBcralChz6fCSNDZZP9Q8M0N7l6w92ZuUo7WXzfLyVWdQsxOEpaILDuCOvpScuMXBZWPB9v2kCUTDjbOGbHrGvwMIIVgw4E2ujhKAYXWi5aTkzeI/4oC8vRe5h3A4lJfXBn1c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718192302; c=relaxed/simple; bh=2Kq2+dxCxqy2vBLR6aMK3CS1B+4OMZwLLqdvtyedUPY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type; b=ms5YgtE8b8nlv1Jkpc8iQ3nYMZsFhMzqmOv2sncv+aeGBWT5dSEBKjcX47v0RxfTGiFTLKz4T9iDV6TOc8ZJjKaZ9SFwpGShy86yisJjAH/9Nfs1APNqbSQyTfJiJTZzyNmVYo/jhQqBCKEJiNqFJhHhSbL4oZwwqknwBsZ7TtE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=KaZm++LC; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="KaZm++LC" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2c2edc2611bso502867a91.0 for ; Wed, 12 Jun 2024 04:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1718192300; x=1718797100; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=Why58SAdP5Y6rkV+8qgdzmMz3htYTE6s2TGPcruv6C4=; b=KaZm++LCZO4h8u5u7+fqzbFgUlAQ3rB5I0sFQqC8Hr1MW0al1gBcvGh54hLqwy+JmS YTy5uveZZU9IozUs59GZZNp5kaFDUfkCqxfoIVN10CO54G1ysk1/Isp+DWMyP8qwC/zi ca82+mO5ivlTl5sBl3Xv8RhB3afvkYLn0tgGU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718192300; x=1718797100; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Why58SAdP5Y6rkV+8qgdzmMz3htYTE6s2TGPcruv6C4=; b=YTXsEqlv6xgUuUoMdro/oPahXYCeXfg46zJOyuGL6VXBvgNGVfcAvGEVirbTDfEzq7 SQecuFsp0XU2V5pquXOnXsnyDo5q9gkqps4xYjvre35oqEIBN6Wc1cBh7KmMvaNIbAXh MwVlZRKddl0VMRtnA4tNQ8wSWZCYQv5qLOfHiFiN0wPE8D0BJNZp5Vws8mQO+oytZl2z /VT3wMi2od2i640g4YM7Wt5SJIuu1GdRv++ivgvMpMT3MQs3vO8Sghl/bGdug3mdDFO6 dKuccC+TDHRuPIxgzqz3mm4yLETb689DWcumVp/zFU3a0jHDZViAQBUkHaQGEg+jTlCj PmUg== X-Gm-Message-State: AOJu0YxztNxHAqLg0A5RVBt9OBjq/5qsoyPfNs5vZzqAN2FbtPIwdzMt VfyTpGiFjCjQs/Jf7rfNaAF+WX7VXgI/9/t3vMfnHdbOpEhm88WXSC60ignTa4F6SQPDDtGhT6B 6O+WqWOuadkgMKlGCSTLS2IxvUMo7uSEFMbau5rT6nh4xhD9d3VN84aGV3Sj85fOaFo5qxFHWIq Qb+2HiD4stJUK68CIqftpTuwNMY4rwRleh20ibMKp5UBnphU/B9a3P7X19kw+ZEfE= X-Google-Smtp-Source: AGHT+IEjaVszanpa6z6YEttWLZ90J+Gma8mpQUbnjH8hOYOBjk1f3iQxxx4ijVssFyXOzqK82vDI4A== X-Received: by 2002:a17:903:2285:b0:1f7:12c9:9426 with SMTP id d9443c01a7336-1f83b7e071dmr16950195ad.3.1718192300192; Wed, 12 Jun 2024 04:38:20 -0700 (PDT) Received: from dhcp-135-24-192-142.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6fc06a5d2sm74392305ad.306.2024.06.12.04.38.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2024 04:38:19 -0700 (PDT) From: Shivasharan S To: linux-pci@vger.kernel.org, bhelgaas@google.com Cc: linux-kernel@vger.kernel.org, sumanesh.samanta@broadcom.com, sathya.prakash@broadcom.com, Shivasharan S Subject: [PATCH 2/2] pci/p2pdma: Modify p2p_dma_distance to detect virtual P2P links Date: Wed, 12 Jun 2024 04:27:36 -0700 Message-Id: <1718191656-32714-3-git-send-email-shivasharan.srikanteshwara@broadcom.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1718191656-32714-1-git-send-email-shivasharan.srikanteshwara@broadcom.com> References: <1718191656-32714-1-git-send-email-shivasharan.srikanteshwara@broadcom.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Update the p2p_dma_distance() to determine virtual inter-switch P2P links existing between two switches and use this to calculate the DMA distance between two devices. Signed-off-by: Shivasharan S --- drivers/pci/Kconfig | 1 + drivers/pci/p2pdma.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index d35001589d88..3e6226ec91fd 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -174,6 +174,7 @@ config PCI_P2PDMA depends on 64BIT select GENERIC_ALLOCATOR select NEED_SG_DMA_FLAGS + select PCI_SW_DISCOVERY help Enables drivers to do PCI peer-to-peer transactions to and from BARs that are exposed in other devices that are the part of diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13cb500..780e649b3a1d 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -21,6 +21,8 @@ #include #include +extern bool sw_disc_check_virtual_link(struct pci_dev *a, struct pci_dev *b); + struct pci_p2pdma { struct gen_pool *pool; bool p2pmem_published; @@ -576,7 +578,7 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, int *dist, bool verbose) { enum pci_p2pdma_map_type map_type = PCI_P2PDMA_MAP_THRU_HOST_BRIDGE; - struct pci_dev *a = provider, *b = client, *bb; + struct pci_dev *a = provider, *b = client, *bb, *b_virtual_link = NULL; bool acs_redirects = false; struct pci_p2pdma *p2pdma; struct seq_buf acs_list; @@ -606,6 +608,17 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, if (a == bb) goto check_b_path_acs; + // Physical Broadcom PEX switches can be provisioned into + // multiple virtual switches. + // if both upstream bridges belong to the same physical + // switch, and the switch supports P2P, + // p2p_dma_distance() should take into account of such + // scenarios. + if (sw_disc_check_virtual_link(a, bb)) { + b_virtual_link = bb; + goto check_b_path_acs; + } + bb = pci_upstream_bridge(bb); dist_b++; } @@ -629,6 +642,9 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client, acs_cnt++; } + if (b_virtual_link && bb == b_virtual_link) + break; + bb = pci_upstream_bridge(bb); }