nvme: add command id quirk for apple controllers

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 <sven@svenpeter.dev>
Reported-by: Orlando Chamberlain <redecorating@protonmail.com>
Reported-by: Aditya Garg <gargaditya08@live.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Sven Peter <sven@svenpeter.dev>
Link: https://lore.kernel.org/r/20210927154306.387437-1-kbusch@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Keith Busch and committed by
Jens Axboe
a2941f6a f278eb3d

+11 -2
+3 -1
drivers/nvme/host/core.c
··· 978 978 blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) 979 979 { 980 980 struct nvme_command *cmd = nvme_req(req)->cmd; 981 + struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; 981 982 blk_status_t ret = BLK_STS_OK; 982 983 983 984 if (!(req->rq_flags & RQF_DONTPREP)) { ··· 1027 1026 return BLK_STS_IOERR; 1028 1027 } 1029 1028 1030 - nvme_req(req)->genctr++; 1029 + if (!(ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN)) 1030 + nvme_req(req)->genctr++; 1031 1031 cmd->common.command_id = nvme_cid(req); 1032 1032 trace_nvme_setup_cmd(req, cmd); 1033 1033 return ret;
+6
drivers/nvme/host/nvme.h
··· 138 138 * 48 bits. 139 139 */ 140 140 NVME_QUIRK_DMA_ADDRESS_BITS_48 = (1 << 16), 141 + 142 + /* 143 + * The controller requires the command_id value be be limited, so skip 144 + * encoding the generation sequence number. 145 + */ 146 + NVME_QUIRK_SKIP_CID_GEN = (1 << 17), 141 147 }; 142 148 143 149 /*
+2 -1
drivers/nvme/host/pci.c
··· 3369 3369 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x2005), 3370 3370 .driver_data = NVME_QUIRK_SINGLE_VECTOR | 3371 3371 NVME_QUIRK_128_BYTES_SQES | 3372 - NVME_QUIRK_SHARED_TAGS }, 3372 + NVME_QUIRK_SHARED_TAGS | 3373 + NVME_QUIRK_SKIP_CID_GEN }, 3373 3374 3374 3375 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) }, 3375 3376 { 0, }