Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.infradead.org/users/willy/linux-nvme

Pull NVM Express driver update from Matthew Wilcox.

* git://git.infradead.org/users/willy/linux-nvme:
NVMe: Merge issue on character device bring-up
NVMe: Handle ioremap failure
NVMe: Add pci suspend/resume driver callbacks
NVMe: Use normal shutdown
NVMe: Separate controller init from disk discovery
NVMe: Separate queue alloc/free from create/delete
NVMe: Group pci related actions in functions
NVMe: Disk stats for read/write commands only
NVMe: Bring up cdev on set feature failure
NVMe: Fix checkpatch issues
NVMe: Namespace IDs are unsigned
NVMe: Update nvme_id_power_state with latest spec
NVMe: Split header file into user-visible and kernel-visible pieces
NVMe: Call nvme_process_cq from submission path
NVMe: Remove "process_cq did something" message
NVMe: Return correct value from interrupt handler
NVMe: Disk IO statistics
NVMe: Restructure MSI / MSI-X setup
NVMe: Use kzalloc instead of kmalloc+memset

+895 -658
+400 -185
drivers/block/nvme-core.c
··· 36 36 #include <linux/moduleparam.h> 37 37 #include <linux/pci.h> 38 38 #include <linux/poison.h> 39 + #include <linux/ptrace.h> 39 40 #include <linux/sched.h> 40 41 #include <linux/slab.h> 41 42 #include <linux/types.h> ··· 80 79 u16 sq_head; 81 80 u16 sq_tail; 82 81 u16 cq_head; 83 - u16 cq_phase; 82 + u8 cq_phase; 83 + u8 cqe_seen; 84 + u8 q_suspended; 84 85 unsigned long cmdid_data[]; 85 86 }; 86 87 ··· 116 113 static struct nvme_cmd_info *nvme_cmd_info(struct nvme_queue *nvmeq) 117 114 { 118 115 return (void *)&nvmeq->cmdid_data[BITS_TO_LONGS(nvmeq->q_depth)]; 116 + } 117 + 118 + static unsigned nvme_queue_extra(int depth) 119 + { 120 + return DIV_ROUND_UP(depth, 8) + (depth * sizeof(struct nvme_cmd_info)); 119 121 } 120 122 121 123 /** ··· 293 285 iod->npages = -1; 294 286 iod->length = nbytes; 295 287 iod->nents = 0; 288 + iod->start_time = jiffies; 296 289 } 297 290 298 291 return iod; ··· 317 308 kfree(iod); 318 309 } 319 310 311 + static void nvme_start_io_acct(struct bio *bio) 312 + { 313 + struct gendisk *disk = bio->bi_bdev->bd_disk; 314 + const int rw = bio_data_dir(bio); 315 + int cpu = part_stat_lock(); 316 + part_round_stats(cpu, &disk->part0); 317 + part_stat_inc(cpu, &disk->part0, ios[rw]); 318 + part_stat_add(cpu, &disk->part0, sectors[rw], bio_sectors(bio)); 319 + part_inc_in_flight(&disk->part0, rw); 320 + part_stat_unlock(); 321 + } 322 + 323 + static void nvme_end_io_acct(struct bio *bio, unsigned long start_time) 324 + { 325 + struct gendisk *disk = bio->bi_bdev->bd_disk; 326 + const int rw = bio_data_dir(bio); 327 + unsigned long duration = jiffies - start_time; 328 + int cpu = part_stat_lock(); 329 + part_stat_add(cpu, &disk->part0, ticks[rw], duration); 330 + part_round_stats(cpu, &disk->part0); 331 + part_dec_in_flight(&disk->part0, rw); 332 + part_stat_unlock(); 333 + } 334 + 320 335 static void bio_completion(struct nvme_dev *dev, void *ctx, 321 336 struct nvme_completion *cqe) 322 337 { ··· 348 315 struct bio *bio = iod->private; 349 316 u16 status = le16_to_cpup(&cqe->status) >> 1; 350 317 351 - if (iod->nents) 318 + if (iod->nents) { 352 319 dma_unmap_sg(&dev->pci_dev->dev, iod->sg, iod->nents, 353 320 bio_data_dir(bio) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 321 + nvme_end_io_acct(bio, iod->start_time); 322 + } 354 323 nvme_free_iod(dev, iod); 355 324 if (status) 356 325 bio_endio(bio, -EIO); ··· 457 422 458 423 if (atomic_dec_and_test(&bp->cnt)) { 459 424 bio_endio(bp->parent, bp->err); 460 - if (bp->bv1) 461 - kfree(bp->bv1); 462 - if (bp->bv2) 463 - kfree(bp->bv2); 425 + kfree(bp->bv1); 426 + kfree(bp->bv2); 464 427 kfree(bp); 465 428 } 466 429 } ··· 728 695 cmnd->rw.control = cpu_to_le16(control); 729 696 cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); 730 697 698 + nvme_start_io_acct(bio); 731 699 if (++nvmeq->sq_tail == nvmeq->q_depth) 732 700 nvmeq->sq_tail = 0; 733 701 writel(nvmeq->sq_tail, nvmeq->q_db); ··· 743 709 return result; 744 710 } 745 711 746 - static void nvme_make_request(struct request_queue *q, struct bio *bio) 747 - { 748 - struct nvme_ns *ns = q->queuedata; 749 - struct nvme_queue *nvmeq = get_nvmeq(ns->dev); 750 - int result = -EBUSY; 751 - 752 - spin_lock_irq(&nvmeq->q_lock); 753 - if (bio_list_empty(&nvmeq->sq_cong)) 754 - result = nvme_submit_bio_queue(nvmeq, ns, bio); 755 - if (unlikely(result)) { 756 - if (bio_list_empty(&nvmeq->sq_cong)) 757 - add_wait_queue(&nvmeq->sq_full, &nvmeq->sq_cong_wait); 758 - bio_list_add(&nvmeq->sq_cong, bio); 759 - } 760 - 761 - spin_unlock_irq(&nvmeq->q_lock); 762 - put_nvmeq(nvmeq); 763 - } 764 - 765 - static irqreturn_t nvme_process_cq(struct nvme_queue *nvmeq) 712 + static int nvme_process_cq(struct nvme_queue *nvmeq) 766 713 { 767 714 u16 head, phase; 768 715 ··· 773 758 * a big problem. 774 759 */ 775 760 if (head == nvmeq->cq_head && phase == nvmeq->cq_phase) 776 - return IRQ_NONE; 761 + return 0; 777 762 778 763 writel(head, nvmeq->q_db + (1 << nvmeq->dev->db_stride)); 779 764 nvmeq->cq_head = head; 780 765 nvmeq->cq_phase = phase; 781 766 782 - return IRQ_HANDLED; 767 + nvmeq->cqe_seen = 1; 768 + return 1; 769 + } 770 + 771 + static void nvme_make_request(struct request_queue *q, struct bio *bio) 772 + { 773 + struct nvme_ns *ns = q->queuedata; 774 + struct nvme_queue *nvmeq = get_nvmeq(ns->dev); 775 + int result = -EBUSY; 776 + 777 + if (!nvmeq) { 778 + put_nvmeq(NULL); 779 + bio_endio(bio, -EIO); 780 + return; 781 + } 782 + 783 + spin_lock_irq(&nvmeq->q_lock); 784 + if (!nvmeq->q_suspended && bio_list_empty(&nvmeq->sq_cong)) 785 + result = nvme_submit_bio_queue(nvmeq, ns, bio); 786 + if (unlikely(result)) { 787 + if (bio_list_empty(&nvmeq->sq_cong)) 788 + add_wait_queue(&nvmeq->sq_full, &nvmeq->sq_cong_wait); 789 + bio_list_add(&nvmeq->sq_cong, bio); 790 + } 791 + 792 + nvme_process_cq(nvmeq); 793 + spin_unlock_irq(&nvmeq->q_lock); 794 + put_nvmeq(nvmeq); 783 795 } 784 796 785 797 static irqreturn_t nvme_irq(int irq, void *data) ··· 814 772 irqreturn_t result; 815 773 struct nvme_queue *nvmeq = data; 816 774 spin_lock(&nvmeq->q_lock); 817 - result = nvme_process_cq(nvmeq); 775 + nvme_process_cq(nvmeq); 776 + result = nvmeq->cqe_seen ? IRQ_HANDLED : IRQ_NONE; 777 + nvmeq->cqe_seen = 0; 818 778 spin_unlock(&nvmeq->q_lock); 819 779 return result; 820 780 } ··· 1030 986 } 1031 987 } 1032 988 1033 - static void nvme_free_queue_mem(struct nvme_queue *nvmeq) 989 + static void nvme_free_queue(struct nvme_queue *nvmeq) 1034 990 { 991 + spin_lock_irq(&nvmeq->q_lock); 992 + while (bio_list_peek(&nvmeq->sq_cong)) { 993 + struct bio *bio = bio_list_pop(&nvmeq->sq_cong); 994 + bio_endio(bio, -EIO); 995 + } 996 + spin_unlock_irq(&nvmeq->q_lock); 997 + 1035 998 dma_free_coherent(nvmeq->q_dmadev, CQ_SIZE(nvmeq->q_depth), 1036 999 (void *)nvmeq->cqes, nvmeq->cq_dma_addr); 1037 1000 dma_free_coherent(nvmeq->q_dmadev, SQ_SIZE(nvmeq->q_depth), ··· 1046 995 kfree(nvmeq); 1047 996 } 1048 997 1049 - static void nvme_free_queue(struct nvme_dev *dev, int qid) 998 + static void nvme_free_queues(struct nvme_dev *dev) 999 + { 1000 + int i; 1001 + 1002 + for (i = dev->queue_count - 1; i >= 0; i--) { 1003 + nvme_free_queue(dev->queues[i]); 1004 + dev->queue_count--; 1005 + dev->queues[i] = NULL; 1006 + } 1007 + } 1008 + 1009 + static void nvme_disable_queue(struct nvme_dev *dev, int qid) 1050 1010 { 1051 1011 struct nvme_queue *nvmeq = dev->queues[qid]; 1052 1012 int vector = dev->entry[nvmeq->cq_vector].vector; 1053 1013 1054 1014 spin_lock_irq(&nvmeq->q_lock); 1055 - nvme_cancel_ios(nvmeq, false); 1056 - while (bio_list_peek(&nvmeq->sq_cong)) { 1057 - struct bio *bio = bio_list_pop(&nvmeq->sq_cong); 1058 - bio_endio(bio, -EIO); 1015 + if (nvmeq->q_suspended) { 1016 + spin_unlock_irq(&nvmeq->q_lock); 1017 + return; 1059 1018 } 1019 + nvmeq->q_suspended = 1; 1060 1020 spin_unlock_irq(&nvmeq->q_lock); 1061 1021 1062 1022 irq_set_affinity_hint(vector, NULL); ··· 1079 1017 adapter_delete_cq(dev, qid); 1080 1018 } 1081 1019 1082 - nvme_free_queue_mem(nvmeq); 1020 + spin_lock_irq(&nvmeq->q_lock); 1021 + nvme_process_cq(nvmeq); 1022 + nvme_cancel_ios(nvmeq, false); 1023 + spin_unlock_irq(&nvmeq->q_lock); 1083 1024 } 1084 1025 1085 1026 static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid, 1086 1027 int depth, int vector) 1087 1028 { 1088 1029 struct device *dmadev = &dev->pci_dev->dev; 1089 - unsigned extra = DIV_ROUND_UP(depth, 8) + (depth * 1090 - sizeof(struct nvme_cmd_info)); 1030 + unsigned extra = nvme_queue_extra(depth); 1091 1031 struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq) + extra, GFP_KERNEL); 1092 1032 if (!nvmeq) 1093 1033 return NULL; ··· 1116 1052 nvmeq->q_db = &dev->dbs[qid << (dev->db_stride + 1)]; 1117 1053 nvmeq->q_depth = depth; 1118 1054 nvmeq->cq_vector = vector; 1055 + nvmeq->q_suspended = 1; 1056 + dev->queue_count++; 1119 1057 1120 1058 return nvmeq; 1121 1059 ··· 1141 1075 IRQF_DISABLED | IRQF_SHARED, name, nvmeq); 1142 1076 } 1143 1077 1144 - static struct nvme_queue *nvme_create_queue(struct nvme_dev *dev, int qid, 1145 - int cq_size, int vector) 1078 + static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid) 1146 1079 { 1147 - int result; 1148 - struct nvme_queue *nvmeq = nvme_alloc_queue(dev, qid, cq_size, vector); 1080 + struct nvme_dev *dev = nvmeq->dev; 1081 + unsigned extra = nvme_queue_extra(nvmeq->q_depth); 1149 1082 1150 - if (!nvmeq) 1151 - return ERR_PTR(-ENOMEM); 1083 + nvmeq->sq_tail = 0; 1084 + nvmeq->cq_head = 0; 1085 + nvmeq->cq_phase = 1; 1086 + nvmeq->q_db = &dev->dbs[qid << (dev->db_stride + 1)]; 1087 + memset(nvmeq->cmdid_data, 0, extra); 1088 + memset((void *)nvmeq->cqes, 0, CQ_SIZE(nvmeq->q_depth)); 1089 + nvme_cancel_ios(nvmeq, false); 1090 + nvmeq->q_suspended = 0; 1091 + } 1092 + 1093 + static int nvme_create_queue(struct nvme_queue *nvmeq, int qid) 1094 + { 1095 + struct nvme_dev *dev = nvmeq->dev; 1096 + int result; 1152 1097 1153 1098 result = adapter_alloc_cq(dev, qid, nvmeq); 1154 1099 if (result < 0) 1155 - goto free_nvmeq; 1100 + return result; 1156 1101 1157 1102 result = adapter_alloc_sq(dev, qid, nvmeq); 1158 1103 if (result < 0) ··· 1173 1096 if (result < 0) 1174 1097 goto release_sq; 1175 1098 1176 - return nvmeq; 1099 + spin_lock(&nvmeq->q_lock); 1100 + nvme_init_queue(nvmeq, qid); 1101 + spin_unlock(&nvmeq->q_lock); 1102 + 1103 + return result; 1177 1104 1178 1105 release_sq: 1179 1106 adapter_delete_sq(dev, qid); 1180 1107 release_cq: 1181 1108 adapter_delete_cq(dev, qid); 1182 - free_nvmeq: 1183 - dma_free_coherent(nvmeq->q_dmadev, CQ_SIZE(nvmeq->q_depth), 1184 - (void *)nvmeq->cqes, nvmeq->cq_dma_addr); 1185 - dma_free_coherent(nvmeq->q_dmadev, SQ_SIZE(nvmeq->q_depth), 1186 - nvmeq->sq_cmds, nvmeq->sq_dma_addr); 1187 - kfree(nvmeq); 1188 - return ERR_PTR(result); 1109 + return result; 1189 1110 } 1190 1111 1191 1112 static int nvme_wait_ready(struct nvme_dev *dev, u64 cap, bool enabled) ··· 1227 1152 return nvme_wait_ready(dev, cap, true); 1228 1153 } 1229 1154 1155 + static int nvme_shutdown_ctrl(struct nvme_dev *dev) 1156 + { 1157 + unsigned long timeout; 1158 + u32 cc; 1159 + 1160 + cc = (readl(&dev->bar->cc) & ~NVME_CC_SHN_MASK) | NVME_CC_SHN_NORMAL; 1161 + writel(cc, &dev->bar->cc); 1162 + 1163 + timeout = 2 * HZ + jiffies; 1164 + while ((readl(&dev->bar->csts) & NVME_CSTS_SHST_MASK) != 1165 + NVME_CSTS_SHST_CMPLT) { 1166 + msleep(100); 1167 + if (fatal_signal_pending(current)) 1168 + return -EINTR; 1169 + if (time_after(jiffies, timeout)) { 1170 + dev_err(&dev->pci_dev->dev, 1171 + "Device shutdown incomplete; abort shutdown\n"); 1172 + return -ENODEV; 1173 + } 1174 + } 1175 + 1176 + return 0; 1177 + } 1178 + 1230 1179 static int nvme_configure_admin_queue(struct nvme_dev *dev) 1231 1180 { 1232 1181 int result; ··· 1258 1159 u64 cap = readq(&dev->bar->cap); 1259 1160 struct nvme_queue *nvmeq; 1260 1161 1261 - dev->dbs = ((void __iomem *)dev->bar) + 4096; 1262 - dev->db_stride = NVME_CAP_STRIDE(cap); 1263 - 1264 1162 result = nvme_disable_ctrl(dev, cap); 1265 1163 if (result < 0) 1266 1164 return result; 1267 1165 1268 - nvmeq = nvme_alloc_queue(dev, 0, 64, 0); 1269 - if (!nvmeq) 1270 - return -ENOMEM; 1166 + nvmeq = dev->queues[0]; 1167 + if (!nvmeq) { 1168 + nvmeq = nvme_alloc_queue(dev, 0, 64, 0); 1169 + if (!nvmeq) 1170 + return -ENOMEM; 1171 + dev->queues[0] = nvmeq; 1172 + } 1271 1173 1272 1174 aqa = nvmeq->q_depth - 1; 1273 1175 aqa |= aqa << 16; ··· 1285 1185 1286 1186 result = nvme_enable_ctrl(dev, cap); 1287 1187 if (result) 1288 - goto free_q; 1188 + return result; 1289 1189 1290 1190 result = queue_request_irq(dev, nvmeq, "nvme admin"); 1291 1191 if (result) 1292 - goto free_q; 1192 + return result; 1293 1193 1294 - dev->queues[0] = nvmeq; 1295 - return result; 1296 - 1297 - free_q: 1298 - nvme_free_queue_mem(nvmeq); 1194 + spin_lock(&nvmeq->q_lock); 1195 + nvme_init_queue(nvmeq, 0); 1196 + spin_unlock(&nvmeq->q_lock); 1299 1197 return result; 1300 1198 } 1301 1199 ··· 1412 1314 c.rw.appmask = cpu_to_le16(io.appmask); 1413 1315 1414 1316 if (meta_len) { 1415 - meta_iod = nvme_map_user_pages(dev, io.opcode & 1, io.metadata, meta_len); 1317 + meta_iod = nvme_map_user_pages(dev, io.opcode & 1, io.metadata, 1318 + meta_len); 1416 1319 if (IS_ERR(meta_iod)) { 1417 1320 status = PTR_ERR(meta_iod); 1418 1321 meta_iod = NULL; ··· 1455 1356 put_nvmeq(nvmeq); 1456 1357 if (length != (io.nblocks + 1) << ns->lba_shift) 1457 1358 status = -ENOMEM; 1359 + else if (!nvmeq || nvmeq->q_suspended) 1360 + status = -EBUSY; 1458 1361 else 1459 1362 status = nvme_submit_sync_cmd(nvmeq, &c, NULL, NVME_IO_TIMEOUT); 1460 1363 ··· 1554 1453 1555 1454 switch (cmd) { 1556 1455 case NVME_IOCTL_ID: 1456 + force_successful_syscall_return(); 1557 1457 return ns->ns_id; 1558 1458 case NVME_IOCTL_ADMIN_CMD: 1559 1459 return nvme_user_admin_cmd(ns->dev, (void __user *)arg); ··· 1608 1506 if (!nvmeq) 1609 1507 continue; 1610 1508 spin_lock_irq(&nvmeq->q_lock); 1611 - if (nvme_process_cq(nvmeq)) 1612 - printk("process_cq did something\n"); 1509 + if (nvmeq->q_suspended) 1510 + goto unlock; 1511 + nvme_process_cq(nvmeq); 1613 1512 nvme_cancel_ios(nvmeq, true); 1614 1513 nvme_resubmit_bios(nvmeq); 1514 + unlock: 1615 1515 spin_unlock_irq(&nvmeq->q_lock); 1616 1516 } 1617 1517 } ··· 1660 1556 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, ns->queue); 1661 1557 } 1662 1558 1663 - static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, int nsid, 1559 + static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, 1664 1560 struct nvme_id_ns *id, struct nvme_lba_range_type *rt) 1665 1561 { 1666 1562 struct nvme_ns *ns; ··· 1735 1631 status = nvme_set_features(dev, NVME_FEAT_NUM_QUEUES, q_count, 0, 1736 1632 &result); 1737 1633 if (status) 1738 - return -EIO; 1634 + return status < 0 ? -EIO : -EBUSY; 1739 1635 return min(result & 0xffff, result >> 16) + 1; 1636 + } 1637 + 1638 + static size_t db_bar_size(struct nvme_dev *dev, unsigned nr_io_queues) 1639 + { 1640 + return 4096 + ((nr_io_queues + 1) << (dev->db_stride + 3)); 1740 1641 } 1741 1642 1742 1643 static int nvme_setup_io_queues(struct nvme_dev *dev) 1743 1644 { 1744 1645 struct pci_dev *pdev = dev->pci_dev; 1745 - int result, cpu, i, nr_io_queues, db_bar_size, q_depth, q_count; 1646 + int result, cpu, i, vecs, nr_io_queues, size, q_depth; 1746 1647 1747 1648 nr_io_queues = num_online_cpus(); 1748 1649 result = set_queue_count(dev, nr_io_queues); ··· 1756 1647 if (result < nr_io_queues) 1757 1648 nr_io_queues = result; 1758 1649 1759 - q_count = nr_io_queues; 1760 - /* Deregister the admin queue's interrupt */ 1761 - free_irq(dev->entry[0].vector, dev->queues[0]); 1762 - 1763 - db_bar_size = 4096 + ((nr_io_queues + 1) << (dev->db_stride + 3)); 1764 - if (db_bar_size > 8192) { 1650 + size = db_bar_size(dev, nr_io_queues); 1651 + if (size > 8192) { 1765 1652 iounmap(dev->bar); 1766 - dev->bar = ioremap(pci_resource_start(pdev, 0), db_bar_size); 1653 + do { 1654 + dev->bar = ioremap(pci_resource_start(pdev, 0), size); 1655 + if (dev->bar) 1656 + break; 1657 + if (!--nr_io_queues) 1658 + return -ENOMEM; 1659 + size = db_bar_size(dev, nr_io_queues); 1660 + } while (1); 1767 1661 dev->dbs = ((void __iomem *)dev->bar) + 4096; 1768 1662 dev->queues[0]->q_db = dev->dbs; 1769 1663 } 1770 1664 1771 - for (i = 0; i < nr_io_queues; i++) 1665 + /* Deregister the admin queue's interrupt */ 1666 + free_irq(dev->entry[0].vector, dev->queues[0]); 1667 + 1668 + vecs = nr_io_queues; 1669 + for (i = 0; i < vecs; i++) 1772 1670 dev->entry[i].entry = i; 1773 1671 for (;;) { 1774 - result = pci_enable_msix(pdev, dev->entry, nr_io_queues); 1775 - if (result == 0) { 1672 + result = pci_enable_msix(pdev, dev->entry, vecs); 1673 + if (result <= 0) 1776 1674 break; 1777 - } else if (result > 0) { 1778 - nr_io_queues = result; 1779 - continue; 1780 - } else { 1781 - nr_io_queues = 0; 1782 - break; 1783 - } 1675 + vecs = result; 1784 1676 } 1785 1677 1786 - if (nr_io_queues == 0) { 1787 - nr_io_queues = q_count; 1678 + if (result < 0) { 1679 + vecs = nr_io_queues; 1680 + if (vecs > 32) 1681 + vecs = 32; 1788 1682 for (;;) { 1789 - result = pci_enable_msi_block(pdev, nr_io_queues); 1683 + result = pci_enable_msi_block(pdev, vecs); 1790 1684 if (result == 0) { 1791 - for (i = 0; i < nr_io_queues; i++) 1685 + for (i = 0; i < vecs; i++) 1792 1686 dev->entry[i].vector = i + pdev->irq; 1793 1687 break; 1794 - } else if (result > 0) { 1795 - nr_io_queues = result; 1796 - continue; 1797 - } else { 1798 - nr_io_queues = 1; 1688 + } else if (result < 0) { 1689 + vecs = 1; 1799 1690 break; 1800 1691 } 1692 + vecs = result; 1801 1693 } 1802 1694 } 1803 1695 1696 + /* 1697 + * Should investigate if there's a performance win from allocating 1698 + * more queues than interrupt vectors; it might allow the submission 1699 + * path to scale better, even if the receive path is limited by the 1700 + * number of interrupts. 1701 + */ 1702 + nr_io_queues = vecs; 1703 + 1804 1704 result = queue_request_irq(dev, dev->queues[0], "nvme admin"); 1805 - /* XXX: handle failure here */ 1705 + if (result) { 1706 + dev->queues[0]->q_suspended = 1; 1707 + goto free_queues; 1708 + } 1709 + 1710 + /* Free previously allocated queues that are no longer usable */ 1711 + spin_lock(&dev_list_lock); 1712 + for (i = dev->queue_count - 1; i > nr_io_queues; i--) { 1713 + struct nvme_queue *nvmeq = dev->queues[i]; 1714 + 1715 + spin_lock(&nvmeq->q_lock); 1716 + nvme_cancel_ios(nvmeq, false); 1717 + spin_unlock(&nvmeq->q_lock); 1718 + 1719 + nvme_free_queue(nvmeq); 1720 + dev->queue_count--; 1721 + dev->queues[i] = NULL; 1722 + } 1723 + spin_unlock(&dev_list_lock); 1806 1724 1807 1725 cpu = cpumask_first(cpu_online_mask); 1808 1726 for (i = 0; i < nr_io_queues; i++) { ··· 1839 1703 1840 1704 q_depth = min_t(int, NVME_CAP_MQES(readq(&dev->bar->cap)) + 1, 1841 1705 NVME_Q_DEPTH); 1842 - for (i = 0; i < nr_io_queues; i++) { 1843 - dev->queues[i + 1] = nvme_create_queue(dev, i + 1, q_depth, i); 1844 - if (IS_ERR(dev->queues[i + 1])) 1845 - return PTR_ERR(dev->queues[i + 1]); 1846 - dev->queue_count++; 1706 + for (i = dev->queue_count - 1; i < nr_io_queues; i++) { 1707 + dev->queues[i + 1] = nvme_alloc_queue(dev, i + 1, q_depth, i); 1708 + if (!dev->queues[i + 1]) { 1709 + result = -ENOMEM; 1710 + goto free_queues; 1711 + } 1847 1712 } 1848 1713 1849 1714 for (; i < num_possible_cpus(); i++) { ··· 1852 1715 dev->queues[i + 1] = dev->queues[target + 1]; 1853 1716 } 1854 1717 1718 + for (i = 1; i < dev->queue_count; i++) { 1719 + result = nvme_create_queue(dev->queues[i], i); 1720 + if (result) { 1721 + for (--i; i > 0; i--) 1722 + nvme_disable_queue(dev, i); 1723 + goto free_queues; 1724 + } 1725 + } 1726 + 1855 1727 return 0; 1856 - } 1857 1728 1858 - static void nvme_free_queues(struct nvme_dev *dev) 1859 - { 1860 - int i; 1861 - 1862 - for (i = dev->queue_count - 1; i >= 0; i--) 1863 - nvme_free_queue(dev, i); 1729 + free_queues: 1730 + nvme_free_queues(dev); 1731 + return result; 1864 1732 } 1865 1733 1866 1734 /* ··· 1876 1734 */ 1877 1735 static int nvme_dev_add(struct nvme_dev *dev) 1878 1736 { 1879 - int res, nn, i; 1737 + int res; 1738 + unsigned nn, i; 1880 1739 struct nvme_ns *ns; 1881 1740 struct nvme_id_ctrl *ctrl; 1882 1741 struct nvme_id_ns *id_ns; 1883 1742 void *mem; 1884 1743 dma_addr_t dma_addr; 1885 1744 int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12; 1886 - 1887 - res = nvme_setup_io_queues(dev); 1888 - if (res) 1889 - return res; 1890 1745 1891 1746 mem = dma_alloc_coherent(&dev->pci_dev->dev, 8192, &dma_addr, 1892 1747 GFP_KERNEL); ··· 1935 1796 return res; 1936 1797 } 1937 1798 1938 - static int nvme_dev_remove(struct nvme_dev *dev) 1799 + static int nvme_dev_map(struct nvme_dev *dev) 1939 1800 { 1940 - struct nvme_ns *ns, *next; 1801 + int bars, result = -ENOMEM; 1802 + struct pci_dev *pdev = dev->pci_dev; 1803 + 1804 + if (pci_enable_device_mem(pdev)) 1805 + return result; 1806 + 1807 + dev->entry[0].vector = pdev->irq; 1808 + pci_set_master(pdev); 1809 + bars = pci_select_bars(pdev, IORESOURCE_MEM); 1810 + if (pci_request_selected_regions(pdev, bars, "nvme")) 1811 + goto disable_pci; 1812 + 1813 + if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) 1814 + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 1815 + else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) 1816 + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 1817 + else 1818 + goto disable_pci; 1819 + 1820 + pci_set_drvdata(pdev, dev); 1821 + dev->bar = ioremap(pci_resource_start(pdev, 0), 8192); 1822 + if (!dev->bar) 1823 + goto disable; 1824 + 1825 + dev->db_stride = NVME_CAP_STRIDE(readq(&dev->bar->cap)); 1826 + dev->dbs = ((void __iomem *)dev->bar) + 4096; 1827 + 1828 + return 0; 1829 + 1830 + disable: 1831 + pci_release_regions(pdev); 1832 + disable_pci: 1833 + pci_disable_device(pdev); 1834 + return result; 1835 + } 1836 + 1837 + static void nvme_dev_unmap(struct nvme_dev *dev) 1838 + { 1839 + if (dev->pci_dev->msi_enabled) 1840 + pci_disable_msi(dev->pci_dev); 1841 + else if (dev->pci_dev->msix_enabled) 1842 + pci_disable_msix(dev->pci_dev); 1843 + 1844 + if (dev->bar) { 1845 + iounmap(dev->bar); 1846 + dev->bar = NULL; 1847 + } 1848 + 1849 + pci_release_regions(dev->pci_dev); 1850 + if (pci_is_enabled(dev->pci_dev)) 1851 + pci_disable_device(dev->pci_dev); 1852 + } 1853 + 1854 + static void nvme_dev_shutdown(struct nvme_dev *dev) 1855 + { 1856 + int i; 1857 + 1858 + for (i = dev->queue_count - 1; i >= 0; i--) 1859 + nvme_disable_queue(dev, i); 1941 1860 1942 1861 spin_lock(&dev_list_lock); 1943 - list_del(&dev->node); 1862 + list_del_init(&dev->node); 1944 1863 spin_unlock(&dev_list_lock); 1864 + 1865 + if (dev->bar) 1866 + nvme_shutdown_ctrl(dev); 1867 + nvme_dev_unmap(dev); 1868 + } 1869 + 1870 + static void nvme_dev_remove(struct nvme_dev *dev) 1871 + { 1872 + struct nvme_ns *ns, *next; 1945 1873 1946 1874 list_for_each_entry_safe(ns, next, &dev->namespaces, list) { 1947 1875 list_del(&ns->list); 1948 1876 del_gendisk(ns->disk); 1949 1877 nvme_ns_free(ns); 1950 1878 } 1951 - 1952 - nvme_free_queues(dev); 1953 - 1954 - return 0; 1955 1879 } 1956 1880 1957 1881 static int nvme_setup_prp_pools(struct nvme_dev *dev) ··· 2074 1872 { 2075 1873 struct nvme_dev *dev = container_of(kref, struct nvme_dev, kref); 2076 1874 nvme_dev_remove(dev); 2077 - if (dev->pci_dev->msi_enabled) 2078 - pci_disable_msi(dev->pci_dev); 2079 - else if (dev->pci_dev->msix_enabled) 2080 - pci_disable_msix(dev->pci_dev); 2081 - iounmap(dev->bar); 1875 + nvme_dev_shutdown(dev); 1876 + nvme_free_queues(dev); 2082 1877 nvme_release_instance(dev); 2083 1878 nvme_release_prp_pools(dev); 2084 - pci_disable_device(dev->pci_dev); 2085 - pci_release_regions(dev->pci_dev); 2086 1879 kfree(dev->queues); 2087 1880 kfree(dev->entry); 2088 1881 kfree(dev); ··· 2118 1921 .compat_ioctl = nvme_dev_ioctl, 2119 1922 }; 2120 1923 1924 + static int nvme_dev_start(struct nvme_dev *dev) 1925 + { 1926 + int result; 1927 + 1928 + result = nvme_dev_map(dev); 1929 + if (result) 1930 + return result; 1931 + 1932 + result = nvme_configure_admin_queue(dev); 1933 + if (result) 1934 + goto unmap; 1935 + 1936 + spin_lock(&dev_list_lock); 1937 + list_add(&dev->node, &dev_list); 1938 + spin_unlock(&dev_list_lock); 1939 + 1940 + result = nvme_setup_io_queues(dev); 1941 + if (result && result != -EBUSY) 1942 + goto disable; 1943 + 1944 + return result; 1945 + 1946 + disable: 1947 + spin_lock(&dev_list_lock); 1948 + list_del_init(&dev->node); 1949 + spin_unlock(&dev_list_lock); 1950 + unmap: 1951 + nvme_dev_unmap(dev); 1952 + return result; 1953 + } 1954 + 2121 1955 static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) 2122 1956 { 2123 - int bars, result = -ENOMEM; 1957 + int result = -ENOMEM; 2124 1958 struct nvme_dev *dev; 2125 1959 2126 1960 dev = kzalloc(sizeof(*dev), GFP_KERNEL); ··· 2166 1938 if (!dev->queues) 2167 1939 goto free; 2168 1940 2169 - if (pci_enable_device_mem(pdev)) 2170 - goto free; 2171 - pci_set_master(pdev); 2172 - bars = pci_select_bars(pdev, IORESOURCE_MEM); 2173 - if (pci_request_selected_regions(pdev, bars, "nvme")) 2174 - goto disable; 2175 - 2176 1941 INIT_LIST_HEAD(&dev->namespaces); 2177 1942 dev->pci_dev = pdev; 2178 - pci_set_drvdata(pdev, dev); 2179 - 2180 - if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) 2181 - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); 2182 - else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) 2183 - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 2184 - else 2185 - goto disable; 2186 - 2187 1943 result = nvme_set_instance(dev); 2188 1944 if (result) 2189 - goto disable; 2190 - 2191 - dev->entry[0].vector = pdev->irq; 1945 + goto free; 2192 1946 2193 1947 result = nvme_setup_prp_pools(dev); 2194 1948 if (result) 2195 - goto disable_msix; 1949 + goto release; 2196 1950 2197 - dev->bar = ioremap(pci_resource_start(pdev, 0), 8192); 2198 - if (!dev->bar) { 2199 - result = -ENOMEM; 2200 - goto disable_msix; 1951 + result = nvme_dev_start(dev); 1952 + if (result) { 1953 + if (result == -EBUSY) 1954 + goto create_cdev; 1955 + goto release_pools; 2201 1956 } 2202 - 2203 - result = nvme_configure_admin_queue(dev); 2204 - if (result) 2205 - goto unmap; 2206 - dev->queue_count++; 2207 - 2208 - spin_lock(&dev_list_lock); 2209 - list_add(&dev->node, &dev_list); 2210 - spin_unlock(&dev_list_lock); 2211 1957 2212 1958 result = nvme_dev_add(dev); 2213 1959 if (result) 2214 - goto delete; 1960 + goto shutdown; 2215 1961 1962 + create_cdev: 2216 1963 scnprintf(dev->name, sizeof(dev->name), "nvme%d", dev->instance); 2217 1964 dev->miscdev.minor = MISC_DYNAMIC_MINOR; 2218 1965 dev->miscdev.parent = &pdev->dev; ··· 2202 1999 2203 2000 remove: 2204 2001 nvme_dev_remove(dev); 2205 - delete: 2206 - spin_lock(&dev_list_lock); 2207 - list_del(&dev->node); 2208 - spin_unlock(&dev_list_lock); 2209 - 2002 + shutdown: 2003 + nvme_dev_shutdown(dev); 2004 + release_pools: 2210 2005 nvme_free_queues(dev); 2211 - unmap: 2212 - iounmap(dev->bar); 2213 - disable_msix: 2214 - if (dev->pci_dev->msi_enabled) 2215 - pci_disable_msi(dev->pci_dev); 2216 - else if (dev->pci_dev->msix_enabled) 2217 - pci_disable_msix(dev->pci_dev); 2218 - nvme_release_instance(dev); 2219 2006 nvme_release_prp_pools(dev); 2220 - disable: 2221 - pci_disable_device(pdev); 2222 - pci_release_regions(pdev); 2007 + release: 2008 + nvme_release_instance(dev); 2223 2009 free: 2224 2010 kfree(dev->queues); 2225 2011 kfree(dev->entry); ··· 2229 2037 #define nvme_link_reset NULL 2230 2038 #define nvme_slot_reset NULL 2231 2039 #define nvme_error_resume NULL 2232 - #define nvme_suspend NULL 2233 - #define nvme_resume NULL 2040 + 2041 + static int nvme_suspend(struct device *dev) 2042 + { 2043 + struct pci_dev *pdev = to_pci_dev(dev); 2044 + struct nvme_dev *ndev = pci_get_drvdata(pdev); 2045 + 2046 + nvme_dev_shutdown(ndev); 2047 + return 0; 2048 + } 2049 + 2050 + static int nvme_resume(struct device *dev) 2051 + { 2052 + struct pci_dev *pdev = to_pci_dev(dev); 2053 + struct nvme_dev *ndev = pci_get_drvdata(pdev); 2054 + int ret; 2055 + 2056 + ret = nvme_dev_start(ndev); 2057 + /* XXX: should remove gendisks if resume fails */ 2058 + if (ret) 2059 + nvme_free_queues(ndev); 2060 + return ret; 2061 + } 2062 + 2063 + static SIMPLE_DEV_PM_OPS(nvme_dev_pm_ops, nvme_suspend, nvme_resume); 2234 2064 2235 2065 static const struct pci_error_handlers nvme_err_handler = { 2236 2066 .error_detected = nvme_error_detected, ··· 2276 2062 .id_table = nvme_id_table, 2277 2063 .probe = nvme_probe, 2278 2064 .remove = nvme_remove, 2279 - .suspend = nvme_suspend, 2280 - .resume = nvme_resume, 2065 + .driver = { 2066 + .pm = &nvme_dev_pm_ops, 2067 + }, 2281 2068 .err_handler = &nvme_err_handler, 2282 2069 }; 2283 2070
+8 -16
drivers/block/nvme-scsi.c
··· 933 933 int res = SNTI_TRANSLATION_SUCCESS; 934 934 int xfer_len; 935 935 936 - inq_response = kmalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH, GFP_KERNEL); 936 + inq_response = kzalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH, GFP_KERNEL); 937 937 if (inq_response == NULL) { 938 938 res = -ENOMEM; 939 939 goto out_mem; 940 940 } 941 941 942 - memset(inq_response, 0, EXTENDED_INQUIRY_DATA_PAGE_LENGTH); 943 942 inq_response[1] = INQ_BDEV_CHARACTERISTICS_PAGE; /* Page Code */ 944 943 inq_response[2] = 0x00; /* Page Length MSB */ 945 944 inq_response[3] = 0x3C; /* Page Length LSB */ ··· 963 964 int xfer_len; 964 965 u8 *log_response; 965 966 966 - log_response = kmalloc(LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH, GFP_KERNEL); 967 + log_response = kzalloc(LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH, GFP_KERNEL); 967 968 if (log_response == NULL) { 968 969 res = -ENOMEM; 969 970 goto out_mem; 970 971 } 971 - memset(log_response, 0, LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH); 972 972 973 973 log_response[0] = LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE; 974 974 /* Subpage=0x00, Page Length MSB=0 */ ··· 998 1000 u8 temp_c; 999 1001 u16 temp_k; 1000 1002 1001 - log_response = kmalloc(LOG_INFO_EXCP_PAGE_LENGTH, GFP_KERNEL); 1003 + log_response = kzalloc(LOG_INFO_EXCP_PAGE_LENGTH, GFP_KERNEL); 1002 1004 if (log_response == NULL) { 1003 1005 res = -ENOMEM; 1004 1006 goto out_mem; 1005 1007 } 1006 - memset(log_response, 0, LOG_INFO_EXCP_PAGE_LENGTH); 1007 1008 1008 1009 mem = dma_alloc_coherent(&dev->pci_dev->dev, 1009 1010 sizeof(struct nvme_smart_log), ··· 1066 1069 u8 temp_c_cur, temp_c_thresh; 1067 1070 u16 temp_k; 1068 1071 1069 - log_response = kmalloc(LOG_TEMP_PAGE_LENGTH, GFP_KERNEL); 1072 + log_response = kzalloc(LOG_TEMP_PAGE_LENGTH, GFP_KERNEL); 1070 1073 if (log_response == NULL) { 1071 1074 res = -ENOMEM; 1072 1075 goto out_mem; 1073 1076 } 1074 - memset(log_response, 0, LOG_TEMP_PAGE_LENGTH); 1075 1077 1076 1078 mem = dma_alloc_coherent(&dev->pci_dev->dev, 1077 1079 sizeof(struct nvme_smart_log), ··· 1376 1380 blk_desc_offset = mph_size; 1377 1381 mode_pages_offset_1 = blk_desc_offset + blk_desc_len; 1378 1382 1379 - response = kmalloc(resp_size, GFP_KERNEL); 1383 + response = kzalloc(resp_size, GFP_KERNEL); 1380 1384 if (response == NULL) { 1381 1385 res = -ENOMEM; 1382 1386 goto out_mem; 1383 1387 } 1384 - memset(response, 0, resp_size); 1385 1388 1386 1389 res = nvme_trans_fill_mode_parm_hdr(&response[0], mph_size, cdb10, 1387 1390 llbaa, mode_data_length, blk_desc_len); ··· 2475 2480 } 2476 2481 id_ns = mem; 2477 2482 2478 - response = kmalloc(resp_size, GFP_KERNEL); 2483 + response = kzalloc(resp_size, GFP_KERNEL); 2479 2484 if (response == NULL) { 2480 2485 res = -ENOMEM; 2481 2486 goto out_dma; 2482 2487 } 2483 - memset(response, 0, resp_size); 2484 2488 nvme_trans_fill_read_cap(response, id_ns, cdb16); 2485 2489 2486 2490 xfer_len = min(alloc_len, resp_size); ··· 2548 2554 goto out_dma; 2549 2555 } 2550 2556 2551 - response = kmalloc(resp_size, GFP_KERNEL); 2557 + response = kzalloc(resp_size, GFP_KERNEL); 2552 2558 if (response == NULL) { 2553 2559 res = -ENOMEM; 2554 2560 goto out_dma; 2555 2561 } 2556 - memset(response, 0, resp_size); 2557 2562 2558 2563 /* The first LUN ID will always be 0 per the SAM spec */ 2559 2564 for (lun_id = 0; lun_id < le32_to_cpu(id_ctrl->nn); lun_id++) { ··· 2593 2600 2594 2601 resp_size = ((desc_format) ? (DESC_FMT_SENSE_DATA_SIZE) : 2595 2602 (FIXED_FMT_SENSE_DATA_SIZE)); 2596 - response = kmalloc(resp_size, GFP_KERNEL); 2603 + response = kzalloc(resp_size, GFP_KERNEL); 2597 2604 if (response == NULL) { 2598 2605 res = -ENOMEM; 2599 2606 goto out; 2600 2607 } 2601 - memset(response, 0, resp_size); 2602 2608 2603 2609 if (desc_format == DESCRIPTOR_FORMAT_SENSE_DATA_TYPE) { 2604 2610 /* Descriptor Format Sense Data */
+9 -457
include/linux/nvme.h
··· 1 1 /* 2 2 * Definitions for the NVM Express interface 3 - * Copyright (c) 2011, Intel Corporation. 3 + * Copyright (c) 2011-2013, Intel Corporation. 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify it 6 6 * under the terms and conditions of the GNU General Public License, ··· 19 19 #ifndef _LINUX_NVME_H 20 20 #define _LINUX_NVME_H 21 21 22 - #include <linux/types.h> 22 + #include <uapi/linux/nvme.h> 23 + #include <linux/pci.h> 24 + #include <linux/miscdevice.h> 25 + #include <linux/kref.h> 23 26 24 27 struct nvme_bar { 25 28 __u64 cap; /* Controller Capabilities */ ··· 53 50 NVME_CC_SHN_NONE = 0 << 14, 54 51 NVME_CC_SHN_NORMAL = 1 << 14, 55 52 NVME_CC_SHN_ABRUPT = 2 << 14, 53 + NVME_CC_SHN_MASK = 3 << 14, 56 54 NVME_CC_IOSQES = 6 << 16, 57 55 NVME_CC_IOCQES = 4 << 20, 58 56 NVME_CSTS_RDY = 1 << 0, ··· 61 57 NVME_CSTS_SHST_NORMAL = 0 << 2, 62 58 NVME_CSTS_SHST_OCCUR = 1 << 2, 63 59 NVME_CSTS_SHST_CMPLT = 2 << 2, 64 - }; 65 - 66 - struct nvme_id_power_state { 67 - __le16 max_power; /* centiwatts */ 68 - __u16 rsvd2; 69 - __le32 entry_lat; /* microseconds */ 70 - __le32 exit_lat; /* microseconds */ 71 - __u8 read_tput; 72 - __u8 read_lat; 73 - __u8 write_tput; 74 - __u8 write_lat; 75 - __u8 rsvd16[16]; 60 + NVME_CSTS_SHST_MASK = 3 << 2, 76 61 }; 77 62 78 63 #define NVME_VS(major, minor) (major << 16 | minor) 79 - 80 - struct nvme_id_ctrl { 81 - __le16 vid; 82 - __le16 ssvid; 83 - char sn[20]; 84 - char mn[40]; 85 - char fr[8]; 86 - __u8 rab; 87 - __u8 ieee[3]; 88 - __u8 mic; 89 - __u8 mdts; 90 - __u8 rsvd78[178]; 91 - __le16 oacs; 92 - __u8 acl; 93 - __u8 aerl; 94 - __u8 frmw; 95 - __u8 lpa; 96 - __u8 elpe; 97 - __u8 npss; 98 - __u8 rsvd264[248]; 99 - __u8 sqes; 100 - __u8 cqes; 101 - __u8 rsvd514[2]; 102 - __le32 nn; 103 - __le16 oncs; 104 - __le16 fuses; 105 - __u8 fna; 106 - __u8 vwc; 107 - __le16 awun; 108 - __le16 awupf; 109 - __u8 rsvd530[1518]; 110 - struct nvme_id_power_state psd[32]; 111 - __u8 vs[1024]; 112 - }; 113 - 114 - enum { 115 - NVME_CTRL_ONCS_COMPARE = 1 << 0, 116 - NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1, 117 - NVME_CTRL_ONCS_DSM = 1 << 2, 118 - }; 119 - 120 - struct nvme_lbaf { 121 - __le16 ms; 122 - __u8 ds; 123 - __u8 rp; 124 - }; 125 - 126 - struct nvme_id_ns { 127 - __le64 nsze; 128 - __le64 ncap; 129 - __le64 nuse; 130 - __u8 nsfeat; 131 - __u8 nlbaf; 132 - __u8 flbas; 133 - __u8 mc; 134 - __u8 dpc; 135 - __u8 dps; 136 - __u8 rsvd30[98]; 137 - struct nvme_lbaf lbaf[16]; 138 - __u8 rsvd192[192]; 139 - __u8 vs[3712]; 140 - }; 141 - 142 - enum { 143 - NVME_NS_FEAT_THIN = 1 << 0, 144 - NVME_LBAF_RP_BEST = 0, 145 - NVME_LBAF_RP_BETTER = 1, 146 - NVME_LBAF_RP_GOOD = 2, 147 - NVME_LBAF_RP_DEGRADED = 3, 148 - }; 149 - 150 - struct nvme_smart_log { 151 - __u8 critical_warning; 152 - __u8 temperature[2]; 153 - __u8 avail_spare; 154 - __u8 spare_thresh; 155 - __u8 percent_used; 156 - __u8 rsvd6[26]; 157 - __u8 data_units_read[16]; 158 - __u8 data_units_written[16]; 159 - __u8 host_reads[16]; 160 - __u8 host_writes[16]; 161 - __u8 ctrl_busy_time[16]; 162 - __u8 power_cycles[16]; 163 - __u8 power_on_hours[16]; 164 - __u8 unsafe_shutdowns[16]; 165 - __u8 media_errors[16]; 166 - __u8 num_err_log_entries[16]; 167 - __u8 rsvd192[320]; 168 - }; 169 - 170 - enum { 171 - NVME_SMART_CRIT_SPARE = 1 << 0, 172 - NVME_SMART_CRIT_TEMPERATURE = 1 << 1, 173 - NVME_SMART_CRIT_RELIABILITY = 1 << 2, 174 - NVME_SMART_CRIT_MEDIA = 1 << 3, 175 - NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4, 176 - }; 177 - 178 - struct nvme_lba_range_type { 179 - __u8 type; 180 - __u8 attributes; 181 - __u8 rsvd2[14]; 182 - __u64 slba; 183 - __u64 nlb; 184 - __u8 guid[16]; 185 - __u8 rsvd48[16]; 186 - }; 187 - 188 - enum { 189 - NVME_LBART_TYPE_FS = 0x01, 190 - NVME_LBART_TYPE_RAID = 0x02, 191 - NVME_LBART_TYPE_CACHE = 0x03, 192 - NVME_LBART_TYPE_SWAP = 0x04, 193 - 194 - NVME_LBART_ATTRIB_TEMP = 1 << 0, 195 - NVME_LBART_ATTRIB_HIDE = 1 << 1, 196 - }; 197 - 198 - /* I/O commands */ 199 - 200 - enum nvme_opcode { 201 - nvme_cmd_flush = 0x00, 202 - nvme_cmd_write = 0x01, 203 - nvme_cmd_read = 0x02, 204 - nvme_cmd_write_uncor = 0x04, 205 - nvme_cmd_compare = 0x05, 206 - nvme_cmd_dsm = 0x09, 207 - }; 208 - 209 - struct nvme_common_command { 210 - __u8 opcode; 211 - __u8 flags; 212 - __u16 command_id; 213 - __le32 nsid; 214 - __le32 cdw2[2]; 215 - __le64 metadata; 216 - __le64 prp1; 217 - __le64 prp2; 218 - __le32 cdw10[6]; 219 - }; 220 - 221 - struct nvme_rw_command { 222 - __u8 opcode; 223 - __u8 flags; 224 - __u16 command_id; 225 - __le32 nsid; 226 - __u64 rsvd2; 227 - __le64 metadata; 228 - __le64 prp1; 229 - __le64 prp2; 230 - __le64 slba; 231 - __le16 length; 232 - __le16 control; 233 - __le32 dsmgmt; 234 - __le32 reftag; 235 - __le16 apptag; 236 - __le16 appmask; 237 - }; 238 - 239 - enum { 240 - NVME_RW_LR = 1 << 15, 241 - NVME_RW_FUA = 1 << 14, 242 - NVME_RW_DSM_FREQ_UNSPEC = 0, 243 - NVME_RW_DSM_FREQ_TYPICAL = 1, 244 - NVME_RW_DSM_FREQ_RARE = 2, 245 - NVME_RW_DSM_FREQ_READS = 3, 246 - NVME_RW_DSM_FREQ_WRITES = 4, 247 - NVME_RW_DSM_FREQ_RW = 5, 248 - NVME_RW_DSM_FREQ_ONCE = 6, 249 - NVME_RW_DSM_FREQ_PREFETCH = 7, 250 - NVME_RW_DSM_FREQ_TEMP = 8, 251 - NVME_RW_DSM_LATENCY_NONE = 0 << 4, 252 - NVME_RW_DSM_LATENCY_IDLE = 1 << 4, 253 - NVME_RW_DSM_LATENCY_NORM = 2 << 4, 254 - NVME_RW_DSM_LATENCY_LOW = 3 << 4, 255 - NVME_RW_DSM_SEQ_REQ = 1 << 6, 256 - NVME_RW_DSM_COMPRESSED = 1 << 7, 257 - }; 258 - 259 - struct nvme_dsm_cmd { 260 - __u8 opcode; 261 - __u8 flags; 262 - __u16 command_id; 263 - __le32 nsid; 264 - __u64 rsvd2[2]; 265 - __le64 prp1; 266 - __le64 prp2; 267 - __le32 nr; 268 - __le32 attributes; 269 - __u32 rsvd12[4]; 270 - }; 271 - 272 - enum { 273 - NVME_DSMGMT_IDR = 1 << 0, 274 - NVME_DSMGMT_IDW = 1 << 1, 275 - NVME_DSMGMT_AD = 1 << 2, 276 - }; 277 - 278 - struct nvme_dsm_range { 279 - __le32 cattr; 280 - __le32 nlb; 281 - __le64 slba; 282 - }; 283 - 284 - /* Admin commands */ 285 - 286 - enum nvme_admin_opcode { 287 - nvme_admin_delete_sq = 0x00, 288 - nvme_admin_create_sq = 0x01, 289 - nvme_admin_get_log_page = 0x02, 290 - nvme_admin_delete_cq = 0x04, 291 - nvme_admin_create_cq = 0x05, 292 - nvme_admin_identify = 0x06, 293 - nvme_admin_abort_cmd = 0x08, 294 - nvme_admin_set_features = 0x09, 295 - nvme_admin_get_features = 0x0a, 296 - nvme_admin_async_event = 0x0c, 297 - nvme_admin_activate_fw = 0x10, 298 - nvme_admin_download_fw = 0x11, 299 - nvme_admin_format_nvm = 0x80, 300 - nvme_admin_security_send = 0x81, 301 - nvme_admin_security_recv = 0x82, 302 - }; 303 - 304 - enum { 305 - NVME_QUEUE_PHYS_CONTIG = (1 << 0), 306 - NVME_CQ_IRQ_ENABLED = (1 << 1), 307 - NVME_SQ_PRIO_URGENT = (0 << 1), 308 - NVME_SQ_PRIO_HIGH = (1 << 1), 309 - NVME_SQ_PRIO_MEDIUM = (2 << 1), 310 - NVME_SQ_PRIO_LOW = (3 << 1), 311 - NVME_FEAT_ARBITRATION = 0x01, 312 - NVME_FEAT_POWER_MGMT = 0x02, 313 - NVME_FEAT_LBA_RANGE = 0x03, 314 - NVME_FEAT_TEMP_THRESH = 0x04, 315 - NVME_FEAT_ERR_RECOVERY = 0x05, 316 - NVME_FEAT_VOLATILE_WC = 0x06, 317 - NVME_FEAT_NUM_QUEUES = 0x07, 318 - NVME_FEAT_IRQ_COALESCE = 0x08, 319 - NVME_FEAT_IRQ_CONFIG = 0x09, 320 - NVME_FEAT_WRITE_ATOMIC = 0x0a, 321 - NVME_FEAT_ASYNC_EVENT = 0x0b, 322 - NVME_FEAT_SW_PROGRESS = 0x0c, 323 - NVME_FWACT_REPL = (0 << 3), 324 - NVME_FWACT_REPL_ACTV = (1 << 3), 325 - NVME_FWACT_ACTV = (2 << 3), 326 - }; 327 - 328 - struct nvme_identify { 329 - __u8 opcode; 330 - __u8 flags; 331 - __u16 command_id; 332 - __le32 nsid; 333 - __u64 rsvd2[2]; 334 - __le64 prp1; 335 - __le64 prp2; 336 - __le32 cns; 337 - __u32 rsvd11[5]; 338 - }; 339 - 340 - struct nvme_features { 341 - __u8 opcode; 342 - __u8 flags; 343 - __u16 command_id; 344 - __le32 nsid; 345 - __u64 rsvd2[2]; 346 - __le64 prp1; 347 - __le64 prp2; 348 - __le32 fid; 349 - __le32 dword11; 350 - __u32 rsvd12[4]; 351 - }; 352 - 353 - struct nvme_create_cq { 354 - __u8 opcode; 355 - __u8 flags; 356 - __u16 command_id; 357 - __u32 rsvd1[5]; 358 - __le64 prp1; 359 - __u64 rsvd8; 360 - __le16 cqid; 361 - __le16 qsize; 362 - __le16 cq_flags; 363 - __le16 irq_vector; 364 - __u32 rsvd12[4]; 365 - }; 366 - 367 - struct nvme_create_sq { 368 - __u8 opcode; 369 - __u8 flags; 370 - __u16 command_id; 371 - __u32 rsvd1[5]; 372 - __le64 prp1; 373 - __u64 rsvd8; 374 - __le16 sqid; 375 - __le16 qsize; 376 - __le16 sq_flags; 377 - __le16 cqid; 378 - __u32 rsvd12[4]; 379 - }; 380 - 381 - struct nvme_delete_queue { 382 - __u8 opcode; 383 - __u8 flags; 384 - __u16 command_id; 385 - __u32 rsvd1[9]; 386 - __le16 qid; 387 - __u16 rsvd10; 388 - __u32 rsvd11[5]; 389 - }; 390 - 391 - struct nvme_download_firmware { 392 - __u8 opcode; 393 - __u8 flags; 394 - __u16 command_id; 395 - __u32 rsvd1[5]; 396 - __le64 prp1; 397 - __le64 prp2; 398 - __le32 numd; 399 - __le32 offset; 400 - __u32 rsvd12[4]; 401 - }; 402 - 403 - struct nvme_format_cmd { 404 - __u8 opcode; 405 - __u8 flags; 406 - __u16 command_id; 407 - __le32 nsid; 408 - __u64 rsvd2[4]; 409 - __le32 cdw10; 410 - __u32 rsvd11[5]; 411 - }; 412 - 413 - struct nvme_command { 414 - union { 415 - struct nvme_common_command common; 416 - struct nvme_rw_command rw; 417 - struct nvme_identify identify; 418 - struct nvme_features features; 419 - struct nvme_create_cq create_cq; 420 - struct nvme_create_sq create_sq; 421 - struct nvme_delete_queue delete_queue; 422 - struct nvme_download_firmware dlfw; 423 - struct nvme_format_cmd format; 424 - struct nvme_dsm_cmd dsm; 425 - }; 426 - }; 427 - 428 - enum { 429 - NVME_SC_SUCCESS = 0x0, 430 - NVME_SC_INVALID_OPCODE = 0x1, 431 - NVME_SC_INVALID_FIELD = 0x2, 432 - NVME_SC_CMDID_CONFLICT = 0x3, 433 - NVME_SC_DATA_XFER_ERROR = 0x4, 434 - NVME_SC_POWER_LOSS = 0x5, 435 - NVME_SC_INTERNAL = 0x6, 436 - NVME_SC_ABORT_REQ = 0x7, 437 - NVME_SC_ABORT_QUEUE = 0x8, 438 - NVME_SC_FUSED_FAIL = 0x9, 439 - NVME_SC_FUSED_MISSING = 0xa, 440 - NVME_SC_INVALID_NS = 0xb, 441 - NVME_SC_CMD_SEQ_ERROR = 0xc, 442 - NVME_SC_LBA_RANGE = 0x80, 443 - NVME_SC_CAP_EXCEEDED = 0x81, 444 - NVME_SC_NS_NOT_READY = 0x82, 445 - NVME_SC_CQ_INVALID = 0x100, 446 - NVME_SC_QID_INVALID = 0x101, 447 - NVME_SC_QUEUE_SIZE = 0x102, 448 - NVME_SC_ABORT_LIMIT = 0x103, 449 - NVME_SC_ABORT_MISSING = 0x104, 450 - NVME_SC_ASYNC_LIMIT = 0x105, 451 - NVME_SC_FIRMWARE_SLOT = 0x106, 452 - NVME_SC_FIRMWARE_IMAGE = 0x107, 453 - NVME_SC_INVALID_VECTOR = 0x108, 454 - NVME_SC_INVALID_LOG_PAGE = 0x109, 455 - NVME_SC_INVALID_FORMAT = 0x10a, 456 - NVME_SC_BAD_ATTRIBUTES = 0x180, 457 - NVME_SC_WRITE_FAULT = 0x280, 458 - NVME_SC_READ_ERROR = 0x281, 459 - NVME_SC_GUARD_CHECK = 0x282, 460 - NVME_SC_APPTAG_CHECK = 0x283, 461 - NVME_SC_REFTAG_CHECK = 0x284, 462 - NVME_SC_COMPARE_FAILED = 0x285, 463 - NVME_SC_ACCESS_DENIED = 0x286, 464 - }; 465 - 466 - struct nvme_completion { 467 - __le32 result; /* Used by admin commands to return data */ 468 - __u32 rsvd; 469 - __le16 sq_head; /* how much of this queue may be reclaimed */ 470 - __le16 sq_id; /* submission queue that generated this entry */ 471 - __u16 command_id; /* of the command which completed */ 472 - __le16 status; /* did the command fail, and if so, why? */ 473 - }; 474 - 475 - struct nvme_user_io { 476 - __u8 opcode; 477 - __u8 flags; 478 - __u16 control; 479 - __u16 nblocks; 480 - __u16 rsvd; 481 - __u64 metadata; 482 - __u64 addr; 483 - __u64 slba; 484 - __u32 dsmgmt; 485 - __u32 reftag; 486 - __u16 apptag; 487 - __u16 appmask; 488 - }; 489 - 490 - struct nvme_admin_cmd { 491 - __u8 opcode; 492 - __u8 flags; 493 - __u16 rsvd1; 494 - __u32 nsid; 495 - __u32 cdw2; 496 - __u32 cdw3; 497 - __u64 metadata; 498 - __u64 addr; 499 - __u32 metadata_len; 500 - __u32 data_len; 501 - __u32 cdw10; 502 - __u32 cdw11; 503 - __u32 cdw12; 504 - __u32 cdw13; 505 - __u32 cdw14; 506 - __u32 cdw15; 507 - __u32 timeout_ms; 508 - __u32 result; 509 - }; 510 - 511 - #define NVME_IOCTL_ID _IO('N', 0x40) 512 - #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd) 513 - #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io) 514 - 515 - #ifdef __KERNEL__ 516 - #include <linux/pci.h> 517 - #include <linux/miscdevice.h> 518 - #include <linux/kref.h> 519 64 520 65 #define NVME_IO_TIMEOUT (5 * HZ) 521 66 ··· 106 553 struct request_queue *queue; 107 554 struct gendisk *disk; 108 555 109 - int ns_id; 556 + unsigned ns_id; 110 557 int lba_shift; 111 558 int ms; 112 559 u64 mode_select_num_blocks; ··· 125 572 int offset; /* Of PRP list */ 126 573 int nents; /* Used in scatterlist */ 127 574 int length; /* Of data, in bytes */ 575 + unsigned long start_time; 128 576 dma_addr_t first_dma; 129 577 struct scatterlist sg[0]; 130 578 }; ··· 166 612 167 613 int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr); 168 614 int nvme_sg_get_version_num(int __user *ip); 169 - 170 - #endif 171 615 172 616 #endif /* _LINUX_NVME_H */
+1
include/uapi/linux/Kbuild
··· 284 284 header-y += nfsacl.h 285 285 header-y += nl80211.h 286 286 header-y += nubus.h 287 + header-y += nvme.h 287 288 header-y += nvram.h 288 289 header-y += omap3isp.h 289 290 header-y += omapfb.h
+477
include/uapi/linux/nvme.h
··· 1 + /* 2 + * Definitions for the NVM Express interface 3 + * Copyright (c) 2011-2013, Intel Corporation. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope it will be useful, but WITHOUT 10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 + * more details. 13 + * 14 + * You should have received a copy of the GNU General Public License along with 15 + * this program; if not, write to the Free Software Foundation, Inc., 16 + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 17 + */ 18 + 19 + #ifndef _UAPI_LINUX_NVME_H 20 + #define _UAPI_LINUX_NVME_H 21 + 22 + #include <linux/types.h> 23 + 24 + struct nvme_id_power_state { 25 + __le16 max_power; /* centiwatts */ 26 + __u8 rsvd2; 27 + __u8 flags; 28 + __le32 entry_lat; /* microseconds */ 29 + __le32 exit_lat; /* microseconds */ 30 + __u8 read_tput; 31 + __u8 read_lat; 32 + __u8 write_tput; 33 + __u8 write_lat; 34 + __u8 rsvd16[16]; 35 + }; 36 + 37 + enum { 38 + NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0, 39 + NVME_PS_FLAGS_NON_OP_STATE = 1 << 1, 40 + }; 41 + 42 + struct nvme_id_ctrl { 43 + __le16 vid; 44 + __le16 ssvid; 45 + char sn[20]; 46 + char mn[40]; 47 + char fr[8]; 48 + __u8 rab; 49 + __u8 ieee[3]; 50 + __u8 mic; 51 + __u8 mdts; 52 + __u8 rsvd78[178]; 53 + __le16 oacs; 54 + __u8 acl; 55 + __u8 aerl; 56 + __u8 frmw; 57 + __u8 lpa; 58 + __u8 elpe; 59 + __u8 npss; 60 + __u8 rsvd264[248]; 61 + __u8 sqes; 62 + __u8 cqes; 63 + __u8 rsvd514[2]; 64 + __le32 nn; 65 + __le16 oncs; 66 + __le16 fuses; 67 + __u8 fna; 68 + __u8 vwc; 69 + __le16 awun; 70 + __le16 awupf; 71 + __u8 rsvd530[1518]; 72 + struct nvme_id_power_state psd[32]; 73 + __u8 vs[1024]; 74 + }; 75 + 76 + enum { 77 + NVME_CTRL_ONCS_COMPARE = 1 << 0, 78 + NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1, 79 + NVME_CTRL_ONCS_DSM = 1 << 2, 80 + }; 81 + 82 + struct nvme_lbaf { 83 + __le16 ms; 84 + __u8 ds; 85 + __u8 rp; 86 + }; 87 + 88 + struct nvme_id_ns { 89 + __le64 nsze; 90 + __le64 ncap; 91 + __le64 nuse; 92 + __u8 nsfeat; 93 + __u8 nlbaf; 94 + __u8 flbas; 95 + __u8 mc; 96 + __u8 dpc; 97 + __u8 dps; 98 + __u8 rsvd30[98]; 99 + struct nvme_lbaf lbaf[16]; 100 + __u8 rsvd192[192]; 101 + __u8 vs[3712]; 102 + }; 103 + 104 + enum { 105 + NVME_NS_FEAT_THIN = 1 << 0, 106 + NVME_LBAF_RP_BEST = 0, 107 + NVME_LBAF_RP_BETTER = 1, 108 + NVME_LBAF_RP_GOOD = 2, 109 + NVME_LBAF_RP_DEGRADED = 3, 110 + }; 111 + 112 + struct nvme_smart_log { 113 + __u8 critical_warning; 114 + __u8 temperature[2]; 115 + __u8 avail_spare; 116 + __u8 spare_thresh; 117 + __u8 percent_used; 118 + __u8 rsvd6[26]; 119 + __u8 data_units_read[16]; 120 + __u8 data_units_written[16]; 121 + __u8 host_reads[16]; 122 + __u8 host_writes[16]; 123 + __u8 ctrl_busy_time[16]; 124 + __u8 power_cycles[16]; 125 + __u8 power_on_hours[16]; 126 + __u8 unsafe_shutdowns[16]; 127 + __u8 media_errors[16]; 128 + __u8 num_err_log_entries[16]; 129 + __u8 rsvd192[320]; 130 + }; 131 + 132 + enum { 133 + NVME_SMART_CRIT_SPARE = 1 << 0, 134 + NVME_SMART_CRIT_TEMPERATURE = 1 << 1, 135 + NVME_SMART_CRIT_RELIABILITY = 1 << 2, 136 + NVME_SMART_CRIT_MEDIA = 1 << 3, 137 + NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4, 138 + }; 139 + 140 + struct nvme_lba_range_type { 141 + __u8 type; 142 + __u8 attributes; 143 + __u8 rsvd2[14]; 144 + __u64 slba; 145 + __u64 nlb; 146 + __u8 guid[16]; 147 + __u8 rsvd48[16]; 148 + }; 149 + 150 + enum { 151 + NVME_LBART_TYPE_FS = 0x01, 152 + NVME_LBART_TYPE_RAID = 0x02, 153 + NVME_LBART_TYPE_CACHE = 0x03, 154 + NVME_LBART_TYPE_SWAP = 0x04, 155 + 156 + NVME_LBART_ATTRIB_TEMP = 1 << 0, 157 + NVME_LBART_ATTRIB_HIDE = 1 << 1, 158 + }; 159 + 160 + /* I/O commands */ 161 + 162 + enum nvme_opcode { 163 + nvme_cmd_flush = 0x00, 164 + nvme_cmd_write = 0x01, 165 + nvme_cmd_read = 0x02, 166 + nvme_cmd_write_uncor = 0x04, 167 + nvme_cmd_compare = 0x05, 168 + nvme_cmd_dsm = 0x09, 169 + }; 170 + 171 + struct nvme_common_command { 172 + __u8 opcode; 173 + __u8 flags; 174 + __u16 command_id; 175 + __le32 nsid; 176 + __le32 cdw2[2]; 177 + __le64 metadata; 178 + __le64 prp1; 179 + __le64 prp2; 180 + __le32 cdw10[6]; 181 + }; 182 + 183 + struct nvme_rw_command { 184 + __u8 opcode; 185 + __u8 flags; 186 + __u16 command_id; 187 + __le32 nsid; 188 + __u64 rsvd2; 189 + __le64 metadata; 190 + __le64 prp1; 191 + __le64 prp2; 192 + __le64 slba; 193 + __le16 length; 194 + __le16 control; 195 + __le32 dsmgmt; 196 + __le32 reftag; 197 + __le16 apptag; 198 + __le16 appmask; 199 + }; 200 + 201 + enum { 202 + NVME_RW_LR = 1 << 15, 203 + NVME_RW_FUA = 1 << 14, 204 + NVME_RW_DSM_FREQ_UNSPEC = 0, 205 + NVME_RW_DSM_FREQ_TYPICAL = 1, 206 + NVME_RW_DSM_FREQ_RARE = 2, 207 + NVME_RW_DSM_FREQ_READS = 3, 208 + NVME_RW_DSM_FREQ_WRITES = 4, 209 + NVME_RW_DSM_FREQ_RW = 5, 210 + NVME_RW_DSM_FREQ_ONCE = 6, 211 + NVME_RW_DSM_FREQ_PREFETCH = 7, 212 + NVME_RW_DSM_FREQ_TEMP = 8, 213 + NVME_RW_DSM_LATENCY_NONE = 0 << 4, 214 + NVME_RW_DSM_LATENCY_IDLE = 1 << 4, 215 + NVME_RW_DSM_LATENCY_NORM = 2 << 4, 216 + NVME_RW_DSM_LATENCY_LOW = 3 << 4, 217 + NVME_RW_DSM_SEQ_REQ = 1 << 6, 218 + NVME_RW_DSM_COMPRESSED = 1 << 7, 219 + }; 220 + 221 + struct nvme_dsm_cmd { 222 + __u8 opcode; 223 + __u8 flags; 224 + __u16 command_id; 225 + __le32 nsid; 226 + __u64 rsvd2[2]; 227 + __le64 prp1; 228 + __le64 prp2; 229 + __le32 nr; 230 + __le32 attributes; 231 + __u32 rsvd12[4]; 232 + }; 233 + 234 + enum { 235 + NVME_DSMGMT_IDR = 1 << 0, 236 + NVME_DSMGMT_IDW = 1 << 1, 237 + NVME_DSMGMT_AD = 1 << 2, 238 + }; 239 + 240 + struct nvme_dsm_range { 241 + __le32 cattr; 242 + __le32 nlb; 243 + __le64 slba; 244 + }; 245 + 246 + /* Admin commands */ 247 + 248 + enum nvme_admin_opcode { 249 + nvme_admin_delete_sq = 0x00, 250 + nvme_admin_create_sq = 0x01, 251 + nvme_admin_get_log_page = 0x02, 252 + nvme_admin_delete_cq = 0x04, 253 + nvme_admin_create_cq = 0x05, 254 + nvme_admin_identify = 0x06, 255 + nvme_admin_abort_cmd = 0x08, 256 + nvme_admin_set_features = 0x09, 257 + nvme_admin_get_features = 0x0a, 258 + nvme_admin_async_event = 0x0c, 259 + nvme_admin_activate_fw = 0x10, 260 + nvme_admin_download_fw = 0x11, 261 + nvme_admin_format_nvm = 0x80, 262 + nvme_admin_security_send = 0x81, 263 + nvme_admin_security_recv = 0x82, 264 + }; 265 + 266 + enum { 267 + NVME_QUEUE_PHYS_CONTIG = (1 << 0), 268 + NVME_CQ_IRQ_ENABLED = (1 << 1), 269 + NVME_SQ_PRIO_URGENT = (0 << 1), 270 + NVME_SQ_PRIO_HIGH = (1 << 1), 271 + NVME_SQ_PRIO_MEDIUM = (2 << 1), 272 + NVME_SQ_PRIO_LOW = (3 << 1), 273 + NVME_FEAT_ARBITRATION = 0x01, 274 + NVME_FEAT_POWER_MGMT = 0x02, 275 + NVME_FEAT_LBA_RANGE = 0x03, 276 + NVME_FEAT_TEMP_THRESH = 0x04, 277 + NVME_FEAT_ERR_RECOVERY = 0x05, 278 + NVME_FEAT_VOLATILE_WC = 0x06, 279 + NVME_FEAT_NUM_QUEUES = 0x07, 280 + NVME_FEAT_IRQ_COALESCE = 0x08, 281 + NVME_FEAT_IRQ_CONFIG = 0x09, 282 + NVME_FEAT_WRITE_ATOMIC = 0x0a, 283 + NVME_FEAT_ASYNC_EVENT = 0x0b, 284 + NVME_FEAT_SW_PROGRESS = 0x0c, 285 + NVME_FWACT_REPL = (0 << 3), 286 + NVME_FWACT_REPL_ACTV = (1 << 3), 287 + NVME_FWACT_ACTV = (2 << 3), 288 + }; 289 + 290 + struct nvme_identify { 291 + __u8 opcode; 292 + __u8 flags; 293 + __u16 command_id; 294 + __le32 nsid; 295 + __u64 rsvd2[2]; 296 + __le64 prp1; 297 + __le64 prp2; 298 + __le32 cns; 299 + __u32 rsvd11[5]; 300 + }; 301 + 302 + struct nvme_features { 303 + __u8 opcode; 304 + __u8 flags; 305 + __u16 command_id; 306 + __le32 nsid; 307 + __u64 rsvd2[2]; 308 + __le64 prp1; 309 + __le64 prp2; 310 + __le32 fid; 311 + __le32 dword11; 312 + __u32 rsvd12[4]; 313 + }; 314 + 315 + struct nvme_create_cq { 316 + __u8 opcode; 317 + __u8 flags; 318 + __u16 command_id; 319 + __u32 rsvd1[5]; 320 + __le64 prp1; 321 + __u64 rsvd8; 322 + __le16 cqid; 323 + __le16 qsize; 324 + __le16 cq_flags; 325 + __le16 irq_vector; 326 + __u32 rsvd12[4]; 327 + }; 328 + 329 + struct nvme_create_sq { 330 + __u8 opcode; 331 + __u8 flags; 332 + __u16 command_id; 333 + __u32 rsvd1[5]; 334 + __le64 prp1; 335 + __u64 rsvd8; 336 + __le16 sqid; 337 + __le16 qsize; 338 + __le16 sq_flags; 339 + __le16 cqid; 340 + __u32 rsvd12[4]; 341 + }; 342 + 343 + struct nvme_delete_queue { 344 + __u8 opcode; 345 + __u8 flags; 346 + __u16 command_id; 347 + __u32 rsvd1[9]; 348 + __le16 qid; 349 + __u16 rsvd10; 350 + __u32 rsvd11[5]; 351 + }; 352 + 353 + struct nvme_download_firmware { 354 + __u8 opcode; 355 + __u8 flags; 356 + __u16 command_id; 357 + __u32 rsvd1[5]; 358 + __le64 prp1; 359 + __le64 prp2; 360 + __le32 numd; 361 + __le32 offset; 362 + __u32 rsvd12[4]; 363 + }; 364 + 365 + struct nvme_format_cmd { 366 + __u8 opcode; 367 + __u8 flags; 368 + __u16 command_id; 369 + __le32 nsid; 370 + __u64 rsvd2[4]; 371 + __le32 cdw10; 372 + __u32 rsvd11[5]; 373 + }; 374 + 375 + struct nvme_command { 376 + union { 377 + struct nvme_common_command common; 378 + struct nvme_rw_command rw; 379 + struct nvme_identify identify; 380 + struct nvme_features features; 381 + struct nvme_create_cq create_cq; 382 + struct nvme_create_sq create_sq; 383 + struct nvme_delete_queue delete_queue; 384 + struct nvme_download_firmware dlfw; 385 + struct nvme_format_cmd format; 386 + struct nvme_dsm_cmd dsm; 387 + }; 388 + }; 389 + 390 + enum { 391 + NVME_SC_SUCCESS = 0x0, 392 + NVME_SC_INVALID_OPCODE = 0x1, 393 + NVME_SC_INVALID_FIELD = 0x2, 394 + NVME_SC_CMDID_CONFLICT = 0x3, 395 + NVME_SC_DATA_XFER_ERROR = 0x4, 396 + NVME_SC_POWER_LOSS = 0x5, 397 + NVME_SC_INTERNAL = 0x6, 398 + NVME_SC_ABORT_REQ = 0x7, 399 + NVME_SC_ABORT_QUEUE = 0x8, 400 + NVME_SC_FUSED_FAIL = 0x9, 401 + NVME_SC_FUSED_MISSING = 0xa, 402 + NVME_SC_INVALID_NS = 0xb, 403 + NVME_SC_CMD_SEQ_ERROR = 0xc, 404 + NVME_SC_LBA_RANGE = 0x80, 405 + NVME_SC_CAP_EXCEEDED = 0x81, 406 + NVME_SC_NS_NOT_READY = 0x82, 407 + NVME_SC_CQ_INVALID = 0x100, 408 + NVME_SC_QID_INVALID = 0x101, 409 + NVME_SC_QUEUE_SIZE = 0x102, 410 + NVME_SC_ABORT_LIMIT = 0x103, 411 + NVME_SC_ABORT_MISSING = 0x104, 412 + NVME_SC_ASYNC_LIMIT = 0x105, 413 + NVME_SC_FIRMWARE_SLOT = 0x106, 414 + NVME_SC_FIRMWARE_IMAGE = 0x107, 415 + NVME_SC_INVALID_VECTOR = 0x108, 416 + NVME_SC_INVALID_LOG_PAGE = 0x109, 417 + NVME_SC_INVALID_FORMAT = 0x10a, 418 + NVME_SC_BAD_ATTRIBUTES = 0x180, 419 + NVME_SC_WRITE_FAULT = 0x280, 420 + NVME_SC_READ_ERROR = 0x281, 421 + NVME_SC_GUARD_CHECK = 0x282, 422 + NVME_SC_APPTAG_CHECK = 0x283, 423 + NVME_SC_REFTAG_CHECK = 0x284, 424 + NVME_SC_COMPARE_FAILED = 0x285, 425 + NVME_SC_ACCESS_DENIED = 0x286, 426 + }; 427 + 428 + struct nvme_completion { 429 + __le32 result; /* Used by admin commands to return data */ 430 + __u32 rsvd; 431 + __le16 sq_head; /* how much of this queue may be reclaimed */ 432 + __le16 sq_id; /* submission queue that generated this entry */ 433 + __u16 command_id; /* of the command which completed */ 434 + __le16 status; /* did the command fail, and if so, why? */ 435 + }; 436 + 437 + struct nvme_user_io { 438 + __u8 opcode; 439 + __u8 flags; 440 + __u16 control; 441 + __u16 nblocks; 442 + __u16 rsvd; 443 + __u64 metadata; 444 + __u64 addr; 445 + __u64 slba; 446 + __u32 dsmgmt; 447 + __u32 reftag; 448 + __u16 apptag; 449 + __u16 appmask; 450 + }; 451 + 452 + struct nvme_admin_cmd { 453 + __u8 opcode; 454 + __u8 flags; 455 + __u16 rsvd1; 456 + __u32 nsid; 457 + __u32 cdw2; 458 + __u32 cdw3; 459 + __u64 metadata; 460 + __u64 addr; 461 + __u32 metadata_len; 462 + __u32 data_len; 463 + __u32 cdw10; 464 + __u32 cdw11; 465 + __u32 cdw12; 466 + __u32 cdw13; 467 + __u32 cdw14; 468 + __u32 cdw15; 469 + __u32 timeout_ms; 470 + __u32 result; 471 + }; 472 + 473 + #define NVME_IOCTL_ID _IO('N', 0x40) 474 + #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd) 475 + #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io) 476 + 477 + #endif /* _UAPI_LINUX_NVME_H */