Commit e277d2fc authored by Yu Zhao's avatar Yu Zhao Committed by David Woodhouse

PCI: handle Virtual Function ATS enabling

The SR-IOV spec requires that the Smallest Translation Unit and
the Invalidate Queue Depth fields in the Virtual Function ATS
capability are hardwired to 0. If a function is a Virtual Function,
then and set its Physical Function's STU before enabling the ATS.
Signed-off-by: default avatarYu Zhao <yu.zhao@intel.com>
Acked-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 302b4215
...@@ -491,10 +491,10 @@ static int sriov_init(struct pci_dev *dev, int pos) ...@@ -491,10 +491,10 @@ static int sriov_init(struct pci_dev *dev, int pos)
if (pdev) if (pdev)
iov->dev = pci_dev_get(pdev); iov->dev = pci_dev_get(pdev);
else { else
iov->dev = dev; iov->dev = dev;
mutex_init(&iov->lock);
} mutex_init(&iov->lock);
dev->sriov = iov; dev->sriov = iov;
dev->is_physfn = 1; dev->is_physfn = 1;
...@@ -514,11 +514,11 @@ static void sriov_release(struct pci_dev *dev) ...@@ -514,11 +514,11 @@ static void sriov_release(struct pci_dev *dev)
{ {
BUG_ON(dev->sriov->nr_virtfn); BUG_ON(dev->sriov->nr_virtfn);
if (dev == dev->sriov->dev) if (dev != dev->sriov->dev)
mutex_destroy(&dev->sriov->lock);
else
pci_dev_put(dev->sriov->dev); pci_dev_put(dev->sriov->dev);
mutex_destroy(&dev->sriov->lock);
kfree(dev->sriov); kfree(dev->sriov);
dev->sriov = NULL; dev->sriov = NULL;
} }
...@@ -723,19 +723,40 @@ int pci_enable_ats(struct pci_dev *dev, int ps) ...@@ -723,19 +723,40 @@ int pci_enable_ats(struct pci_dev *dev, int ps)
int rc; int rc;
u16 ctrl; u16 ctrl;
BUG_ON(dev->ats); BUG_ON(dev->ats && dev->ats->is_enabled);
if (ps < PCI_ATS_MIN_STU) if (ps < PCI_ATS_MIN_STU)
return -EINVAL; return -EINVAL;
rc = ats_alloc_one(dev, ps); if (dev->is_physfn || dev->is_virtfn) {
if (rc) struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
return rc;
mutex_lock(&pdev->sriov->lock);
if (pdev->ats)
rc = pdev->ats->stu == ps ? 0 : -EINVAL;
else
rc = ats_alloc_one(pdev, ps);
if (!rc)
pdev->ats->ref_cnt++;
mutex_unlock(&pdev->sriov->lock);
if (rc)
return rc;
}
if (!dev->is_physfn) {
rc = ats_alloc_one(dev, ps);
if (rc)
return rc;
}
ctrl = PCI_ATS_CTRL_ENABLE; ctrl = PCI_ATS_CTRL_ENABLE;
ctrl |= PCI_ATS_CTRL_STU(ps - PCI_ATS_MIN_STU); if (!dev->is_virtfn)
ctrl |= PCI_ATS_CTRL_STU(ps - PCI_ATS_MIN_STU);
pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl); pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
dev->ats->is_enabled = 1;
return 0; return 0;
} }
...@@ -747,13 +768,26 @@ void pci_disable_ats(struct pci_dev *dev) ...@@ -747,13 +768,26 @@ void pci_disable_ats(struct pci_dev *dev)
{ {
u16 ctrl; u16 ctrl;
BUG_ON(!dev->ats); BUG_ON(!dev->ats || !dev->ats->is_enabled);
pci_read_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, &ctrl); pci_read_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, &ctrl);
ctrl &= ~PCI_ATS_CTRL_ENABLE; ctrl &= ~PCI_ATS_CTRL_ENABLE;
pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl); pci_write_config_word(dev, dev->ats->pos + PCI_ATS_CTRL, ctrl);
ats_free_one(dev); dev->ats->is_enabled = 0;
if (dev->is_physfn || dev->is_virtfn) {
struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
mutex_lock(&pdev->sriov->lock);
pdev->ats->ref_cnt--;
if (!pdev->ats->ref_cnt)
ats_free_one(pdev);
mutex_unlock(&pdev->sriov->lock);
}
if (!dev->is_physfn)
ats_free_one(dev);
} }
/** /**
...@@ -765,13 +799,17 @@ void pci_disable_ats(struct pci_dev *dev) ...@@ -765,13 +799,17 @@ void pci_disable_ats(struct pci_dev *dev)
* The ATS spec uses 0 in the Invalidate Queue Depth field to * The ATS spec uses 0 in the Invalidate Queue Depth field to
* indicate that the function can accept 32 Invalidate Request. * indicate that the function can accept 32 Invalidate Request.
* But here we use the `real' values (i.e. 1~32) for the Queue * But here we use the `real' values (i.e. 1~32) for the Queue
* Depth. * Depth; and 0 indicates the function shares the Queue with
* other functions (doesn't exclusively own a Queue).
*/ */
int pci_ats_queue_depth(struct pci_dev *dev) int pci_ats_queue_depth(struct pci_dev *dev)
{ {
int pos; int pos;
u16 cap; u16 cap;
if (dev->is_virtfn)
return 0;
if (dev->ats) if (dev->ats)
return dev->ats->qdep; return dev->ats->qdep;
......
...@@ -234,6 +234,8 @@ struct pci_ats { ...@@ -234,6 +234,8 @@ struct pci_ats {
int pos; /* capability position */ int pos; /* capability position */
int stu; /* Smallest Translation Unit */ int stu; /* Smallest Translation Unit */
int qdep; /* Invalidate Queue Depth */ int qdep; /* Invalidate Queue Depth */
int ref_cnt; /* Physical Function reference count */
int is_enabled:1; /* Enable bit is set */
}; };
#ifdef CONFIG_PCI_IOV #ifdef CONFIG_PCI_IOV
...@@ -255,7 +257,7 @@ extern int pci_ats_queue_depth(struct pci_dev *dev); ...@@ -255,7 +257,7 @@ extern int pci_ats_queue_depth(struct pci_dev *dev);
*/ */
static inline int pci_ats_enabled(struct pci_dev *dev) static inline int pci_ats_enabled(struct pci_dev *dev)
{ {
return !!dev->ats; return dev->ats && dev->ats->is_enabled;
} }
#else #else
static inline int pci_iov_init(struct pci_dev *dev) static inline int pci_iov_init(struct pci_dev *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment