// SPDX-License-Identifier: GPL-2.0/* * PCI Express I/O Virtualization (IOV) support * Single Root IOV 1.0 * Address Translation Service 1.0 * * Copyright (C) 2009 Intel Corporation, Yu Zhao <yu.zhao@intel.com> */#include<linux/bitfield.h>#include<linux/bits.h>#include<linux/log2.h>#include<linux/pci.h>#include<linux/sizes.h>#include<linux/slab.h>#include<linux/export.h>#include<linux/string.h>#include<linux/delay.h>#include<asm/div64.h>#include"pci.h"#define VIRTFN_ID_LEN 17 /* "virtfn%u\0" for 2^32 - 1 */intpci_iov_virtfn_bus(structpci_dev*dev,intvf_id){if(!dev->is_physfn)return-EINVAL;returndev->bus->number+((dev->devfn+dev->sriov->offset+dev->sriov->stride*vf_id)>>8);}intpci_iov_virtfn_devfn(structpci_dev*dev,intvf_id){if(!dev->is_physfn)return-EINVAL;return(dev->devfn+dev->sriov->offset+dev->sriov->stride*vf_id)&0xff;}EXPORT_SYMBOL_GPL(pci_iov_virtfn_devfn);intpci_iov_vf_id(structpci_dev*dev){structpci_dev*pf;if(!dev->is_virtfn)return-EINVAL;pf=pci_physfn(dev);return(pci_dev_id(dev)-(pci_dev_id(pf)+pf->sriov->offset))/pf->sriov->stride;}EXPORT_SYMBOL_GPL(pci_iov_vf_id);/** * pci_iov_get_pf_drvdata - Return the drvdata of a PF * @dev: VF pci_dev * @pf_driver: Device driver required to own the PF * * This must be called from a context that ensures that a VF driver is attached. * The value returned is invalid once the VF driver completes its remove() * callback. * * Locking is achieved by the driver core. A VF driver cannot be probed until * pci_enable_sriov() is called and pci_disable_sriov() does not return until * all VF drivers have completed their remove().