aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-11-28 09:42:28 -0500
committerJens Axboe <axboe@fb.com>2015-12-22 11:38:34 -0500
commitadf68f21c15572c68d9fadae618a09cf324b9814 (patch)
tree89f4a63bcf1d106d5442fc7480a50678167ee310
parente7a2a87d5938bbebe1637c82fbde94ea6be3ef78 (diff)
nvme: special case AEN requests
AEN requests are different from other requests in that they don't time out or can easily be cancelled. Because of that we should not use the blk-mq infrastructure but just special case them in the completion path. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/nvme/host/pci.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 6a32a92a9227..0497ff67324c 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -48,6 +48,13 @@
48#define NVME_AQ_DEPTH 256 48#define NVME_AQ_DEPTH 256
49#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command)) 49#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command))
50#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion)) 50#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion))
51
52/*
53 * We handle AEN commands ourselves and don't even let the
54 * block layer know about them.
55 */
56#define NVME_NR_AEN_COMMANDS 1
57#define NVME_AQ_BLKMQ_DEPTH (NVME_AQ_DEPTH - NVME_NR_AEN_COMMANDS)
51 58
52unsigned char admin_timeout = 60; 59unsigned char admin_timeout = 60;
53module_param(admin_timeout, byte, 0644); 60module_param(admin_timeout, byte, 0644);
@@ -355,23 +362,23 @@ static void *cancel_cmd_info(struct nvme_cmd_info *cmd, nvme_completion_fn *fn)
355 return ctx; 362 return ctx;
356} 363}
357 364
358static void async_req_completion(struct nvme_queue *nvmeq, void *ctx, 365static void nvme_complete_async_event(struct nvme_dev *dev,
359 struct nvme_completion *cqe) 366 struct nvme_completion *cqe)
360{ 367{
361 u32 result = le32_to_cpup(&cqe->result); 368 u16 status = le16_to_cpu(cqe->status) >> 1;
362 u16 status = le16_to_cpup(&cqe->status) >> 1; 369 u32 result = le32_to_cpu(cqe->result);
363 370
364 if (status == NVME_SC_SUCCESS || status == NVME_SC_ABORT_REQ) 371 if (status == NVME_SC_SUCCESS || status == NVME_SC_ABORT_REQ)
365 ++nvmeq->dev->ctrl.event_limit; 372 ++dev->ctrl.event_limit;
366 if (status != NVME_SC_SUCCESS) 373 if (status != NVME_SC_SUCCESS)
367 return; 374 return;
368 375
369 switch (result & 0xff07) { 376 switch (result & 0xff07) {
370 case NVME_AER_NOTICE_NS_CHANGED: 377 case NVME_AER_NOTICE_NS_CHANGED:
371 dev_info(nvmeq->q_dmadev, "rescanning\n"); 378 dev_info(dev->dev, "rescanning\n");
372 queue_work(nvme_workq, &nvmeq->dev->scan_work); 379 queue_work(nvme_workq, &dev->scan_work);
373 default: 380 default:
374 dev_warn(nvmeq->q_dmadev, "async event result %08x\n", result); 381 dev_warn(dev->dev, "async event result %08x\n", result);
375 } 382 }
376} 383}
377 384
@@ -404,7 +411,7 @@ static void *nvme_finish_cmd(struct nvme_queue *nvmeq, int tag,
404} 411}
405 412
406/** 413/**
407 * nvme_submit_cmd() - Copy a command into a queue and ring the doorbell 414 * __nvme_submit_cmd() - Copy a command into a queue and ring the doorbell
408 * @nvmeq: The queue to use 415 * @nvmeq: The queue to use
409 * @cmd: The command to send 416 * @cmd: The command to send
410 * 417 *
@@ -853,15 +860,31 @@ static void __nvme_process_cq(struct nvme_queue *nvmeq, unsigned int *tag)
853 void *ctx; 860 void *ctx;
854 nvme_completion_fn fn; 861 nvme_completion_fn fn;
855 struct nvme_completion cqe = nvmeq->cqes[head]; 862 struct nvme_completion cqe = nvmeq->cqes[head];
856 if ((le16_to_cpu(cqe.status) & 1) != phase) 863 u16 status = le16_to_cpu(cqe.status);
864
865 if ((status & 1) != phase)
857 break; 866 break;
858 nvmeq->sq_head = le16_to_cpu(cqe.sq_head); 867 nvmeq->sq_head = le16_to_cpu(cqe.sq_head);
859 if (++head == nvmeq->q_depth) { 868 if (++head == nvmeq->q_depth) {
860 head = 0; 869 head = 0;
861 phase = !phase; 870 phase = !phase;
862 } 871 }
872
863 if (tag && *tag == cqe.command_id) 873 if (tag && *tag == cqe.command_id)
864 *tag = -1; 874 *tag = -1;
875
876 /*
877 * AEN requests are special as they don't time out and can
878 * survive any kind of queue freeze and often don't respond to
879 * aborts. We don't even bother to allocate a struct request
880 * for them but rather special case them here.
881 */
882 if (unlikely(nvmeq->qid == 0 &&
883 cqe.command_id >= NVME_AQ_BLKMQ_DEPTH)) {
884 nvme_complete_async_event(nvmeq->dev, &cqe);
885 continue;
886 }
887
865 ctx = nvme_finish_cmd(nvmeq, cqe.command_id, &fn); 888 ctx = nvme_finish_cmd(nvmeq, cqe.command_id, &fn);
866 fn(nvmeq, ctx, &cqe); 889 fn(nvmeq, ctx, &cqe);
867 } 890 }
@@ -926,29 +949,15 @@ static int nvme_poll(struct blk_mq_hw_ctx *hctx, unsigned int tag)
926 return 0; 949 return 0;
927} 950}
928 951
929static int nvme_submit_async_admin_req(struct nvme_dev *dev) 952static void nvme_submit_async_event(struct nvme_dev *dev)
930{ 953{
931 struct nvme_queue *nvmeq = dev->queues[0];
932 struct nvme_command c; 954 struct nvme_command c;
933 struct nvme_cmd_info *cmd_info;
934 struct request *req;
935
936 req = blk_mq_alloc_request(dev->ctrl.admin_q, WRITE,
937 BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED);
938 if (IS_ERR(req))
939 return PTR_ERR(req);
940
941 req->cmd_flags |= REQ_NO_TIMEOUT;
942 cmd_info = blk_mq_rq_to_pdu(req);
943 nvme_set_info(cmd_info, NULL, async_req_completion);
944 955
945 memset(&c, 0, sizeof(c)); 956 memset(&c, 0, sizeof(c));
946 c.common.opcode = nvme_admin_async_event; 957 c.common.opcode = nvme_admin_async_event;
947 c.common.command_id = req->tag; 958 c.common.command_id = NVME_AQ_BLKMQ_DEPTH + --dev->ctrl.event_limit;
948 959
949 blk_mq_free_request(req); 960 __nvme_submit_cmd(dev->queues[0], &c);
950 __nvme_submit_cmd(nvmeq, &c);
951 return 0;
952} 961}
953 962
954static void async_cmd_info_endio(struct request *req, int error) 963static void async_cmd_info_endio(struct request *req, int error)
@@ -1387,8 +1396,7 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev)
1387 if (!dev->ctrl.admin_q) { 1396 if (!dev->ctrl.admin_q) {
1388 dev->admin_tagset.ops = &nvme_mq_admin_ops; 1397 dev->admin_tagset.ops = &nvme_mq_admin_ops;
1389 dev->admin_tagset.nr_hw_queues = 1; 1398 dev->admin_tagset.nr_hw_queues = 1;
1390 dev->admin_tagset.queue_depth = NVME_AQ_DEPTH; 1399 dev->admin_tagset.queue_depth = NVME_AQ_BLKMQ_DEPTH;
1391 dev->admin_tagset.reserved_tags = 1;
1392 dev->admin_tagset.timeout = ADMIN_TIMEOUT; 1400 dev->admin_tagset.timeout = ADMIN_TIMEOUT;
1393 dev->admin_tagset.numa_node = dev_to_node(dev->dev); 1401 dev->admin_tagset.numa_node = dev_to_node(dev->dev);
1394 dev->admin_tagset.cmd_size = nvme_cmd_size(dev); 1402 dev->admin_tagset.cmd_size = nvme_cmd_size(dev);
@@ -1496,11 +1504,8 @@ static int nvme_kthread(void *data)
1496 spin_lock_irq(&nvmeq->q_lock); 1504 spin_lock_irq(&nvmeq->q_lock);
1497 nvme_process_cq(nvmeq); 1505 nvme_process_cq(nvmeq);
1498 1506
1499 while (i == 0 && dev->ctrl.event_limit > 0) { 1507 while (i == 0 && dev->ctrl.event_limit > 0)
1500 if (nvme_submit_async_admin_req(dev)) 1508 nvme_submit_async_event(dev);
1501 break;
1502 dev->ctrl.event_limit--;
1503 }
1504 spin_unlock_irq(&nvmeq->q_lock); 1509 spin_unlock_irq(&nvmeq->q_lock);
1505 } 1510 }
1506 } 1511 }
@@ -2151,7 +2156,7 @@ static void nvme_reset_work(struct work_struct *work)
2151 if (result) 2156 if (result)
2152 goto free_tags; 2157 goto free_tags;
2153 2158
2154 dev->ctrl.event_limit = 1; 2159 dev->ctrl.event_limit = NVME_NR_AEN_COMMANDS;
2155 2160
2156 result = nvme_dev_list_add(dev); 2161 result = nvme_dev_list_add(dev);
2157 if (result) 2162 if (result)