]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.75/nvme-quirk-add-a-delay-before-checking-for-adapter-readiness.patch
5.0-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.75 / nvme-quirk-add-a-delay-before-checking-for-adapter-readiness.patch
1 From 54adc01055b75ec8769c5a36574c7a0895c0c0b2 Mon Sep 17 00:00:00 2001
2 From: "Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>
3 Date: Tue, 14 Jun 2016 18:22:41 -0300
4 Subject: nvme/quirk: Add a delay before checking for adapter readiness
5
6 From: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
7
8 commit 54adc01055b75ec8769c5a36574c7a0895c0c0b2 upstream.
9
10 When disabling the controller, the specification says the register
11 NVME_REG_CC should be written and then driver needs to wait the
12 adapter to be ready, which is checked by reading another register
13 bit (NVME_CSTS_RDY). There's a timeout validation in this checking,
14 so in case this timeout is reached the driver gives up and removes
15 the adapter from the system.
16
17 After a firmware activation procedure, the PCI_DEVICE(0x1c58, 0x0003)
18 (HGST adapter) end up being removed if we issue a reset_controller,
19 because driver keeps verifying the NVME_REG_CSTS until the timeout is
20 reached. This patch adds a necessary quirk for this adapter, by
21 introducing a delay before nvme_wait_ready(), so the reset procedure
22 is able to be completed. This quirk is needed because just increasing
23 the timeout is not enough in case of this adapter - the driver must
24 wait before start reading NVME_REG_CSTS register on this specific
25 device.
26
27 Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com>
28 Reviewed-by: Christoph Hellwig <hch@lst.de>
29 Signed-off-by: Jens Axboe <axboe@fb.com>
30 [mauricfo: backport to v4.4.70 without nvme quirk handling & nvme_ctrl]
31 Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
32 Tested-by: Narasimhan Vaidyanathan <vnarasimhan@in.ibm.com>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34
35 ---
36 drivers/nvme/host/nvme.h | 7 +++++++
37 drivers/nvme/host/pci.c | 10 ++++++++++
38 2 files changed, 17 insertions(+)
39
40 --- a/drivers/nvme/host/nvme.h
41 +++ b/drivers/nvme/host/nvme.h
42 @@ -27,6 +27,13 @@ enum {
43 NVME_NS_LIGHTNVM = 1,
44 };
45
46 +/* The below value is the specific amount of delay needed before checking
47 + * readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the
48 + * NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
49 + * found empirically.
50 + */
51 +#define NVME_QUIRK_DELAY_AMOUNT 2000
52 +
53 /*
54 * Represents an NVM Express device. Each nvme_dev is a PCI function.
55 */
56 --- a/drivers/nvme/host/pci.c
57 +++ b/drivers/nvme/host/pci.c
58 @@ -1633,10 +1633,20 @@ static int nvme_wait_ready(struct nvme_d
59 */
60 static int nvme_disable_ctrl(struct nvme_dev *dev, u64 cap)
61 {
62 + struct pci_dev *pdev = to_pci_dev(dev->dev);
63 +
64 dev->ctrl_config &= ~NVME_CC_SHN_MASK;
65 dev->ctrl_config &= ~NVME_CC_ENABLE;
66 writel(dev->ctrl_config, &dev->bar->cc);
67
68 + /* Checking for dev->tagset is a trick to avoid sleeping on module
69 + * load, since we only need the quirk on reset_controller. Notice
70 + * that the HGST device needs this delay only in firmware activation
71 + * procedure; unfortunately we have no (easy) way to verify this.
72 + */
73 + if (pdev->vendor == 0x1c58 && pdev->device == 0x0003 && dev->tagset)
74 + msleep(NVME_QUIRK_DELAY_AMOUNT);
75 +
76 return nvme_wait_ready(dev, cap, false);
77 }
78