aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/nvme.c
diff options
context:
space:
mode:
authorQuoc-Son Anh <quoc-sonx.anh@intel.com>2012-02-21 18:50:53 -0500
committerMatthew Wilcox <matthew.r.wilcox@intel.com>2012-07-31 13:31:34 -0400
commitcd58ad7d188c643cf572b038909c2f7dd96fdafe (patch)
tree187986ed44f50b6a71b33819561a98754efe04c9 /drivers/block/nvme.c
parent0ac13140d796eb1e2f8956aea97a6e5e4ebcf981 (diff)
NVMe: Use ida for nvme device instance
Signed-off-by: Quoc-Son Anh <quoc-sonx.anh@intel.com> Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Diffstat (limited to 'drivers/block/nvme.c')
-rw-r--r--drivers/block/nvme.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/drivers/block/nvme.c b/drivers/block/nvme.c
index 0ba6b7cb344b..3278fbdb8dc0 100644
--- a/drivers/block/nvme.c
+++ b/drivers/block/nvme.c
@@ -1576,15 +1576,33 @@ static void nvme_release_prp_pools(struct nvme_dev *dev)
1576 dma_pool_destroy(dev->prp_small_pool); 1576 dma_pool_destroy(dev->prp_small_pool);
1577} 1577}
1578 1578
1579/* XXX: Use an ida or something to let remove / add work correctly */ 1579static DEFINE_IDA(nvme_instance_ida);
1580static void nvme_set_instance(struct nvme_dev *dev) 1580
1581static int nvme_set_instance(struct nvme_dev *dev)
1581{ 1582{
1582 static int instance; 1583 int instance, error;
1583 dev->instance = instance++; 1584
1585 do {
1586 if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL))
1587 return -ENODEV;
1588
1589 spin_lock(&dev_list_lock);
1590 error = ida_get_new(&nvme_instance_ida, &instance);
1591 spin_unlock(&dev_list_lock);
1592 } while (error == -EAGAIN);
1593
1594 if (error)
1595 return -ENODEV;
1596
1597 dev->instance = instance;
1598 return 0;
1584} 1599}
1585 1600
1586static void nvme_release_instance(struct nvme_dev *dev) 1601static void nvme_release_instance(struct nvme_dev *dev)
1587{ 1602{
1603 spin_lock(&dev_list_lock);
1604 ida_remove(&nvme_instance_ida, dev->instance);
1605 spin_unlock(&dev_list_lock);
1588} 1606}
1589 1607
1590static int __devinit nvme_probe(struct pci_dev *pdev, 1608static int __devinit nvme_probe(struct pci_dev *pdev,
@@ -1617,7 +1635,10 @@ static int __devinit nvme_probe(struct pci_dev *pdev,
1617 pci_set_drvdata(pdev, dev); 1635 pci_set_drvdata(pdev, dev);
1618 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); 1636 dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
1619 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 1637 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
1620 nvme_set_instance(dev); 1638 result = nvme_set_instance(dev);
1639 if (result)
1640 goto disable;
1641
1621 dev->entry[0].vector = pdev->irq; 1642 dev->entry[0].vector = pdev->irq;
1622 1643
1623 result = nvme_setup_prp_pools(dev); 1644 result = nvme_setup_prp_pools(dev);