From owner-svn-src-all@freebsd.org Fri May 1 09:50:37 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 196C92D05D1; Fri, 1 May 2020 09:50:37 +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 49D6v06yzgz4JXK; Fri, 1 May 2020 09:50:36 +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 EA8616565; Fri, 1 May 2020 09:50:36 +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 0419oapN061267; Fri, 1 May 2020 09:50:36 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0419oaNk061265; Fri, 1 May 2020 09:50:36 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202005010950.0419oaNk061265@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Fri, 1 May 2020 09:50:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360526 - in stable/12/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/12/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 360526 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: Fri, 01 May 2020 09:50:37 -0000 Author: hselasky Date: Fri May 1 09:50:36 2020 New Revision: 360526 URL: https://svnweb.freebsd.org/changeset/base/360526 Log: MFC r360196: 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 Sponsored by: Mellanox Technologies Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h stable/12/sys/compat/linuxkpi/common/src/linux_pci.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Fri May 1 09:46:27 2020 (r360525) +++ stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Fri May 1 09:50:36 2020 (r360526) @@ -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: stable/12/sys/compat/linuxkpi/common/src/linux_pci.c ============================================================================== --- stable/12/sys/compat/linuxkpi/common/src/linux_pci.c Fri May 1 09:46:27 2020 (r360525) +++ stable/12/sys/compat/linuxkpi/common/src/linux_pci.c Fri May 1 09:50:36 2020 (r360526) @@ -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);