From nobody Thu Feb 23 19:34:38 2023 X-Original-To: dev-commits-src-branches@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 4PN3BR1p37z3sfQh; Thu, 23 Feb 2023 19:34:39 +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 4PN3BQ5s6kz45T5; Thu, 23 Feb 2023 19:34:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677180878; 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=YzzF/jyAlz25ZqeN29AHYQS818Pr4Va0UGyXP4Hz3oo=; b=CSpFylkUdi6IEOX1XqBmnNglFwG5p6rchwQ8ZIaQS4xd9CTy0y85rX5+GGMzgL9CmULI4v V+7cC9RbACnk3/+oEVFxKlxderyLX53kJpITdHGf8XykbEDOVVPnl1Rc1ECMlMvrWiBVrU qgFb4FLfIb/9uqFh3WQhDkqPyu8iMqPIoDBoxNgftViB/BlsxyPCHk9sclLjcaHF7o/aWy YHSsGyBhlNPZ39XaykrF5oruC5G67AMexwGSUJQuTO0XU1ewqSDxzxOrOdd4RKkeZvxPJq VOtQrBtufVA+JSSiEubpIMlFBn9DaG2hgtDlbyzmfyhR0bxBzG6Z+1NNE2CSbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677180878; 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=YzzF/jyAlz25ZqeN29AHYQS818Pr4Va0UGyXP4Hz3oo=; b=j2Rit4SvnHIvwVyWXX8Poi5RH73VjIodMHc+G4M/xLrDO0eRJkby+mf7eJjRdo9N1aZONN BSpy1BFlH7o8ol0f5o2qe3R9LS7lQJ8Ol73ZHpn/gwKgiIPOswoEhzcG6XkWJXOSGe/wP7 xLb3YOLW6QGs+gwy7ewG6zfv4RyZGzXZNcLAN17avRT9QVTB2UWq/jahCBYUiUgEgZNrd1 y5E93ArIGxmBhTlycleNU9e/e40qOSQizMmDzPcrivkAmO1zApZUTEQ97Az8g1ohYz+NqV 9u258LGRQFzXcaJDXzxa0nCHdEbIFvJQHiYPTU9g1bWVOwZnHnGLiHDY37LY7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677180878; a=rsa-sha256; cv=none; b=KZwzSzoy/7NvaKg2EjjDYfaepno5aDcRppwqfLR95+kAjdO9gF6rH0xk0afuN5uZfZcyVC sSnImYt1SwK4miRtnoQIylAa/3fTdIvpMaO7EcFKiMhmpfGaW37SWA10PfQY0TngZK1nlI d5sPN/8FMxSNtUcRxVysF7yk10bFnTs6A3t5LSxSeOthDZ1fzDSflrIAAAq7ZZr2eRNCgP BlkFZUiJkrpDMj//xuydkc3VFY10LtoX5daV1YmDpaksyLpS+qF3Gu1kVEN6eoksH3TD63 THvxaInAZ2zGWe2oy7Lfib/yALubEeco3qNeQ3oT6DUttHfh6PmuqTzwyGsXyw== 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 4PN3BQ4xykzvTM; Thu, 23 Feb 2023 19:34:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31NJYckk020417; Thu, 23 Feb 2023 19:34:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31NJYcJ3020416; Thu, 23 Feb 2023 19:34:38 GMT (envelope-from git) Date: Thu, 23 Feb 2023 19:34:38 GMT Message-Id: <202302231934.31NJYcJ3020416@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 4876c939ce63 - releng/13.2 - LinuxKPI: implement irq_get_msi_desc() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 4876c939ce63c86fe918e469881cc92ec40cfbee Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=4876c939ce63c86fe918e469881cc92ec40cfbee commit 4876c939ce63c86fe918e469881cc92ec40cfbee Author: Bjoern A. Zeeb AuthorDate: 2022-11-28 18:27:03 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-02-23 19:33:09 +0000 LinuxKPI: implement irq_get_msi_desc() Add irq_get_msi_desc() as a wrapper around a PCI function which will allocate a single cached value (see comment on struct) for the msi_desc requested if it doesn't exist yet and handle freeing it when the PCI device goes away. We take the values from the ivars of the native (FreeBSD) device. While changing struct pci_dev also add the msi_cap field requested by a wireless driver. Reviewed by: hselasky (earlier version) Approved by: re (cperciva) Differential Revision: https://reviews.freebsd.org/D37523 (cherry picked from commit 4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb) (cherry picked from commit 7d23664b35a2611dc4fea56f7cfd2b99f91626a0) --- sys/compat/linuxkpi/common/include/linux/pci.h | 14 ++++++++++++ sys/compat/linuxkpi/common/src/linux_pci.c | 31 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 8d41e33b0da8..1475a159e0b5 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -303,6 +303,17 @@ _pci_exit(void) \ module_init(_pci_init); \ module_exit(_pci_exit) +struct msi_msg { + uint32_t data; +}; + +struct msi_desc { + struct msi_msg msg; + struct { + bool is_64; + } msi_attrib; +}; + /* * If we find drivers accessing this from multiple KPIs we may have to * refcount objects of this structure. @@ -338,6 +349,8 @@ struct pci_dev { bool managed; /* devres "pcim_*(). */ bool want_iomap_res; bool msix_enabled; + uint8_t msi_cap; + struct msi_desc *msi_desc; }; /* XXX add kassert here on the mmio offset */ @@ -366,6 +379,7 @@ struct resource *_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size); struct pcim_iomap_devres *lkpi_pcim_iomap_devres_find(struct pci_dev *pdev); void lkpi_pcim_iomap_table_release(struct device *, void *); struct pci_dev *lkpi_pci_get_device(uint16_t, uint16_t, struct pci_dev *); +struct msi_desc *lkpi_pci_msi_desc_alloc(int); static inline bool dev_is_pci(struct device *dev) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 15c5030a33b9..e31ff18b675d 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -341,6 +341,8 @@ lkpinew_pci_dev_release(struct device *dev) if (pdev->bus->self != pdev) pci_dev_put(pdev->bus->self); free(pdev->bus, M_DEVBUF); + if (pdev->msi_desc != NULL) + free(pdev->msi_desc, M_DEVBUF); free(pdev, M_DEVBUF); } @@ -962,6 +964,35 @@ out: return (-EINVAL); } +struct msi_desc * +lkpi_pci_msi_desc_alloc(int irq) +{ + struct device *dev; + struct pci_dev *pdev; + struct msi_desc *desc; + struct pci_devinfo *dinfo; + struct pcicfg_msi *msi; + + dev = linux_pci_find_irq_dev(irq); + if (dev == NULL) + return (NULL); + + pdev = to_pci_dev(dev); + if (pdev->msi_desc != NULL) + return (pdev->msi_desc); + + dinfo = device_get_ivars(dev->bsddev); + msi = &dinfo->cfg.msi; + + desc = malloc(sizeof(*desc), M_DEVBUF, M_WAITOK | M_ZERO); + + desc->msi_attrib.is_64 = + (msi->msi_ctrl & PCIM_MSICTRL_64BIT) ? true : false; + desc->msg.data = msi->msi_data; + + return (desc); +} + CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t)); struct linux_dma_obj {