aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm/core.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-07 17:42:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-07 17:42:05 -0400
commit513a4befae06c4469abfb836e8f71977de58c636 (patch)
tree18cc7d0b01a7fd2352de734e99a4ca5c29ad5fac /drivers/lightnvm/core.c
parent87840a2b7e048018d18d60bdac5c09224de85370 (diff)
parent997198ba1ed691c09457120576c27dbd953d0557 (diff)
Merge branch 'for-4.9/block' of git://git.kernel.dk/linux-block
Pull block layer updates from Jens Axboe: "This is the main pull request for block layer changes in 4.9. As mentioned at the last merge window, I've changed things up and now do just one branch for core block layer changes, and driver changes. This avoids dependencies between the two branches. Outside of this main pull request, there are two topical branches coming as well. This pull request contains: - A set of fixes, and a conversion to blk-mq, of nbd. From Josef. - Set of fixes and updates for lightnvm from Matias, Simon, and Arnd. Followup dependency fix from Geert. - General fixes from Bart, Baoyou, Guoqing, and Linus W. - CFQ async write starvation fix from Glauber. - Add supprot for delayed kick of the requeue list, from Mike. - Pull out the scalable bitmap code from blk-mq-tag.c and make it generally available under the name of sbitmap. Only blk-mq-tag uses it for now, but the blk-mq scheduling bits will use it as well. From Omar. - bdev thaw error progagation from Pierre. - Improve the blk polling statistics, and allow the user to clear them. From Stephen. - Set of minor cleanups from Christoph in block/blk-mq. - Set of cleanups and optimizations from me for block/blk-mq. - Various nvme/nvmet/nvmeof fixes from the various folks" * 'for-4.9/block' of git://git.kernel.dk/linux-block: (54 commits) fs/block_dev.c: return the right error in thaw_bdev() nvme: Pass pointers, not dma addresses, to nvme_get/set_features() nvme/scsi: Remove power management support nvmet: Make dsm number of ranges zero based nvmet: Use direct IO for writes admin-cmd: Added smart-log command support. nvme-fabrics: Add host_traddr options field to host infrastructure nvme-fabrics: revise host transport option descriptions nvme-fabrics: rework nvmf_get_address() for variable options nbd: use BLK_MQ_F_BLOCKING blkcg: Annotate blkg_hint correctly cfq: fix starvation of asynchronous writes blk-mq: add flag for drivers wanting blocking ->queue_rq() blk-mq: remove non-blocking pass in blk_mq_map_request blk-mq: get rid of manual run of queue with __blk_mq_run_hw_queue() block: export bio_free_pages to other modules lightnvm: propagate device_add() error code lightnvm: expose device geometry through sysfs lightnvm: control life of nvm_dev in driver blk-mq: register device instead of disk ...
Diffstat (limited to 'drivers/lightnvm/core.c')
-rw-r--r--drivers/lightnvm/core.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index c784ddcd4405..1cac0f8bc0dc 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -27,6 +27,8 @@
27#include <linux/lightnvm.h> 27#include <linux/lightnvm.h>
28#include <linux/sched/sysctl.h> 28#include <linux/sched/sysctl.h>
29 29
30#include "lightnvm.h"
31
30static LIST_HEAD(nvm_tgt_types); 32static LIST_HEAD(nvm_tgt_types);
31static DECLARE_RWSEM(nvm_tgtt_lock); 33static DECLARE_RWSEM(nvm_tgtt_lock);
32static LIST_HEAD(nvm_mgrs); 34static LIST_HEAD(nvm_mgrs);
@@ -581,6 +583,8 @@ static int nvm_core_init(struct nvm_dev *dev)
581 mutex_init(&dev->mlock); 583 mutex_init(&dev->mlock);
582 spin_lock_init(&dev->lock); 584 spin_lock_init(&dev->lock);
583 585
586 blk_queue_logical_block_size(dev->q, dev->sec_size);
587
584 return 0; 588 return 0;
585err_fmtype: 589err_fmtype:
586 kfree(dev->lun_map); 590 kfree(dev->lun_map);
@@ -596,15 +600,19 @@ static void nvm_free_mgr(struct nvm_dev *dev)
596 dev->mt = NULL; 600 dev->mt = NULL;
597} 601}
598 602
599static void nvm_free(struct nvm_dev *dev) 603void nvm_free(struct nvm_dev *dev)
600{ 604{
601 if (!dev) 605 if (!dev)
602 return; 606 return;
603 607
604 nvm_free_mgr(dev); 608 nvm_free_mgr(dev);
605 609
610 if (dev->dma_pool)
611 dev->ops->destroy_dma_pool(dev->dma_pool);
612
606 kfree(dev->lptbl); 613 kfree(dev->lptbl);
607 kfree(dev->lun_map); 614 kfree(dev->lun_map);
615 kfree(dev);
608} 616}
609 617
610static int nvm_init(struct nvm_dev *dev) 618static int nvm_init(struct nvm_dev *dev)
@@ -651,30 +659,19 @@ err:
651 659
652static void nvm_exit(struct nvm_dev *dev) 660static void nvm_exit(struct nvm_dev *dev)
653{ 661{
654 if (dev->dma_pool) 662 nvm_sysfs_unregister_dev(dev);
655 dev->ops->destroy_dma_pool(dev->dma_pool); 663}
656 nvm_free(dev);
657 664
658 pr_info("nvm: successfully unloaded\n"); 665struct nvm_dev *nvm_alloc_dev(int node)
666{
667 return kzalloc_node(sizeof(struct nvm_dev), GFP_KERNEL, node);
659} 668}
669EXPORT_SYMBOL(nvm_alloc_dev);
660 670
661int nvm_register(struct request_queue *q, char *disk_name, 671int nvm_register(struct nvm_dev *dev)
662 struct nvm_dev_ops *ops)
663{ 672{
664 struct nvm_dev *dev;
665 int ret; 673 int ret;
666 674
667 if (!ops->identity)
668 return -EINVAL;
669
670 dev = kzalloc(sizeof(struct nvm_dev), GFP_KERNEL);
671 if (!dev)
672 return -ENOMEM;
673
674 dev->q = q;
675 dev->ops = ops;
676 strncpy(dev->name, disk_name, DISK_NAME_LEN);
677
678 ret = nvm_init(dev); 675 ret = nvm_init(dev);
679 if (ret) 676 if (ret)
680 goto err_init; 677 goto err_init;
@@ -694,6 +691,10 @@ int nvm_register(struct request_queue *q, char *disk_name,
694 } 691 }
695 } 692 }
696 693
694 ret = nvm_sysfs_register_dev(dev);
695 if (ret)
696 goto err_ppalist;
697
697 if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { 698 if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) {
698 ret = nvm_get_sysblock(dev, &dev->sb); 699 ret = nvm_get_sysblock(dev, &dev->sb);
699 if (!ret) 700 if (!ret)
@@ -710,31 +711,21 @@ int nvm_register(struct request_queue *q, char *disk_name,
710 up_write(&nvm_lock); 711 up_write(&nvm_lock);
711 712
712 return 0; 713 return 0;
714err_ppalist:
715 dev->ops->destroy_dma_pool(dev->dma_pool);
713err_init: 716err_init:
714 kfree(dev->lun_map); 717 kfree(dev->lun_map);
715 kfree(dev);
716 return ret; 718 return ret;
717} 719}
718EXPORT_SYMBOL(nvm_register); 720EXPORT_SYMBOL(nvm_register);
719 721
720void nvm_unregister(char *disk_name) 722void nvm_unregister(struct nvm_dev *dev)
721{ 723{
722 struct nvm_dev *dev;
723
724 down_write(&nvm_lock); 724 down_write(&nvm_lock);
725 dev = nvm_find_nvm_dev(disk_name);
726 if (!dev) {
727 pr_err("nvm: could not find device %s to unregister\n",
728 disk_name);
729 up_write(&nvm_lock);
730 return;
731 }
732
733 list_del(&dev->devices); 725 list_del(&dev->devices);
734 up_write(&nvm_lock); 726 up_write(&nvm_lock);
735 727
736 nvm_exit(dev); 728 nvm_exit(dev);
737 kfree(dev);
738} 729}
739EXPORT_SYMBOL(nvm_unregister); 730EXPORT_SYMBOL(nvm_unregister);
740 731