Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4068481pxb; Mon, 27 Sep 2021 08:45:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFPL5SoExhuTFjAFgdfQgGUW33BCcH4Njsmzph2LRcPFTgcDhg2dwgrSg0ZtjLpBcpBa03 X-Received: by 2002:aa7:c0d4:: with SMTP id j20mr699605edp.26.1632757504896; Mon, 27 Sep 2021 08:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632757504; cv=none; d=google.com; s=arc-20160816; b=E04yMZe1+qoSAfFkjiZNqj1BTS1WQ4jareJMtyOKxLkJ81oq9zn6N3r1tRoTXs5UKD KGp6X04TfN0SG6acuEFzfokc8SN1gWrtze6lBFRdRqhY3rg0eoEuyPL6hNicNFsyAHKh wGWi7AuDQBeaCuXgjrisuJy/WAcVE4hxB2ZPyo0nK6hdh+24xGJqQAjGUcWm2dtVMTQw AgvQAdvm6+dXu45lHosWNMlF65zl8jVPFiaFMMhfFpHCDHTqvH+PgDgiRONhJFwOzkF2 y3ldmgfxi7WFGzL3/dv+s95/OUcFLkPkZSOUb+TyJG+bVSpdn7iMPDgsAdQeh/uTMIpl /hKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YV5/tsZXzMX/wiIOC7NcSAccuKaZ4mYnw0g2kBBXv3c=; b=TlSJGrwsFGKN7Mt/wIMdYKsU9OBnnvpqA6Ko6TPeVoOMh6wZ2J0YyjlldGNAIUktQT KzueQU02lScRYm9oExkxpWvOKRhNf/JZ3Hweq0KSOrJk6EwujE/sj1U1odTafdj78rRT y03UrarIB0RkakKHXJQh0WPs3Im+wvf2cw8d1UbXObmH7CpwR0xDhM8DOxvAi1PhBaCb 4gmM7lE2bqOL07oijgdq9ZgRJ8Uhdi/qpdLSAC7RJcZyqK5O5Tb8ZW0TD/wJnFx7tFZD +jE5ssmH+6axPoV7E5iKQUVzkecmKOMgJA3oDWUBVHi3q+LvqKTEKBabnZHbLc1hn1y3 bLRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c+JNOFl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si9910200ejk.41.2021.09.27.08.44.39; Mon, 27 Sep 2021 08:45:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c+JNOFl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235163AbhI0Pos (ORCPT + 99 others); Mon, 27 Sep 2021 11:44:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:46206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbhI0Pos (ORCPT ); Mon, 27 Sep 2021 11:44:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7BCF160F94; Mon, 27 Sep 2021 15:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632757390; bh=P86cBH1nf5DfPMZ7Grlz7Pivw0MvErpNkzJ45WZUB2I=; h=From:To:Cc:Subject:Date:From; b=c+JNOFl2zUqUZoLIu0lznJURo6n+3GWiKgHBRErKfwx1Vkvxlg3aA5vGHd4xmmGjt xvfsaF7ytHSDsXUH2kOKWkGOqJjX5WUoirqc5GGoW3PkcCpFJYX0SopwzFYvI50YeB musN90yK8x4SBq0a3Feu3JL3Zc2V1H7diD8AsocJk6JLpPbplMt9l+oraAZgG1UDkJ 6QrLs/TBVaHJcTFM79ycuv3M41cZ9A/dE/zgZhkQkW6Wgc4U+wDHDyL7BQfVukL1Be lEpqlDDAff+hybok1TodgI1AdxbLrZLot2eiyqRmKIrg9Sc+bOTl9DaX3roMeb1ACO GXKVD7awT7yZw== From: Keith Busch To: linux-nvme@lists.infradead.org, sagi@grimberg.me, hch@lst.de Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk, Keith Busch , Sven Peter , Orlando Chamberlain , Aditya Garg Subject: [PATCHv2] nvme: add command id quirk for apple controllers Date: Mon, 27 Sep 2021 08:43:06 -0700 Message-Id: <20210927154306.387437-1-kbusch@kernel.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some apple controllers use the command id as an index to implementation specific data structures and will fail if the value is out of bounds. The nvme driver's recently introduced command sequence number breaks this controller. Provide a quirk so these spec incompliant controllers can function as before. The driver will not have the ability to detect bad completions when this quirk is used, but we weren't previously checking this anyway. The quirk bit was selected so that it can readily apply to stable. Link: https://bugzilla.kernel.org/show_bug.cgi?id=214509 Cc: Sven Peter Reported-by: Orlando Chamberlain Reported-by: Aditya Garg Signed-off-by: Keith Busch --- v1->v2: fixed logical bug checking the quirk setting drivers/nvme/host/core.c | 4 +++- drivers/nvme/host/nvme.h | 6 ++++++ drivers/nvme/host/pci.c | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e486845d2c7e..7712a8f78337 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -978,6 +978,7 @@ EXPORT_SYMBOL_GPL(nvme_cleanup_cmd); blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) { struct nvme_command *cmd = nvme_req(req)->cmd; + struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; blk_status_t ret = BLK_STS_OK; if (!(req->rq_flags & RQF_DONTPREP)) { @@ -1026,7 +1027,8 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) return BLK_STS_IOERR; } - nvme_req(req)->genctr++; + if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN)) + nvme_req(req)->genctr++; cmd->common.command_id = nvme_cid(req); trace_nvme_setup_cmd(req, cmd); return ret; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 9871c0c9374c..ed79a6c7e804 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -138,6 +138,12 @@ enum nvme_quirks { * 48 bits. */ NVME_QUIRK_DMA_ADDRESS_BITS_48 = (1 << 16), + + /* + * The controller requires the command_id value be be limited, so skip + * encoding the generation sequence number. + */ + NVME_QUIRK_SKIP_CID_GEN = (1 << 17), }; /* diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index b82492cd7503..456a0e8a5718 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -3369,7 +3369,8 @@ static const struct pci_device_id nvme_id_table[] = { { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2005), .driver_data = NVME_QUIRK_SINGLE_VECTOR | NVME_QUIRK_128_BYTES_SQES | - NVME_QUIRK_SHARED_TAGS }, + NVME_QUIRK_SHARED_TAGS | + NVME_QUIRK_SKIP_CID_GEN }, { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) }, { 0, } -- 2.25.4