From nobody Fri Jan 13 00:44:36 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 4NtN3S6Kmpz2sgL4; Fri, 13 Jan 2023 00:44:36 +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 4NtN3S5tzLz3R55; Fri, 13 Jan 2023 00:44:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673570676; 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=ttFdpcHEniThhAn1UFCgj0iBuiOHxTbEfceB+ryRorU=; b=nIO2REIpo0hSOciR83d8mkrvHPlw2Ivh9IIdkCEsC3eD6KIdY0ZOeoN4Z+cU60vjV3AzWQ hlzKNwXxnrpWFmJzVDmpYzos8/XEjVQ/zRQ+Lk4nPza4LJ96Fb5jlTs6rIGbUxiyfR+daU R+lOe0YxbqLcNjH0EnW7uBH0hqQj9nibo8RVOyVTYolGYr/65plPIVxDXPxfn+nGhtseqd 5wjUjj0Xp9AcLEv0TP8eDGllEGr65rtmTtrfu+qz608gd5NM0O5BmqfQXefN/6cAF/qYUj ABPdLkhWyzcscM3LiX8mhoVwB/nFe1uQVAmTuZqtT0x4vawzo0y1e012Pv2VMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673570676; 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=ttFdpcHEniThhAn1UFCgj0iBuiOHxTbEfceB+ryRorU=; b=gr/PQs2XwzBvLk5wMdAYHgF6dwWZGM04IVFw21rqUNGZaZQG1fuBswxAsVOiRxobvYBXXa 1DnHy31PnoZG3o7kC2bwyAqHNh7JqLunFo9hfPNNFangCzzVRqT8YXvjHxRKKyJTnLiJwM 6jyyqa5SlNOcy2iDEh+mxRFp8dGfz42QGXk/6Q1nmeoGJiM0wlTMAadk5rNoaf/BZbQ6w8 wVODbxbXmzFx2rCShPAHT7uXfoSMoTDVOLkzcF/F3HOXgk1HE+GRMds716bATVkNvLl22G 8T6g+a2EpmpvsmxDntKU8nZGyTVu/mBejLZ4g2ptG698MATiZsTlZi/KzCKHcA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673570676; a=rsa-sha256; cv=none; b=UW6AyswPGT5m53HA2U6yCimUCt6DCTf7zTOo2fwOwGpVFSA27GBDy3cklgEUNnrPNAaCgP U0hL8g2Wh+egSCQ+9u1LciQLue9wDSaeWyLF0VNcUa80kGua2vciDXdW472FvVJNUlaRny 7Mpc+gMrKy22BzXddAQU3/TnSleRtgJ5S+jOgXR6B3S/mrGj9YsW5Nf1FUEP4f7bxm8yOf PoBgZPB25toEbCLYju/snO2op96EfJIvrEzAbREZor4Gcnd7tRIVHiZJhk3ZKNi2QDmjeu Drx/9gJDP/H4yJIrSws1VS4NQmrL26WRAfmkHuVT0jBBzBBc0yAZhBnSGM3puA== 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 4NtN3S4sWtzp21; Fri, 13 Jan 2023 00:44:36 +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 30D0iaEv064927; Fri, 13 Jan 2023 00:44:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30D0ianh064926; Fri, 13 Jan 2023 00:44:36 GMT (envelope-from git) Date: Fri, 13 Jan 2023 00:44:36 GMT Message-Id: <202301130044.30D0ianh064926@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 4b56afaf7bf4 - main - LinuxKPI: implement irq_get_msi_desc() 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb commit 4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb Author: Bjoern A. Zeeb AuthorDate: 2022-11-28 18:27:03 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-01-13 00:43:23 +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. Bump __FreeBSD_version so these changes can be detected. MFC after: 3 days X-MFC: move fields to end of struct (alloc happens in linux_pci.c) Reviewed by: hselasky (earlier version) Differential Revision: https://reviews.freebsd.org/D37523 --- UPDATING | 4 +++ .../linuxkpi/common/include/linux/interrupt.h | 7 +++++ sys/compat/linuxkpi/common/include/linux/pci.h | 18 +++++++++++++ sys/compat/linuxkpi/common/src/linux_pci.c | 31 ++++++++++++++++++++++ sys/sys/param.h | 2 +- 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/UPDATING b/UPDATING index 13007feb15c6..a0fdb839f668 100644 --- a/UPDATING +++ b/UPDATING @@ -27,6 +27,10 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 14.x IS SLOW: world, or to merely disable the most expensive debugging functionality at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20230113: + LinuxKPI pci.h changes may require out-of-tree drivers to be recompiled. + Bump _FreeBSD_version to 1400078 to be able to detect this change. + 20221212: llvm-objump is now always installed as objdump. Previously there was no /usr/bin/objdump unless the WITH_LLVM_BINUTILS knob was used. diff --git a/sys/compat/linuxkpi/common/include/linux/interrupt.h b/sys/compat/linuxkpi/common/include/linux/interrupt.h index 4c914a7b45a1..f56140632605 100644 --- a/sys/compat/linuxkpi/common/include/linux/interrupt.h +++ b/sys/compat/linuxkpi/common/include/linux/interrupt.h @@ -131,6 +131,13 @@ irq_set_affinity_hint(int vector, cpumask_t *mask) return (-error); } +static inline struct msi_desc * +irq_get_msi_desc(unsigned int irq) +{ + + return (lkpi_pci_msi_desc_alloc(irq)); +} + /* * LinuxKPI tasklet support */ diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index cc9cb7da0b2a..6651fd62b44b 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -285,6 +285,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. @@ -311,12 +322,18 @@ struct pci_dev { unsigned int devfn; uint32_t class; uint8_t revision; + uint8_t msi_cap; bool managed; /* devres "pcim_*(). */ bool want_iomap_res; bool msi_enabled; bool msix_enabled; phys_addr_t rom; size_t romlen; + /* + * msi_desc should be an array one day? For as long as we only support + * 1 MSI vector this is fine. + */ + struct msi_desc *msi_desc; TAILQ_HEAD(, pci_mmio_region) mmio; }; @@ -345,6 +362,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 57e431a7abcd..da5430eb0d7b 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -339,6 +339,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); } @@ -965,6 +967,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 { diff --git a/sys/sys/param.h b/sys/sys/param.h index f0f35e3a268e..07b3e6de80e6 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -76,7 +76,7 @@ * cannot include sys/param.h and should only be updated here. */ #undef __FreeBSD_version -#define __FreeBSD_version 1400077 +#define __FreeBSD_version 1400078 /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,