From patchwork Wed Feb 8 18:43:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ganapatrao Kulkarni X-Patchwork-Id: 54575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3625171wrn; Wed, 8 Feb 2023 10:50:18 -0800 (PST) X-Google-Smtp-Source: AK7set93HNtGOeW14olicvhuS7M74G+X6JkywhwfP3tbcfcfEnZ7FJ8dKYTKRikjI+UiT+AetOeP X-Received: by 2002:a05:6a20:7f8e:b0:be:9972:1605 with SMTP id d14-20020a056a207f8e00b000be99721605mr7518811pzj.1.1675882218383; Wed, 08 Feb 2023 10:50:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1675882218; cv=pass; d=google.com; s=arc-20160816; b=E9U6y7fvKeH1zhlxvAJZ88D+M6goQ8zhn3t7rMF6prjmImX5eU8+7A7Q50j10TE07Y Qu0L5ERj8v0vVGeukdYDSVTaz8oCHrE+4LPc2flwHb0Wat9leGYdcyud7EaWyy4R3GAE eGKVkQgOTWGeLkugE5FZA9O5euEOu15vrAjLeUgqS8424a89PhALQFIAiH7F6mETLvxa 6PberRH1STPwtc1yAJbb+pfxv/2rVtssB5BG4XqEIwIOM76qj9Y2eGpWytoKYyScBe+P 3suhe2a1AoAwvTFym9D1yUOnBsacVnObo0SLBvQH0M+sbAqeJWwlciThBOP+RKJsP2OE Bh8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=vT5RSrfEBo8fvZhhD/2llSTYg25RKSa8MSg6NPu/Rep4VSVnFlsEe1ap35zAyGw+/+ h9f1wKsZQwlktfOXPodJo3ONYxm40YGqmiyQbmen2KS1JFSbRU0p+tEFc1mG8mzoLkNm 6AH2BALxusX+ESm9Oofs7h1NjHicskhlIYJjGiNmESuNnHGSYYnkwhF2UxYH/v4kQYRI +HxEfH027MKxkBd+DWaXxy3uNjGDn2b18zwNOMzckGb/9xxaCajnRa4CJD+WQDM/FyN1 h8AaOB8/a/HGhsWN8VoIC9AKUm2OHFaO8HWpTFZnwM5hpPV22U0Z9zSBp/mRqAGuSmKS bM5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=ptaOipxr; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a17090a190d00b0022929341650si2910793pjg.15.2023.02.08.10.50.03; Wed, 08 Feb 2023 10:50:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=ptaOipxr; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjBHSnw (ORCPT + 99 others); Wed, 8 Feb 2023 13:43:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBHSnv (ORCPT ); Wed, 8 Feb 2023 13:43:51 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2094.outbound.protection.outlook.com [40.107.237.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CC944B6; Wed, 8 Feb 2023 10:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DiqXVm8GoUOxJK8yz6Cm3CrGmOfbmcHmc2bSH3PihfVF2HllkLSRrcMvnsqg3KTNjSXT86BmcJb0iWYi8bVWp/eYyG2+MHPrEGDk3tyL/69ufPIfGX9zKkHMRC2oyqiamn7r7SwLAX4tVdRzuibXrM/NhBwWplla0xKRAAJtNsBPpcRh2kd6kANDCCn90yJ4VqdF8McCQxhhGmwzlH74yiCf0eVC0S/wHdOd4ySLugKkGERzUrrdbDqhSST9uMKYHTIidMXg2oflKcH6wb+Eg0PLn3Jgoe/d5kvoIPuKufMJhTiQXj9Q5sQIKY6ceKd3PkXDboPlI48AmdebrhdLPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=EsupisavtW831g2i/PtjV7dY98k5JlWr9opwrdEsV0aZLJJmPh7ZXCBihKd8l1ttJQMQlByiVgzP2qBVza46g6trWVN6eVyFOKT8cXsVMzhniAzvKMjTIsNw5RboarYuziExFaIAs8M5t96oqujJjtx0E/pwk+bRQbJagx2h0MYgaCC2+TFikDBbhfS63dLzRjiqs3IfnLj+g/X7EtI8vM1YoD4jTWG+4Oh82GUAS7LNpy0DuOZa1iM7Qf+fxz0Lv/aq2cmyomiEEOX8gr1cFtD4BNUrs1mXqAbsRpxz5tVD28tTa5Agh2cthX35HIi72cFzDV17pnuN5qnJMexdZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PduJKKTXFIsfNhRg08c2oah3aHxiHm73GdqFmMecpjY=; b=ptaOipxrZaMw9TXTiG7+7wEMWUw5cvCrszmpAVXQG9D6wdYVma6TOOhfZY5yvTZ1qLolLqCuU4vlfajrPQNLrmRIHcgRYA3jvLEWvOQ8ZtWxUV0nhl7f+Q2lRlZwFCxrsiDMz4Wn4LAQ2EkfGbHasSdUJY1otOg60nM13rlWUPY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) by BYAPR01MB5176.prod.exchangelabs.com (2603:10b6:a03:76::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Wed, 8 Feb 2023 18:43:41 +0000 Received: from DM8PR01MB6824.prod.exchangelabs.com ([fe80::6b5b:1242:818c:e70d]) by DM8PR01MB6824.prod.exchangelabs.com ([fe80::6b5b:1242:818c:e70d%3]) with mapi id 15.20.6086.017; Wed, 8 Feb 2023 18:43:40 +0000 From: Ganapatrao Kulkarni To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com Cc: jean-philippe@linaro.org, darren@os.amperecomputing.com, scott@os.amperecomputing.com, gankulkarni@os.amperecomputing.com Subject: [PATCH] PCI/ATS: Allow to enable ATS on VFs even if it is not enabled on PF Date: Wed, 8 Feb 2023 10:43:21 -0800 Message-Id: <20230208184321.867666-1-gankulkarni@os.amperecomputing.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: SN4PR0501CA0036.namprd05.prod.outlook.com (2603:10b6:803:40::49) To DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM8PR01MB6824:EE_|BYAPR01MB5176:EE_ X-MS-Office365-Filtering-Correlation-Id: ef94d597-c804-4cae-101d-08db0a0465a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J+hTav5A1mx27QRXvAteRdZ/zFI5HQIG32Kn7VtbL9tWa7NXb+cH8fQ+BPNkJ2d8hYYiMz8no3CisrMhBZX+AT1pGywN8Z5MvnvJMWyU5OPFtLGu8Vxzu4p6Ws2MvFjJQrFcWoOxVXbO+K0bZqzcMdg0m/h4YrooGalBDEyVkZ24HhpRj4tXvN5dG5Pwwp70tDZkVAUvrliWZDW2vwnkY5BbCYQZhBXx94Ab1BOf0u12LIPJmHMlgk0z1cuWZPjh3c0fvGRvDjKy4lbCLZpCUw6r145nEk4NANJuR1Ujk6hGvc9At7HT1UQvMCjt0JHVL1gljwI7tOgRB8+UuGswioFsiSoVfb75h3DRaWiN6Gcu2D/rdDtkx1itg+9MvtBu3/imzH+ZbCEOIZzCEdFeeJye44IYwuasdbZQhsxXSJZBXYAysDFuBRJxPUusI5oW3yocnYE6tINiQq5GNkwsv7uwBEaOZgF9djxR35NwUYTS5BlDlaTJ4X9kmycSxrEAWUoF0+a+++XrF69Do2c/Od8TRoTdQ9uMXh9pWtPidHUQeCp8L5jrsDe1TWPEdBs42Usuw47ooUIk6rbGCyE65W/y4zK3EXAAMZSYtpgZCd5hQMywTKC+DgX0nyIo3XCtE0MerG173FJXH0gAMjc8Iu6/8SaIUQMKeChMCnndblybpS7DvnSU6gGpRYFQ6tmA1cQEK3LdM/bBWM6oloOqow== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR01MB6824.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(396003)(366004)(39850400004)(346002)(376002)(451199018)(8936002)(4326008)(38100700002)(478600001)(38350700002)(6486002)(6512007)(2616005)(186003)(26005)(52116002)(6666004)(107886003)(6506007)(1076003)(41300700001)(5660300002)(316002)(8676002)(86362001)(66946007)(66556008)(66476007)(83380400001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D+5FJUp9Gva8CD3G0rJ/rtJBvd/Gvim6t2RZjMZtsrvO8uh95uiTumllv6Z3CPxHhTWp7u1d4fleLvBqcPT/rCzAiaorEZ7cItc81f1IPEQd/xytb1TcTjGK4sYCV2DWTU9rTj9Y/ddv3D/heWqoXuJU39QqwmL3fFpCTYNM1IPkoemzmWabHtMyd2ADW4s7sMpGFWUThpHMwSxlq9SU8oKzifH7l1aJjrbl321wnawZVQsyKCBRuEHq5tLdZCn52SWBirBhbeFgLd+pZRk+IyrSAyw8iOSJh6/f0dThKtGZBXK1azkdOe/bhOGZaO+PKXQX787qliqMEFOq4ntRdbbNKlQal8K2GWI0/qjZx0MzTi2hyhmkxJgLU/GHRb5gNohmqQMphqNK426Mwf5tQQAwT97otQnS+FMYC78PzCMoeuDEhJzgLAdFOuZp004sxS3EjMjMNDMwhHxsKZit3MTrGfSHbHtplDQafwqWsNVfHsZvVGSlQr4i13OC79e4/9fqrgzk1+utD/2hiLzOf8x0tbhpLsVvXGDrqGfbP9f+im1Nbq2wRY7ztxGHuunf9qWZd3g2UL/TNkJxnOjHBtq0c8HXWr1/xfBtB/ziiXIdzhx4PPU0iBMWGOmvchtbWO+xJY+JWUsGFWsJZvDrZW00lCGIce4+EpM+kT7/wjJpt0FUQ48YbgPGqdUBR7+RRxXn14ACTxTL856aqek2hpEBG4rGywlkD4JGdQ7hO2OIzkukoORluRhktUTyRJfv+oxJuBPk6hkrs3caqyMsomAgrP78sH0jgjXOZCPfWvII74fKmgtB9eJoak2RHhJeidB6kcuey0Tokc4WF+PmIc8omxu99PID6JEwj+edqFRtq1ZDLgQ1qH65Bj+lXbV+BGgR8iRw4JVNU1JcnW9RGLGU339X7zFjSMBANCNAl5Q8NXpqbsWO3Qraf2Tdz6Vo/7v+K5esU1bqsgJsjVXfmyY1fJaYiv1kOicuFhYNHOQnyZ9S17RAQLgkDJxqrtyqJA6DDOY/iAZ28jKh3S8f8rCX2ip2UTTIlPYD+Xogp3+Pp8FEdYJmIJbB7mXA1SeHs/rri75L3PeJKZHK4mMq23brDHQK5ypTTSv+Jkh9UJPy5dkhBI3b28BBztYf79Ai9OXBZy1X2Pfa9RehLAOdF/tyyrVZlXUSISaASO6RuZ4e8SGn9EjIadG2rvKJYjiB1WyyPoFvOj14H5bmllWdktysaVG459PFxsDk/jSQjEAWqhDPeFZk5IILpATwGQIpqfvEsfJopU953OeFE4Mtucn+agl22em8DGCgOdKs9/OzsLPlEyrS7xXTCvYlDNMsqQuK4zUdOo+XMOnjRNqSQCCxfQaR/K9FN13MDtCjJtbz7Sm9efanIFNyRFQQz5sobyWZGG4H6rCVuctXDtsTMrQpsNLSX2kVF5yTrpbR2v+6NR799MkFCQNnTCL6pABn+lW7PCIPR1TZehGT9R3i/ElhQ7oBHEhLxr7ajLWS8EkL3MzCpcakn8qyboBI2KPsG05w52Dkk7/T9yffRQwgpUMABVq9tQOgMttQ80M5WsDqiMM4oYkpU7cmAWSsjriK3nUMxcEd3kAU5Wsw7ZDxUhKBeL+sun3sFjUKHcGk1qk= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef94d597-c804-4cae-101d-08db0a0465a2 X-MS-Exchange-CrossTenant-AuthSource: DM8PR01MB6824.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2023 18:43:40.7462 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fznqysSwWkWUguFZ9vEb3wCu43X2us7bw/pTyTuAIcGvkYnNYN0ol5qzKtNXibBu7NPZbdvXo2oVfnqIhKB2q8LQL4yJRjTOP+EkO07KHNuHzFbeepVWC1QOdmzk3sU8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR01MB5176 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757289872988780130?= X-GMAIL-MSGID: =?utf-8?q?1757289872988780130?= As per PCIe specification(section 10.5), If a VF implements an ATS capability, its associated PF must implement an ATS capability. The ATS Capabilities in VFs and their associated PFs are permitted to be enabled independently. Also, it states that the Smallest Translation Unit (STU) for VFs must be hardwired to Zero and the associated PF's value applies to VFs STU. The current code allows to enable ATS on VFs only if it is already enabled on associated PF, which is not necessary as per the specification. It is only required to have valid STU programmed on PF to enable ATS on VFs. Adding code to write the first VFs STU to a PF's STU when PFs ATS is not enabled. Signed-off-by: Ganapatrao Kulkarni --- drivers/pci/ats.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index f9cc2e10b676..a97ec67201d1 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -67,13 +67,20 @@ int pci_enable_ats(struct pci_dev *dev, int ps) if (ps < PCI_ATS_MIN_STU) return -EINVAL; - /* - * Note that enabling ATS on a VF fails unless it's already enabled - * with the same STU on the PF. - */ ctrl = PCI_ATS_CTRL_ENABLE; if (dev->is_virtfn) { pdev = pci_physfn(dev); + + if (!pdev->ats_enabled && + (pdev->ats_stu < PCI_ATS_MIN_STU)) { + u16 ctrl2; + + /* Associated PF's STU value applies to VFs. */ + pdev->ats_stu = ps; + ctrl2 = PCI_ATS_CTRL_STU(pdev->ats_stu - PCI_ATS_MIN_STU); + pci_write_config_word(pdev, pdev->ats_cap + PCI_ATS_CTRL, ctrl2); + } + if (pdev->ats_stu != ps) return -EINVAL; } else {