提交 bd38c555 编写于 作者: M Matthew Wilcox

NVMe: Change NVME_IOCTL_GET_RANGE_TYPE to return all the ranges

Factor out most of nvme_identify() into a new nvme_submit_user_admin_command()
function.  Change nvme_get_range_type() to call it and change nvme_ioctl to
realise that it's getting back all 64 ranges.
Signed-off-by: NMatthew Wilcox <matthew.r.wilcox@intel.com>
上级 b8deb62c
...@@ -677,18 +677,17 @@ static int __devinit nvme_configure_admin_queue(struct nvme_dev *dev) ...@@ -677,18 +677,17 @@ static int __devinit nvme_configure_admin_queue(struct nvme_dev *dev)
return result; return result;
} }
static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns) static int nvme_submit_user_admin_command(struct nvme_dev *dev, unsigned long addr,
unsigned length, struct nvme_command *cmd)
{ {
struct nvme_dev *dev = ns->dev;
int i, err, count, nents, offset; int i, err, count, nents, offset;
struct nvme_command c;
struct scatterlist sg[2]; struct scatterlist sg[2];
struct page *pages[2]; struct page *pages[2];
if (addr & 3) if (addr & 3)
return -EINVAL; return -EINVAL;
offset = offset_in_page(addr); offset = offset_in_page(addr);
count = offset ? 2 : 1; count = ((offset + length) > PAGE_SIZE) ? 2 : 1;
err = get_user_pages_fast(addr, count, 1, pages); err = get_user_pages_fast(addr, count, 1, pages);
if (err < count) { if (err < count) {
...@@ -704,13 +703,9 @@ static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns) ...@@ -704,13 +703,9 @@ static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns)
if (!nents) if (!nents)
goto put_pages; goto put_pages;
memset(&c, 0, sizeof(c)); nvme_setup_prps(&cmd->common, sg, length);
c.identify.opcode = nvme_admin_identify;
c.identify.nsid = cns ? 0 : cpu_to_le32(ns->ns_id);
nvme_setup_prps(&c.common, sg, 4096);
c.identify.cns = cpu_to_le32(cns);
err = nvme_submit_admin_cmd(dev, &c, NULL); err = nvme_submit_admin_cmd(dev, cmd, NULL);
if (err) if (err)
err = -EIO; err = -EIO;
...@@ -723,34 +718,28 @@ static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns) ...@@ -723,34 +718,28 @@ static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns)
return err; return err;
} }
static int nvme_get_range_type(struct nvme_ns *ns, void __user *addr) static int nvme_identify(struct nvme_ns *ns, unsigned long addr, int cns)
{ {
struct nvme_dev *dev = ns->dev;
int status;
struct nvme_command c; struct nvme_command c;
void *page;
dma_addr_t dma_addr;
page = dma_alloc_coherent(&dev->pci_dev->dev, 4096, &dma_addr, memset(&c, 0, sizeof(c));
GFP_KERNEL); c.identify.opcode = nvme_admin_identify;
c.identify.nsid = cns ? 0 : cpu_to_le32(ns->ns_id);
c.identify.cns = cpu_to_le32(cns);
return nvme_submit_user_admin_command(ns->dev, addr, 4096, &c);
}
static int nvme_get_range_type(struct nvme_ns *ns, unsigned long addr)
{
struct nvme_command c;
memset(&c, 0, sizeof(c)); memset(&c, 0, sizeof(c));
c.features.opcode = nvme_admin_get_features; c.features.opcode = nvme_admin_get_features;
c.features.nsid = cpu_to_le32(ns->ns_id); c.features.nsid = cpu_to_le32(ns->ns_id);
c.features.prp1 = cpu_to_le64(dma_addr);
c.features.fid = cpu_to_le32(NVME_FEAT_LBA_RANGE); c.features.fid = cpu_to_le32(NVME_FEAT_LBA_RANGE);
status = nvme_submit_admin_cmd(dev, &c, NULL); return nvme_submit_user_admin_command(ns->dev, addr, 4096, &c);
/* XXX: Assuming first range for now */
if (status)
status = -EIO;
else if (copy_to_user(addr, page, 64))
status = -EFAULT;
dma_free_coherent(&dev->pci_dev->dev, 4096, page, dma_addr);
return status;
} }
static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
...@@ -764,7 +753,7 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, ...@@ -764,7 +753,7 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case NVME_IOCTL_IDENTIFY_CTRL: case NVME_IOCTL_IDENTIFY_CTRL:
return nvme_identify(ns, arg, 1); return nvme_identify(ns, arg, 1);
case NVME_IOCTL_GET_RANGE_TYPE: case NVME_IOCTL_GET_RANGE_TYPE:
return nvme_get_range_type(ns, (void __user *)arg); return nvme_get_range_type(ns, arg);
default: default:
return -ENOTTY; return -ENOTTY;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册