From nobody Sun Dec 24 08:23:22 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SyYvb1PR2z54HYs; Sun, 24 Dec 2023 08:23:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SyYvZ5Tn0z4YH9; Sun, 24 Dec 2023 08:23:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FrwrgeGsdPR15mzzuFnvqsmYLzk7HDFfLEGP0JzV59I=; b=ZOEC2GQTjeIPmnuNLToqojrFmR3FbsQBxdhg4O32J8kM9gJEdpGlaRd0q1YoWA5B5Z8At3 bFUISCbFhPQj0lieeM2fzs6weXxsg4OsYEExACol7j8rJzBSjQtbZ0+DDcMfK+nZwKF2Zh ESbpwgUhqFVqBhfuukfiqT8X3b6ow2CT2MNHBp4n+FD0QrBGiYMYxQgq9+IxKDz5kufvzO 4Jbo87L/cmxUN64GVMOGaBvd5EMWSjDAiLOIndxTeeCx8TLDbLdKvrKYx51XPglWsN+Kig IPN3JfFobvWloY6GtQKfsp43864Gixlv750irHzUzFFagSJhAgGTHSVgzY8eWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703406202; a=rsa-sha256; cv=none; b=dUxlFmSDu0EWYX5mBUz1iYlZcZIvp2OfGdFEPWaxg+ZTIpfXvgCPs2UjYWWnl6qonRbVj1 jkBI5K1ylIhVIeWNpie3Brk25FIr9XV9HjLnt4CLyIxIU5EOvEkervGd5c4CevQhSG7MeD ohwKExvqXW0386PXUTclmEJInbQBOUzW5U1195hbv4TAflJOjPhh3Im6f70RlFiV8NGmNM wFK7HXOYNArdUsuYu3eV24nPG4zXV8nI0zYTdLBszl2QltQImrh7YR5GOdAU7UmGp8McFI Fnoyzvzp7xF8mUU/MpIa+Qp8YiJve/dGsWh/LFyZ1njr9XTpMJm7afLFc/erlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FrwrgeGsdPR15mzzuFnvqsmYLzk7HDFfLEGP0JzV59I=; b=w0yYSHCsGaW266yCY6VPfMBNX+GuEGAsdpNMRgqIxfF5X0pCRJhT3hxzCfTE+adJgNepJe vxhJ/oCmIno5apDUrY4CCg/YxiyfeohaqfFAkgGXIdG3WLjCiVicFFt13bk3t9L9oRdqq3 l39gxuz8LZJ5A5bu/9SQ0UWo1DUJZySHHuUOaxk5gOhRqKGSYfRNbnbeCK8U68MNCHtYMl YLdQCEQtAbeBqPGW6fZtDXZxR07QIMl1f2yTpRBb+IveOW0NNfOuUZU4gKBc+eyEkkyVVM Z3Xc532nUAieinLh/NeQsbdlm/B8Ca0yf1dRqZz7pBAxf+0M2Jzmj/7s1PPOjw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SyYvZ4bNWz5kl; Sun, 24 Dec 2023 08:23:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BO8NM4S087694; Sun, 24 Dec 2023 08:23:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BO8NMs8087691; Sun, 24 Dec 2023 08:23:22 GMT (envelope-from git) Date: Sun, 24 Dec 2023 08:23:22 GMT Message-Id: <202312240823.3BO8NMs8087691@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 808ae4e29b6b - main - LinuxKPI: Add pcie_capability_clear_and_set_word() function List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 808ae4e29b6b9c9acc7eab013c5045370df8182a Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=808ae4e29b6b9c9acc7eab013c5045370df8182a commit 808ae4e29b6b9c9acc7eab013c5045370df8182a Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:20:00 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-12-24 08:20:00 +0000 LinuxKPI: Add pcie_capability_clear_and_set_word() function It does a Read-Modify-Write operation using clear and set bitmasks on PCI Express Capability Register at pos. As certain PCI Express Capability Registers are accessed concurrently in RMW fashion, hence require locking which is handled transparently to the caller. Sponsored by: Serenity CyberSecurity, LLC Reviewed by: manu, bz MFC after: 1 week MFC TODO: Move pcie_cap_lock to bottom to preserve KBI compatibility Differential Revision: https://reviews.freebsd.org/D42821 --- sys/compat/linuxkpi/common/include/linux/pci.h | 36 ++++++++++++++------------ sys/compat/linuxkpi/common/src/linux_pci.c | 3 +++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index aa99b050ffd9..9c7e39bf4a42 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -347,6 +347,7 @@ struct pci_dev { size_t romlen; struct msi_desc **msi_desc; char *path_name; + spinlock_t pcie_cap_lock; TAILQ_HEAD(, pci_mmio_region) mmio; }; @@ -1012,35 +1013,38 @@ pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val) } static inline int -pcie_capability_set_word(struct pci_dev *dev, int pos, uint16_t val) +pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos, + uint16_t clear, uint16_t set) { int error; uint16_t v; + if (pos == PCI_EXP_LNKCTL || pos == PCI_EXP_RTCTL) + spin_lock(&dev->pcie_cap_lock); + error = pcie_capability_read_word(dev, pos, &v); - if (error != 0) - return (error); + if (error == 0) { + v &= ~clear; + v |= set; + error = pcie_capability_write_word(dev, pos, v); + } - v |= val; + if (pos == PCI_EXP_LNKCTL || pos == PCI_EXP_RTCTL) + spin_unlock(&dev->pcie_cap_lock); - error = pcie_capability_write_word(dev, pos, v); return (error); } static inline int -pcie_capability_clear_word(struct pci_dev *dev, int pos, uint16_t val) +pcie_capability_set_word(struct pci_dev *dev, int pos, uint16_t val) { - int error; - uint16_t v; - - error = pcie_capability_read_word(dev, pos, &v); - if (error != 0) - return (error); - - v &= ~val; + return (pcie_capability_clear_and_set_word(dev, pos, 0, val)); +} - error = pcie_capability_write_word(dev, pos, v); - return (error); +static inline int +pcie_capability_clear_word(struct pci_dev *dev, int pos, uint16_t val) +{ + return (pcie_capability_clear_and_set_word(dev, pos, val, 0)); } static inline int pcie_get_minimum_link(struct pci_dev *dev, diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 4cd28fac15d3..825ebe319b1a 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -525,6 +525,7 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, goto out_dma_init; TAILQ_INIT(&pdev->mmio); + spin_lock_init(&pdev->pcie_cap_lock); spin_lock(&pci_lock); list_add(&pdev->links, &pci_devices); @@ -539,6 +540,7 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, out_probe: free(pdev->bus, M_DEVBUF); + spin_lock_destroy(&pdev->pcie_cap_lock); linux_pdev_dma_uninit(pdev); out_dma_init: spin_lock(&pci_lock); @@ -579,6 +581,7 @@ linux_pci_detach_device(struct pci_dev *pdev) spin_lock(&pci_lock); list_del(&pdev->links); spin_unlock(&pci_lock); + spin_lock_destroy(&pdev->pcie_cap_lock); put_device(&pdev->dev); return (0);