Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5124132ybh; Wed, 7 Aug 2019 00:53:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKQOz++K0bWRy1Ggav001zkPaSamWfzpJcVwvRzgQX5FRKkVofoyBtIYiJNQlapFlxgjEN X-Received: by 2002:aa7:8ad0:: with SMTP id b16mr7962578pfd.45.1565164437721; Wed, 07 Aug 2019 00:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565164437; cv=none; d=google.com; s=arc-20160816; b=Dnl283DFSXjf1Odqs/0sCeNWWazNCMI6IkCByfNvYdrrDnWNjxtP5fYdmozFImei8T Ykx35tfyqnSnH+9iBVIyPeA/domx78qjuT4vPUG+8Co8E0MdPO18dInTL6bq0X0e6A2f GLhTckFlp/Bve7MbzA2pSL5c3qMr7gPYRNHJDZJlLlPMsn5K/bs5EFkmXxt4NbBmBmiO nwzuX2fsZfIhlg+N+wNCdc4TO4VI4RhwcKW0mMuulphWH9l0OW4wZSha6J4vhmOSV7NI lyoFhpowSqUtpg17WttTvnykGBoErIxsyM2ojSJJ5v0X3y9HP+bBSCQ5a0TbcY6HPH0n d4hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HBpjpEA8n3YKDanql1oi7B7hT59hV5pFhf1hM1dRduM=; b=doesVfwgP42v4ovrKNBsBdb/KEca3inKEahHX4uw4vJv73MMVdxgxE9UNaJF5m+Am3 jTAEWCBdhLjTTBqxk5WvyA/M2tKKCm+ElWNQM4K+9nHUbeMciN2OGOC+ijGlsGwXcqbT hH0RnuTpcGsZTQnwTa8gxMO5m13eZZjeCWoPZRoMAVluTi/OF2u2k4xdlyJQ9svP2Kcp giwjoHlDpQPY9KxnoXQHTNzRkWLZV/Z0W/sxMxZ+iDZIP9M7r2er32fUOJ5WPv7gj/lB t5g2NKKt/oIl42zWrByHtFUxJjUPoQCskUBVA08ah6n0Xhqg7Yo7SFfkIxxvIkIt+GZH XXZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si47609354pgo.355.2019.08.07.00.53.41; Wed, 07 Aug 2019 00:53:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387521AbfHGHwN (ORCPT + 99 others); Wed, 7 Aug 2019 03:52:13 -0400 Received: from gate.crashing.org ([63.228.1.57]:39486 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbfHGHwM (ORCPT ); Wed, 7 Aug 2019 03:52:12 -0400 Received: from ufdda393ec48b57.ant.amazon.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id x777pPaM021791; Wed, 7 Aug 2019 02:51:37 -0500 From: Benjamin Herrenschmidt To: linux-nvme@lists.infradead.org Cc: Sagi Grimberg , Jens Axboe , Keith Busch , Christoph Hellwig , linux-kernel@vger.kernel.org, Paul Pawlowski , Benjamin Herrenschmidt Subject: [PATCH v4 3/4] nvme-pci: Add support for Apple 2018+ models Date: Wed, 7 Aug 2019 17:51:21 +1000 Message-Id: <20190807075122.6247-4-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190807075122.6247-1-benh@kernel.crashing.org> References: <20190807075122.6247-1-benh@kernel.crashing.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on reverse engineering and original patch by Paul Pawlowski 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 Reviewed-by: Minwoo Im --- drivers/nvme/host/nvme.h | 10 ++++++++++ drivers/nvme/host/pci.c | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 8dc010ca30e5..0925f7fc13ff 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 78a660e229d9..c683263cdf60 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2081,6 +2081,13 @@ 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; + /* + * Some Apple controllers require all queues to use the + * first vector. + */ + 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); } @@ -2321,7 +2328,16 @@ static int nvme_pci_enable(struct nvme_dev *dev) dev->ctrl.sqsize = dev->q_depth - 1; /* 0's based queue depth */ dev->db_stride = 1 << NVME_CAP_STRIDE(dev->ctrl.cap); dev->dbs = dev->bar + 4096; - dev->io_sqes = NVME_NVM_IOSQES; + + /* + * Some Apple controllers require a non-standard SQE size. + * Interestingly they also seem to ignore the CC:IOSQES register + * so we don't bother updating it here. + */ + if (dev->ctrl.quirks & NVME_QUIRK_128_BYTES_SQES) + dev->io_sqes = 7; + else + dev->io_sqes = NVME_NVM_IOSQES; /* * Temporary fix for the Apple controller found in the MacBook8,1 and @@ -3039,6 +3055,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