Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp134874ybi; Tue, 16 Jul 2019 17:46:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3ONrYe3PTyYUKWJT2O2xDrc8dbkK9ofyrCXwPU52/fnXxAu3sF3hY01c0HJRmjrKMbU3m X-Received: by 2002:a63:eb56:: with SMTP id b22mr37723663pgk.355.1563324412801; Tue, 16 Jul 2019 17:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563324412; cv=none; d=google.com; s=arc-20160816; b=hH/R4Fsfcp4Q1rH00nyDmwfj5i6j9wsw77n+pBMx3EPuL7xHcqOCwZECfT9R+0JnFF fKB0JPDKBcDgYVMXB5667+WcdS7MC9kivY/Ib+cRtN1Fdl0PEnI7+T8+b4P6gPAfXvv7 gdO4e6cyvPmblQyIN0jqTM57tvJb7FfEh0CyiO8r89a/2lxPYW2+Db72a3TPCarexxcm Erhix7YV5DyM0d5WpeoWNJnoPc3qneUNSdGAnAS3Xix8Y+4/sEbdH7uw0Q0Gi1x5lGK9 vRAa2SBB5OM1lZ9GRqszc5nrb6sY3u/qs4pCiYGKyzadflGsdqQQXOS70Yi7R1L9zUWS I5Zw== 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=Dqg1DlIXTqghTCpwkwRVcumFlZxirNpj9yWnCBp+Z58=; b=zc61+BCa5kgvx1m1XTthgPudaaSDemhj4T9S1vgkH0BbugkYXh9clqMYiN0hrpckKe Mi7NdhyvNEWFRIFsHWzWM3gtyCim7ZslPaXtb5mnE96MxKNR6pCNEPHvHCQzRACUw81e ZggvgGLE7fnt9KUzOQXTM74xayh7mG5iRvztYCvlvY0nErluAyhFTamjJYLpvKqgI0ZO K2BcVXYwl4pp+F0mUvcshDqa4LyNJ54YdYdjayjvhVMca9DU+k5x+jWl0h+PHI8eH8/b Js3CU/BvLZLwQHsk+lvxXWWBcvpD1kcmio3DXzBHCQy182jAHWRH2i+CfKn0k3/uyBa1 Q8GQ== 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 143si13591477pgc.479.2019.07.16.17.46.23; Tue, 16 Jul 2019 17:46:52 -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 S2388749AbfGQApv (ORCPT + 99 others); Tue, 16 Jul 2019 20:45:51 -0400 Received: from gate.crashing.org ([63.228.1.57]:56495 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbfGQApv (ORCPT ); Tue, 16 Jul 2019 20:45:51 -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 x6H0jXni032429; Tue, 16 Jul 2019 19:45:38 -0500 From: Benjamin Herrenschmidt To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Jens Axboe , Keith Busch , Christoph Hellwig , Paul Pawlowski , Benjamin Herrenschmidt Subject: [PATCH v2 2/3] nvme-pci: Add support for variable IO SQ element size Date: Wed, 17 Jul 2019 10:45:26 +1000 Message-Id: <20190717004527.30363-2-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190717004527.30363-1-benh@kernel.crashing.org> References: <20190717004527.30363-1-benh@kernel.crashing.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The size of a submission queue element should always be 6 (64 bytes) by spec. However some controllers such as Apple's are not properly implementing the standard and require a different size. This provides the ground work for the subsequent quirks for these controllers. Signed-off-by: Benjamin Herrenschmidt --- drivers/nvme/host/pci.c | 11 ++++++++--- include/linux/nvme.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8f006638452b..1637677afb78 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -28,7 +28,7 @@ #include "trace.h" #include "nvme.h" -#define SQ_SIZE(q) ((q)->q_depth * sizeof(struct nvme_command)) +#define SQ_SIZE(q) ((q)->q_depth << (q)->sqes) #define CQ_SIZE(q) ((q)->q_depth * sizeof(struct nvme_completion)) #define SGES_PER_PAGE (PAGE_SIZE / sizeof(struct nvme_sgl_desc)) @@ -100,6 +100,7 @@ struct nvme_dev { unsigned io_queues[HCTX_MAX_TYPES]; unsigned int num_vecs; int q_depth; + int io_sqes; u32 db_stride; void __iomem *bar; unsigned long bar_mapped_size; @@ -162,7 +163,7 @@ static inline struct nvme_dev *to_nvme_dev(struct nvme_ctrl *ctrl) struct nvme_queue { struct nvme_dev *dev; spinlock_t sq_lock; - struct nvme_command *sq_cmds; + void *sq_cmds; /* only used for poll queues: */ spinlock_t cq_poll_lock ____cacheline_aligned_in_smp; volatile struct nvme_completion *cqes; @@ -178,6 +179,7 @@ struct nvme_queue { u16 last_cq_head; u16 qid; u8 cq_phase; + u8 sqes; unsigned long flags; #define NVMEQ_ENABLED 0 #define NVMEQ_SQ_CMB 1 @@ -488,7 +490,8 @@ static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd, bool write_sq) { spin_lock(&nvmeq->sq_lock); - memcpy(&nvmeq->sq_cmds[nvmeq->sq_tail], cmd, sizeof(*cmd)); + memcpy(nvmeq->sq_cmds + (nvmeq->sq_tail << nvmeq->sqes), + cmd, sizeof(*cmd)); if (++nvmeq->sq_tail == nvmeq->q_depth) nvmeq->sq_tail = 0; nvme_write_sq_db(nvmeq, write_sq); @@ -1465,6 +1468,7 @@ static int nvme_alloc_queue(struct nvme_dev *dev, int qid, int depth) if (dev->ctrl.queue_count > qid) return 0; + nvmeq->sqes = qid ? dev->io_sqes : NVME_NVM_ADMSQES; nvmeq->q_depth = depth; nvmeq->cqes = dma_alloc_coherent(dev->dev, CQ_SIZE(nvmeq), &nvmeq->cq_dma_addr, GFP_KERNEL); @@ -2318,6 +2322,7 @@ static int nvme_pci_enable(struct nvme_dev *dev) io_queue_depth); dev->db_stride = 1 << NVME_CAP_STRIDE(dev->ctrl.cap); dev->dbs = dev->bar + 4096; + dev->io_sqes = NVME_NVM_IOSQES; /* * Temporary fix for the Apple controller found in the MacBook8,1 and diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 01aa6a6c241d..d5a4bc21f36b 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -140,6 +140,7 @@ enum { * Submission and Completion Queue Entry Sizes for the NVM command set. * (In bytes and specified as a power of two (2^n)). */ +#define NVME_NVM_ADMSQES 6 #define NVME_NVM_IOSQES 6 #define NVME_NVM_IOCQES 4 -- 2.17.1