Commit f65efd6d authored by Christoph Hellwig's avatar Christoph Hellwig

nvme-pci: clean up CMB initialization

Refactor the call to nvme_map_cmb, and change the conditions for probing
for the CMB.  First remove the version check as NVMe TPs always apply
to earlier versions of the spec as well.  Second check for the whole CMBSZ
register for support of the CMB feature instead of just the size field
inside of it to simplify the code a bit.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <keith.busch@intel.com>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
parent 0fd997d3
...@@ -1651,21 +1651,20 @@ static ssize_t nvme_cmb_show(struct device *dev, ...@@ -1651,21 +1651,20 @@ static ssize_t nvme_cmb_show(struct device *dev,
} }
static DEVICE_ATTR(cmb, S_IRUGO, nvme_cmb_show, NULL); static DEVICE_ATTR(cmb, S_IRUGO, nvme_cmb_show, NULL);
static void __iomem *nvme_map_cmb(struct nvme_dev *dev) static void nvme_map_cmb(struct nvme_dev *dev)
{ {
u64 szu, size, offset; u64 szu, size, offset;
resource_size_t bar_size; resource_size_t bar_size;
struct pci_dev *pdev = to_pci_dev(dev->dev); struct pci_dev *pdev = to_pci_dev(dev->dev);
void __iomem *cmb;
int bar; int bar;
dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ); dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ);
if (!(NVME_CMB_SZ(dev->cmbsz))) if (!dev->cmbsz)
return NULL; return;
dev->cmbloc = readl(dev->bar + NVME_REG_CMBLOC); dev->cmbloc = readl(dev->bar + NVME_REG_CMBLOC);
if (!use_cmb_sqes) if (!use_cmb_sqes)
return NULL; return;
szu = (u64)1 << (12 + 4 * NVME_CMB_SZU(dev->cmbsz)); szu = (u64)1 << (12 + 4 * NVME_CMB_SZU(dev->cmbsz));
size = szu * NVME_CMB_SZ(dev->cmbsz); size = szu * NVME_CMB_SZ(dev->cmbsz);
...@@ -1674,7 +1673,7 @@ static void __iomem *nvme_map_cmb(struct nvme_dev *dev) ...@@ -1674,7 +1673,7 @@ static void __iomem *nvme_map_cmb(struct nvme_dev *dev)
bar_size = pci_resource_len(pdev, bar); bar_size = pci_resource_len(pdev, bar);
if (offset > bar_size) if (offset > bar_size)
return NULL; return;
/* /*
* Controllers may support a CMB size larger than their BAR, * Controllers may support a CMB size larger than their BAR,
...@@ -1684,13 +1683,16 @@ static void __iomem *nvme_map_cmb(struct nvme_dev *dev) ...@@ -1684,13 +1683,16 @@ static void __iomem *nvme_map_cmb(struct nvme_dev *dev)
if (size > bar_size - offset) if (size > bar_size - offset)
size = bar_size - offset; size = bar_size - offset;
cmb = ioremap_wc(pci_resource_start(pdev, bar) + offset, size); dev->cmb = ioremap_wc(pci_resource_start(pdev, bar) + offset, size);
if (!cmb) if (!dev->cmb)
return NULL; return;
dev->cmb_bus_addr = pci_bus_address(pdev, bar) + offset; dev->cmb_bus_addr = pci_bus_address(pdev, bar) + offset;
dev->cmb_size = size; dev->cmb_size = size;
return cmb;
if (sysfs_add_file_to_group(&dev->ctrl.device->kobj,
&dev_attr_cmb.attr, NULL))
dev_warn(dev->ctrl.device,
"failed to add sysfs attribute for CMB\n");
} }
static inline void nvme_release_cmb(struct nvme_dev *dev) static inline void nvme_release_cmb(struct nvme_dev *dev)
...@@ -2115,22 +2117,7 @@ static int nvme_pci_enable(struct nvme_dev *dev) ...@@ -2115,22 +2117,7 @@ static int nvme_pci_enable(struct nvme_dev *dev)
"set queue depth=%u\n", dev->q_depth); "set queue depth=%u\n", dev->q_depth);
} }
/* nvme_map_cmb(dev);
* CMBs can currently only exist on >=1.2 PCIe devices. We only
* populate sysfs if a CMB is implemented. Since nvme_dev_attrs_group
* has no name we can pass NULL as final argument to
* sysfs_add_file_to_group.
*/
if (readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 2, 0)) {
dev->cmb = nvme_map_cmb(dev);
if (dev->cmb) {
if (sysfs_add_file_to_group(&dev->ctrl.device->kobj,
&dev_attr_cmb.attr, NULL))
dev_warn(dev->ctrl.device,
"failed to add sysfs attribute for CMB\n");
}
}
pci_enable_pcie_error_reporting(pdev); pci_enable_pcie_error_reporting(pdev);
pci_save_state(pdev); pci_save_state(pdev);
......
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