From nobody Fri Feb 17 23:45:02 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 4PJT263tWWz3rxYF; Fri, 17 Feb 2023 23:45:02 +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 4PJT262zdXz3HSy; Fri, 17 Feb 2023 23:45:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676677502; 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=mwkoI0gm4oSshYt8nrNF3wdiTT/W0Ha8cqQiu3D4AIY=; b=PLyXzWoFzWuKdP+6Mi1gg7ESZQ7kYs25Cwn/e4/+hpw5S+fpZAH8VtciRpChexSH9yIKd9 GouA9N0GjktWBqBqB11y/okZqh5zVlgqfoFhgM+16LfgeRdz3MDrCssjmYz9GVm6LaC9Nw RsSGk77uqGjDchWCCJSAiN0jjYWBeuUCv4DJOhUR9RdhbBWrZ3GKLkpIw+LlznppBp3QKB brS6KqiPbNCX4r8H2+zd32eW1FkOuLY8N6A2pCtMbd+g0pSaYnyMNExs8GbC7KrRkvRI2g oWh8V5/2AEDTIH9LRE3Jldgjngvflqzd1mJMwlLuU1Dx81mQ+maa3VQGikK29g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676677502; 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=mwkoI0gm4oSshYt8nrNF3wdiTT/W0Ha8cqQiu3D4AIY=; b=NnqWhmWnuPfBi7SluMqFwn2vWWOG5SYM+A+r/+O5ASphcstLMidkbtzhOP8zCpFHJbfox7 +yQwfrwpeJwhGOQEWhtmSF2X3z7sbYJ88nr9h9yjP1ABYdi3hRMiXJAFSlJgYPC2LFLWAs E6sGVarucAhrXEeB8IPfPppO0Evc7uoqmxUbTdZevBpWcFyIGyxANMVdnrUeZ1VQb4Ecbd UTfqKTraGqrZ1b3IGTgrFQ4rkFI9HMa+y8/mWLU5SMLcnDh4WTj2IJIg+B0Hellg06EK8x SYRROjXbn5SSL+0C81W6XsWK8slQJgx44yntpPItY1Ydx/ljRKaPpTVbZOsYrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676677502; a=rsa-sha256; cv=none; b=Js7wSVkMnUdMRnURxaBBEdUV5WqIn3R3Hd195u2zaAWN+FrUZ2mfA1nD9sKwNcIRk3PZtO w3j+sYe/yLfZukFixAVJ0ic3zeEGVvgy+2SKtroYL5imTsdKKX9CCSld8k3/SYd3yU+Gzg b2Jb1OP+cHvN2R3+ts89soT/cCWaNcJ7nXf+amH0/jIg0m2mEy9DmwZTw5FFzUy5c6uyDX 5jYd8GSdINM1D0YW39u6mrldjZwPlPyDObMKqWcZKDnFxS3bk0xIZeVJ161c2aGLQixw0V gzm2lkEy9RbRNTFAiJeWTs0OLeBdDFVGCYrA5J4EMXKobGdRLOGIvXH2o9euRA== 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 4PJT2624XJz11jM; Fri, 17 Feb 2023 23:45:02 +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 31HNj2ma025337; Fri, 17 Feb 2023 23:45:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31HNj2bv025336; Fri, 17 Feb 2023 23:45:02 GMT (envelope-from git) Date: Fri, 17 Feb 2023 23:45:02 GMT Message-Id: <202302172345.31HNj2bv025336@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: 03a85378b81f - stable/13 - LinuxKPI: PCI: implement support for more than 1 MSI vector 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 03a85378b81fcaffae5f8efdd75e2b8e10094e6a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=03a85378b81fcaffae5f8efdd75e2b8e10094e6a commit 03a85378b81fcaffae5f8efdd75e2b8e10094e6a Author: Bjoern A. Zeeb AuthorDate: 2023-01-27 15:34:42 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-02-17 23:42:16 +0000 LinuxKPI: PCI: implement support for more than 1 MSI vector Following e9715b1c4474333ff119aba3a9a74bff91f72372 and 4b56afaf7bf4fa37bae5b26fd93ee1ff5969c1bb, implement support for up-to 32 MSI vectors. This is used by wireless drivers. This also switches msi_desc to an array in order to store per-vector information. Sponsored by: The FreeBSD Foundation Discussed with: grehan (in Dec) MFC after: 3 days Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D38222 (cherry picked from commit b15491b4773af99ce2470144ef6bcd9146cc9a98) --- sys/compat/linuxkpi/common/include/linux/pci.h | 36 +++++++++++++++++++------- sys/compat/linuxkpi/common/src/linux_pci.c | 32 ++++++++++++++++++----- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 6a7dd1eaaa83..5fdfc3a46d8b 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -354,7 +354,7 @@ struct pci_dev { bool want_iomap_res; bool msix_enabled; uint8_t msi_cap; - struct msi_desc *msi_desc; + struct msi_desc **msi_desc; }; /* XXX add kassert here on the mmio offset */ @@ -906,28 +906,44 @@ pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, linux_pci_enable_msi(pdev) static inline int -pci_enable_msi(struct pci_dev *pdev) +_lkpi_pci_enable_msi_range(struct pci_dev *pdev, int minvec, int maxvec) { struct resource_list_entry *rle; int error; - int avail; + int nvec; - avail = pci_msi_count(pdev->dev.bsddev); - if (avail < 1) - return -EINVAL; + if (maxvec < minvec) + return (-EINVAL); + + nvec = pci_msi_count(pdev->dev.bsddev); + if (nvec < 1 || nvec < minvec) + return (-ENOSPC); - avail = 1; /* this function only enable one MSI IRQ */ - if ((error = -pci_alloc_msi(pdev->dev.bsddev, &avail)) != 0) + nvec = min(nvec, maxvec); + if ((error = -pci_alloc_msi(pdev->dev.bsddev, &nvec)) != 0) return error; + /* Native PCI might only ever ask for 32 vectors. */ + if (nvec < minvec) { + pci_release_msi(pdev->dev.bsddev); + return (-ENOSPC); + } + rle = linux_pci_get_rle(pdev, SYS_RES_IRQ, 1, false); pdev->dev.irq_start = rle->start; - pdev->dev.irq_end = rle->start + avail; + pdev->dev.irq_end = rle->start + nvec; pdev->irq = rle->start; pdev->msi_enabled = true; return (0); } +static inline int +pci_enable_msi(struct pci_dev *pdev) +{ + + return (_lkpi_pci_enable_msi_range(pdev, 1, 1)); +} + static inline int pci_channel_offline(struct pci_dev *pdev) { @@ -1628,7 +1644,7 @@ err: /* * We cannot simply re-define pci_get_device() as we would normally do * and then hide it in linux_pci.c as too many semi-native drivers still - * inlucde linux/pci.h and run into the conflict with native PCI. Linux drivers + * include linux/pci.h and run into the conflict with native PCI. Linux drivers * using pci_get_device() need to be changed to call linuxkpi_pci_get_device(). */ static inline struct pci_dev * diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index ba40ded9cddf..5f3a24210c03 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -322,6 +322,11 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) pdev->dev.parent = &linux_root_device; pdev->dev.release = lkpi_pci_dev_release; INIT_LIST_HEAD(&pdev->dev.irqents); + + if (pci_msi_count(dev) > 0) + pdev->msi_desc = malloc(pci_msi_count(dev) * + sizeof(*pdev->msi_desc), M_DEVBUF, M_WAITOK | M_ZERO); + kobject_init(&pdev->dev.kobj, &linux_dev_ktype); kobject_set_name(&pdev->dev.kobj, device_get_nameunit(dev)); kobject_add(&pdev->dev.kobj, &linux_root_device.kobj, @@ -334,6 +339,7 @@ static void lkpinew_pci_dev_release(struct device *dev) { struct pci_dev *pdev; + int i; pdev = to_pci_dev(dev); if (pdev->root != NULL) @@ -341,8 +347,11 @@ 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) + if (pdev->msi_desc != NULL) { + for (i = pci_msi_count(pdev->dev.bsddev) - 1; i >= 0; i--) + free(pdev->msi_desc[i], M_DEVBUF); free(pdev->msi_desc, M_DEVBUF); + } free(pdev, M_DEVBUF); } @@ -949,10 +958,7 @@ out: if (flags & PCI_IRQ_MSI) { if (pci_msi_count(pdev->dev.bsddev) < minv) return (-ENOSPC); - /* We only support 1 vector in pci_enable_msi() */ - if (minv != 1) - return (-ENOSPC); - error = pci_enable_msi(pdev); + error = _lkpi_pci_enable_msi_range(pdev, minv, maxv); if (error == 0 && pdev->msi_enabled) return (pdev->dev.irq_end - pdev->dev.irq_start); } @@ -982,14 +988,24 @@ lkpi_pci_msi_desc_alloc(int irq) struct msi_desc *desc; struct pci_devinfo *dinfo; struct pcicfg_msi *msi; + int vec; 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); + + if (pdev->msi_desc == NULL) + return (NULL); + + if (irq < pdev->dev.irq_start || irq >= pdev->dev.irq_end) + return (NULL); + + vec = pdev->dev.irq_start - irq; + + if (pdev->msi_desc[vec] != NULL) + return (pdev->msi_desc[vec]); dinfo = device_get_ivars(dev->bsddev); msi = &dinfo->cfg.msi; @@ -1000,6 +1016,8 @@ lkpi_pci_msi_desc_alloc(int irq) (msi->msi_ctrl & PCIM_MSICTRL_64BIT) ? true : false; desc->msg.data = msi->msi_data; + pdev->msi_desc[vec] = desc; + return (desc); }