All of lore.kernel.org
 help / color / mirror / Atom feed
From: benh@kernel.crashing.org (Benjamin Herrenschmidt)
Subject: [PATCH 3/3] nvme: Add support for Apple 2018+ models
Date: Tue, 16 Jul 2019 10:46:49 +1000	[thread overview]
Message-ID: <20190716004649.17799-3-benh@kernel.crashing.org> (raw)
In-Reply-To: <20190716004649.17799-1-benh@kernel.crashing.org>

Based on reverse engineering and original patch by

Paul Pawlowski <paul at mrarm.io>

This adds support for Apple weird implementation of NVME in their
2018 or later machines. It accounts for the twice-as-big SQ entries
for the IO queues, and the fact that only interrupt vector 0 appears
to function properly.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
 drivers/nvme/host/core.c |  5 ++++-
 drivers/nvme/host/nvme.h | 10 ++++++++++
 drivers/nvme/host/pci.c  |  6 ++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 716ebe87a2b8..480ea24d8cf4 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2701,7 +2701,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
 
 		/* Grab required IO queue size */
-		ctrl->iosqes = id->sqes & 0xf;
+		if (ctrl->quirks & NVME_QUIRK_128_BYTES_SQES)
+			ctrl->iosqes = 7;
+		else
+			ctrl->iosqes = id->sqes & 0xf;
 		if (ctrl->iosqes < NVME_NVM_IOSQES) {
 			dev_err(ctrl->device,
 				"unsupported required IO queue size %d\n", ctrl->iosqes);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 34ef35fcd8a5..b2a78d08b984 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -92,6 +92,16 @@ enum nvme_quirks {
 	 * Broken Write Zeroes.
 	 */
 	NVME_QUIRK_DISABLE_WRITE_ZEROES		= (1 << 9),
+
+	/*
+	 * Use only one interrupt vector for all queues
+	 */
+	NVME_QUIRK_SINGLE_VECTOR		= (1 << 10),
+
+	/*
+	 * Use non-standard 128 bytes SQEs.
+	 */
+	NVME_QUIRK_128_BYTES_SQES		= (1 << 11),
 };
 
 /*
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 54b35ea4af88..ab2358137419 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2080,6 +2080,9 @@ static int nvme_setup_irqs(struct nvme_dev *dev, unsigned int nr_io_queues)
 	dev->io_queues[HCTX_TYPE_DEFAULT] = 1;
 	dev->io_queues[HCTX_TYPE_READ] = 0;
 
+	if (dev->ctrl.quirks & NVME_QUIRK_SINGLE_VECTOR)
+		irq_queues = 1;
+
 	return pci_alloc_irq_vectors_affinity(pdev, 1, irq_queues,
 			      PCI_IRQ_ALL_TYPES | PCI_IRQ_AFFINITY, &affd);
 }
@@ -3037,6 +3040,9 @@ static const struct pci_device_id nvme_id_table[] = {
 	{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2005),
+		.driver_data = NVME_QUIRK_SINGLE_VECTOR |
+				NVME_QUIRK_128_BYTES_SQES },
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, nvme_id_table);
-- 
2.17.1

WARNING: multiple messages have this Message-ID (diff)
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: linux-nvme@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, Jens Axboe <axboe@fb.com>,
	Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
	Paul Pawlowski <paul@mrarm.io>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH 3/3] nvme: Add support for Apple 2018+ models
Date: Tue, 16 Jul 2019 10:46:49 +1000	[thread overview]
Message-ID: <20190716004649.17799-3-benh@kernel.crashing.org> (raw)
In-Reply-To: <20190716004649.17799-1-benh@kernel.crashing.org>

Based on reverse engineering and original patch by

Paul Pawlowski <paul@mrarm.io>

This adds support for Apple weird implementation of NVME in their
2018 or later machines. It accounts for the twice-as-big SQ entries
for the IO queues, and the fact that only interrupt vector 0 appears
to function properly.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 drivers/nvme/host/core.c |  5 ++++-
 drivers/nvme/host/nvme.h | 10 ++++++++++
 drivers/nvme/host/pci.c  |  6 ++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 716ebe87a2b8..480ea24d8cf4 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2701,7 +2701,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
 
 		/* Grab required IO queue size */
-		ctrl->iosqes = id->sqes & 0xf;
+		if (ctrl->quirks & NVME_QUIRK_128_BYTES_SQES)
+			ctrl->iosqes = 7;
+		else
+			ctrl->iosqes = id->sqes & 0xf;
 		if (ctrl->iosqes < NVME_NVM_IOSQES) {
 			dev_err(ctrl->device,
 				"unsupported required IO queue size %d\n", ctrl->iosqes);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 34ef35fcd8a5..b2a78d08b984 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -92,6 +92,16 @@ enum nvme_quirks {
 	 * Broken Write Zeroes.
 	 */
 	NVME_QUIRK_DISABLE_WRITE_ZEROES		= (1 << 9),
+
+	/*
+	 * Use only one interrupt vector for all queues
+	 */
+	NVME_QUIRK_SINGLE_VECTOR		= (1 << 10),
+
+	/*
+	 * Use non-standard 128 bytes SQEs.
+	 */
+	NVME_QUIRK_128_BYTES_SQES		= (1 << 11),
 };
 
 /*
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 54b35ea4af88..ab2358137419 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2080,6 +2080,9 @@ static int nvme_setup_irqs(struct nvme_dev *dev, unsigned int nr_io_queues)
 	dev->io_queues[HCTX_TYPE_DEFAULT] = 1;
 	dev->io_queues[HCTX_TYPE_READ] = 0;
 
+	if (dev->ctrl.quirks & NVME_QUIRK_SINGLE_VECTOR)
+		irq_queues = 1;
+
 	return pci_alloc_irq_vectors_affinity(pdev, 1, irq_queues,
 			      PCI_IRQ_ALL_TYPES | PCI_IRQ_AFFINITY, &affd);
 }
@@ -3037,6 +3040,9 @@ static const struct pci_device_id nvme_id_table[] = {
 	{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2001) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2003) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2005),
+		.driver_data = NVME_QUIRK_SINGLE_VECTOR |
+				NVME_QUIRK_128_BYTES_SQES },
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, nvme_id_table);
-- 
2.17.1


  parent reply	other threads:[~2019-07-16  0:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-16  0:46 [PATCH 1/3] nvme: Pass the queue to SQ_SIZE/CQ_SIZE macros Benjamin Herrenschmidt
2019-07-16  0:46 ` Benjamin Herrenschmidt
2019-07-16  0:46 ` [PATCH 2/3] nvme: Retrieve the required IO queue entry size from the controller Benjamin Herrenschmidt
2019-07-16  0:46   ` Benjamin Herrenschmidt
2019-07-16  6:04   ` Christoph Hellwig
2019-07-16  6:04     ` Christoph Hellwig
2019-07-16  6:21     ` Benjamin Herrenschmidt
2019-07-16  6:21       ` Benjamin Herrenschmidt
2019-07-16  9:33       ` Christoph Hellwig
2019-07-16  9:33         ` Christoph Hellwig
2019-07-16 10:58         ` Benjamin Herrenschmidt
2019-07-16 10:58           ` Benjamin Herrenschmidt
2019-07-16 12:05           ` Christoph Hellwig
2019-07-16 12:05             ` Christoph Hellwig
2019-07-16 12:17             ` Benjamin Herrenschmidt
2019-07-16 12:17               ` Benjamin Herrenschmidt
2019-07-16 12:25               ` Christoph Hellwig
2019-07-16 12:25                 ` Christoph Hellwig
2019-07-16  0:46 ` Benjamin Herrenschmidt [this message]
2019-07-16  0:46   ` [PATCH 3/3] nvme: Add support for Apple 2018+ models Benjamin Herrenschmidt
2019-07-16  6:06   ` Christoph Hellwig
2019-07-16  6:06     ` Christoph Hellwig
2019-07-16  6:22     ` Benjamin Herrenschmidt
2019-07-16  6:22       ` Benjamin Herrenschmidt
2019-07-16  0:49 ` [PATCH 1/3] nvme: Pass the queue to SQ_SIZE/CQ_SIZE macros Benjamin Herrenschmidt
2019-07-16  0:49   ` Benjamin Herrenschmidt
2019-07-16  5:59 ` Christoph Hellwig
2019-07-16  5:59   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190716004649.17799-3-benh@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.