From owner-svn-src-all@freebsd.org Wed Apr 22 14:33:26 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DE3312B62A0; Wed, 22 Apr 2020 14:33:26 +0000 (UTC) (envelope-from hselasky@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 496jbV5G87z4KLT; Wed, 22 Apr 2020 14:33:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9583C1C3BC; Wed, 22 Apr 2020 14:33:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03MEXQSC012627; Wed, 22 Apr 2020 14:33:26 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03MEXQ6p012625; Wed, 22 Apr 2020 14:33:26 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202004221433.03MEXQ6p012625@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 22 Apr 2020 14:33:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360196 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 360196 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Apr 2020 14:33:26 -0000 Author: hselasky Date: Wed Apr 22 14:33:25 2020 New Revision: 360196 URL: https://svnweb.freebsd.org/changeset/base/360196 Log: Factor code in LinuxKPI to allow attach and detach using any BSD device. This allows non-LinuxKPI based infiniband device drivers to attach correctly to ibcore. No functional change intended. Reviewed by: np @ Differential Revision: https://reviews.freebsd.org/D24514 MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/pci.h head/sys/compat/linuxkpi/common/src/linux_pci.c Modified: head/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/pci.h Wed Apr 22 13:53:22 2020 (r360195) +++ head/sys/compat/linuxkpi/common/include/linux/pci.h Wed Apr 22 14:33:25 2020 (r360196) @@ -954,4 +954,15 @@ pcie_get_width_cap(struct pci_dev *dev) return (PCIE_LNK_WIDTH_UNKNOWN); } +/* + * The following functions can be used to attach/detach the LinuxKPI's + * PCI device runtime. The pci_driver and pci_device_id pointer is + * allowed to be NULL. Other pointers must be all valid. + * The pci_dev structure should be zero-initialized before passed + * to the linux_pci_attach_device function. + */ +extern int linux_pci_attach_device(device_t, struct pci_driver *, + const struct pci_device_id *, struct pci_dev *); +extern int linux_pci_detach_device(struct pci_dev *); + #endif /* _LINUX_PCI_H_ */ Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 22 13:53:22 2020 (r360195) +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 22 14:33:25 2020 (r360196) @@ -213,22 +213,33 @@ linux_pci_probe(device_t dev) static int linux_pci_attach(device_t dev) { + const struct pci_device_id *id; + struct pci_driver *pdrv; + struct pci_dev *pdev; + + pdrv = linux_pci_find(dev, &id); + pdev = device_get_softc(dev); + + MPASS(pdrv != NULL); + MPASS(pdev != NULL); + + return (linux_pci_attach_device(dev, pdrv, id, pdev)); +} + +int +linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, + const struct pci_device_id *id, struct pci_dev *pdev) +{ struct resource_list_entry *rle; struct pci_bus *pbus; - struct pci_dev *pdev; struct pci_devinfo *dinfo; - struct pci_driver *pdrv; - const struct pci_device_id *id; device_t parent; int error; linux_set_current(curthread); - pdrv = linux_pci_find(dev, &id); - pdev = device_get_softc(dev); - - parent = device_get_parent(dev); - if (pdrv->isdrm) { + if (pdrv != NULL && pdrv->isdrm) { + parent = device_get_parent(dev); dinfo = device_get_ivars(parent); device_set_ivars(dev, dinfo); } else { @@ -270,9 +281,11 @@ linux_pci_attach(device_t dev) list_add(&pdev->links, &pci_devices); spin_unlock(&pci_lock); - error = pdrv->probe(pdev, id); - if (error) - goto out_probe; + if (pdrv != NULL) { + error = pdrv->probe(pdev, id); + if (error) + goto out_probe; + } return (0); out_probe: @@ -291,18 +304,30 @@ linux_pci_detach(device_t dev) { struct pci_dev *pdev; - linux_set_current(curthread); pdev = device_get_softc(dev); - pdev->pdrv->remove(pdev); + MPASS(pdev != NULL); + device_set_desc(dev, NULL); + + return (linux_pci_detach_device(pdev)); +} + +int +linux_pci_detach_device(struct pci_dev *pdev) +{ + + linux_set_current(curthread); + + if (pdev->pdrv != NULL) + pdev->pdrv->remove(pdev); + free(pdev->bus, M_DEVBUF); linux_pdev_dma_uninit(pdev); spin_lock(&pci_lock); list_del(&pdev->links); spin_unlock(&pci_lock); - device_set_desc(dev, NULL); put_device(&pdev->dev); return (0);